Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0de78646
提交
0de78646
authored
11月 22, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merged
上级
32105ec9
7bac82c1
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
43 行增加
和
29 行删除
+43
-29
test_wiki.py
examples/tests/test_wiki.py
+17
-28
module.py
theano/compile/module.py
+4
-0
test_blas.py
theano/tensor/tests/test_blas.py
+1
-1
__init__.py
theano/tests/__init__.py
+1
-0
main.py
theano/tests/main.py
+20
-0
没有找到文件。
examples/tests/test_wiki.py
浏览文件 @
0de78646
...
@@ -19,7 +19,8 @@ class Blah(M.ModuleInstance):
...
@@ -19,7 +19,8 @@ class Blah(M.ModuleInstance):
self
.
w
=
rng
.
uniform
(
size
=
sz
,
low
=
-
0.5
,
high
=
0.5
)
self
.
w
=
rng
.
uniform
(
size
=
sz
,
low
=
-
0.5
,
high
=
0.5
)
self
.
b
=
N
.
zeros
(
target_size
)
self
.
b
=
N
.
zeros
(
target_size
)
self
.
stepsize
=
0.01
self
.
stepsize
=
0.01
#we call default_initialize after as we want the parameter to superseed the default value.
M
.
default_initialize
(
self
,
**
init
)
#equivalent to previous line.
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
if
not
isinstance
(
other
.
component
,
SoftmaxXERegression1
)
and
not
isinstance
(
other
.
component
,
SoftmaxXERegression2
):
if
not
isinstance
(
other
.
component
,
SoftmaxXERegression1
)
and
not
isinstance
(
other
.
component
,
SoftmaxXERegression2
):
raise
NotImplemented
raise
NotImplemented
...
@@ -113,11 +114,6 @@ class RegressionLayer2(M.Module):
...
@@ -113,11 +114,6 @@ class RegressionLayer2(M.Module):
seed
=
1827
,
**
init
):
seed
=
1827
,
**
init
):
# obj is an "instance" of this module holding values for each member and
# obj is an "instance" of this module holding values for each member and
# functions for each method
# functions for each method
#super(RegressionLayer, self).initialize(obj, **init)
# here we call the superclass's initialize method, which takes all the name: value
# pairs in init and sets the property with that name to the provided value
# this covers setting stepsize, l2_coef; w and b can be set that way too
if
input_size
and
target_size
:
if
input_size
and
target_size
:
# initialize w and b in a special way using input_size and target_size
# initialize w and b in a special way using input_size and target_size
sz
=
(
input_size
,
target_size
)
sz
=
(
input_size
,
target_size
)
...
@@ -125,6 +121,11 @@ class RegressionLayer2(M.Module):
...
@@ -125,6 +121,11 @@ class RegressionLayer2(M.Module):
obj
.
w
=
rng
.
uniform
(
size
=
sz
,
low
=
-
0.5
,
high
=
0.5
)
obj
.
w
=
rng
.
uniform
(
size
=
sz
,
low
=
-
0.5
,
high
=
0.5
)
obj
.
b
=
N
.
zeros
(
target_size
)
obj
.
b
=
N
.
zeros
(
target_size
)
obj
.
stepsize
=
0.01
obj
.
stepsize
=
0.01
# here we call the default_initialize method, which takes all the name: value
# pairs in init and sets the property with that name to the provided value
# this covers setting stepsize, l2_coef; w and b can be set that way too
# we call it after as we want the parameter to superseed the default value.
M
.
default_initialize
(
obj
,
**
init
)
def
build_regularization
(
self
):
def
build_regularization
(
self
):
return
T
.
zero
()
# no regularization!
return
T
.
zero
()
# no regularization!
...
@@ -219,6 +220,7 @@ class T_test_wiki_module(unittest.TestCase):
...
@@ -219,6 +220,7 @@ class T_test_wiki_module(unittest.TestCase):
m
.
incdec2
=
make_incdec_module
()
m
.
incdec2
=
make_incdec_module
()
m
.
sum
=
M
.
Method
([],
m
.
incdec1
.
c
+
m
.
incdec2
.
c
)
m
.
sum
=
M
.
Method
([],
m
.
incdec1
.
c
+
m
.
incdec2
.
c
)
inst
=
m
.
make
(
incdec1
=
dict
(
c
=
0
),
incdec2
=
dict
(
c
=
0
))
inst
=
m
.
make
(
incdec1
=
dict
(
c
=
0
),
incdec2
=
dict
(
c
=
0
))
assert
inst
.
incdec1
.
c
==
0
and
inst
.
incdec2
.
c
==
0
inst
.
incdec1
.
inc
(
2
)
inst
.
incdec1
.
inc
(
2
)
inst
.
incdec1
.
dec
(
4
)
inst
.
incdec1
.
dec
(
4
)
inst
.
incdec2
.
inc
(
6
)
inst
.
incdec2
.
inc
(
6
)
...
@@ -228,13 +230,13 @@ class T_test_wiki_module(unittest.TestCase):
...
@@ -228,13 +230,13 @@ class T_test_wiki_module(unittest.TestCase):
def
test_Module_Advanced_example
(
self
):
def
test_Module_Advanced_example
(
self
):
data_x
=
N
.
random
.
randn
(
4
,
10
)
data_x
=
N
.
random
.
randn
(
4
,
10
)
data_y
=
[
[
int
(
x
)]
for
x
in
N
.
random
.
randn
(
4
)
>
0
]
data_y
=
[
[
int
(
x
)]
for
x
in
N
.
random
.
randn
(
4
)
>
0
]
# print data_x
# print
# print data_y
def
test
(
model
):
def
test
(
model
):
model
=
model
.
make
(
input_size
=
10
,
model
=
model
.
make
(
input_size
=
10
,
target_size
=
1
,
target_size
=
1
,
stepsize
=
0.1
)
stepsize
=
0.1
)
print
model
.
stepsize
self
.
failUnless
(
model
.
w
.
shape
==
(
10
,
1
)
and
model
.
b
.
shape
==
(
1
,))
assert
model
.
stepsize
==
0.1
for
i
in
xrange
(
1000
):
for
i
in
xrange
(
1000
):
xe
=
model
.
update
(
data_x
,
data_y
)
xe
=
model
.
update
(
data_x
,
data_y
)
if
i
%
100
==
0
:
if
i
%
100
==
0
:
...
@@ -257,7 +259,7 @@ class T_test_wiki_module(unittest.TestCase):
...
@@ -257,7 +259,7 @@ class T_test_wiki_module(unittest.TestCase):
print
m1
==
m2
print
m1
==
m2
assert
m2
==
m1
and
m1
==
m2
assert
m2
==
m1
and
m1
==
m2
def
test_Module_extending_
klass
_methods
(
self
):
def
test_Module_extending_
module
_methods
(
self
):
model_module
=
SoftmaxXERegression1
(
regularize
=
False
)
model_module
=
SoftmaxXERegression1
(
regularize
=
False
)
model_module
.
sum
=
M
.
Member
(
T
.
scalar
())
# we add a module member to hold the sum
model_module
.
sum
=
M
.
Member
(
T
.
scalar
())
# we add a module member to hold the sum
model_module
.
update
.
updates
.
update
(
sum
=
model_module
.
sum
+
model_module
.
cost
)
# now update will also update sum!
model_module
.
update
.
updates
.
update
(
sum
=
model_module
.
sum
+
model_module
.
cost
)
# now update will also update sum!
...
@@ -266,6 +268,9 @@ class T_test_wiki_module(unittest.TestCase):
...
@@ -266,6 +268,9 @@ class T_test_wiki_module(unittest.TestCase):
target_size
=
2
,
target_size
=
2
,
stepsize
=
0.1
,
stepsize
=
0.1
,
sum
=
0
)
# we mustn't forget to initialize the sum
sum
=
0
)
# we mustn't forget to initialize the sum
print
model
.
stepsize
self
.
failUnless
(
model
.
w
.
shape
==
(
4
,
2
)
and
model
.
b
.
shape
==
(
2
,))
assert
model
.
stepsize
==
0.1
test
=
model
.
update
([[
0
,
0
,
1
,
0
]],
[[
0
,
1
]])
test
=
model
.
update
([[
0
,
0
,
1
,
0
]],
[[
0
,
1
]])
test
+=
model
.
update
([[
0
,
1
,
0
,
0
]],
[[
1
,
0
]])
test
+=
model
.
update
([[
0
,
1
,
0
,
0
]],
[[
1
,
0
]])
...
@@ -304,21 +309,5 @@ class T_test_wiki_module(unittest.TestCase):
...
@@ -304,21 +309,5 @@ class T_test_wiki_module(unittest.TestCase):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
theano.tests
import
main
if
0
:
main
(
"test_wiki"
)
unittest
.
main
()
elif
1
:
module
=
__import__
(
"test_wiki"
)
tests
=
unittest
.
TestLoader
()
.
loadTestsFromModule
(
module
)
tests
.
debug
()
else
:
testcases
=
[]
testcases
.
append
(
T_function_module
)
#<testsuite boilerplate>
testloader
=
unittest
.
TestLoader
()
suite
=
unittest
.
TestSuite
()
for
testcase
in
testcases
:
suite
.
addTest
(
testloader
.
loadTestsFromTestCase
(
testcase
))
unittest
.
TextTestRunner
(
verbosity
=
2
)
.
run
(
suite
)
#</boilerplate>
theano/compile/module.py
浏览文件 @
0de78646
...
@@ -664,6 +664,10 @@ class ComponentList(Composite):
...
@@ -664,6 +664,10 @@ class ComponentList(Composite):
return
self
.
__class__
(
*
[
c
.
dup
()
for
c
in
self
.
_components
])
return
self
.
__class__
(
*
[
c
.
dup
()
for
c
in
self
.
_components
])
def
default_initialize
(
self
,
init
=
{},
**
kwinit
):
for
k
,
initv
in
dict
(
init
,
**
kwinit
)
.
iteritems
():
self
[
k
]
=
initv
class
ComponentDictInstance
(
CompositeInstance
):
class
ComponentDictInstance
(
CompositeInstance
):
"""
"""
ComponentDictInstance is meant to be instantiated by ComponentDict.
ComponentDictInstance is meant to be instantiated by ComponentDict.
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
0de78646
import
theano.tensor
as
T
import
theano.tensor
as
T
from
..gof
import
Env
from
..
.
gof
import
Env
import
numpy
import
numpy
from
theano.tensor.blas
import
*
from
theano.tensor.blas
import
*
from
theano.tensor.blas
import
_as_scalar
,
_dot22
from
theano.tensor.blas
import
_as_scalar
,
_dot22
...
...
theano/tests/__init__.py
浏览文件 @
0de78646
from
main
import
main
theano/tests/main.py
0 → 100644
浏览文件 @
0de78646
import
unittest
def
main
(
modulename
):
if
0
:
unittest
.
main
()
elif
1
:
module
=
__import__
(
modulename
)
tests
=
unittest
.
TestLoader
()
.
loadTestsFromModule
(
module
)
tests
.
debug
()
else
:
testcases
=
[]
testcases
.
append
(
T_function_module
)
#<testsuite boilerplate>
testloader
=
unittest
.
TestLoader
()
suite
=
unittest
.
TestSuite
()
for
testcase
in
testcases
:
suite
.
addTest
(
testloader
.
loadTestsFromTestCase
(
testcase
))
unittest
.
TextTestRunner
(
verbosity
=
2
)
.
run
(
suite
)
#</boilerplate>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论