Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9b9602c6
提交
9b9602c6
authored
4月 03, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
6d792716
764e81b9
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
129 行增加
和
107 行删除
+129
-107
NEWS.txt
doc/NEWS.txt
+1
-1
ctype.txt
doc/advanced_tutorial/ctype.txt
+1
-1
graphstructures.txt
doc/advanced_tutorial/graphstructures.txt
+1
-1
contents.txt
doc/contents.txt
+0
-1
install.txt
doc/install.txt
+1
-1
how_to_release.txt
doc/internal/how_to_release.txt
+7
-1
unittest.txt
doc/topics/unittest.txt
+6
-0
test_basic.py
theano/sparse/tests/test_basic.py
+6
-6
basic.py
theano/tensor/basic.py
+0
-1
test_basic.py
theano/tensor/tests/test_basic.py
+71
-71
test_nnet.py
theano/tensor/tests/test_nnet.py
+20
-20
test_xlogx.py
theano/tensor/tests/test_xlogx.py
+3
-3
unittest_tools.py
theano/tests/unittest_tools.py
+12
-0
没有找到文件。
doc/NEWS.txt
浏览文件 @
9b9602c6
...
...
@@ -8,7 +8,7 @@ Release Notes
Theano 0.1
==========
*Release date: 2009-04-0
1
*
*Release date: 2009-04-0
2
*
What works
----------
...
...
doc/advanced_tutorial/ctype.txt
浏览文件 @
9b9602c6
...
...
@@ -42,7 +42,7 @@ What needs to be defined
In order to be C-compatible, a Type must define several additional
methods, which all start with the ``c_`` prefix. The complete list can
be found in the documentation for :api:`gof.Type`. Here, we'll focus on
be found in the documentation for :api:`gof.
type.
Type`. Here, we'll focus on
the most important ones:
...
...
doc/advanced_tutorial/graphstructures.txt
浏览文件 @
9b9602c6
...
...
@@ -146,7 +146,7 @@ Automatic wrapping
All nodes in the graph must be instances of ``Apply`` or ``Result``, but
``<Op subclass>.make_node()`` typically wraps constants to satisfy those
constraints. For example, the :api:`tensor.add <theano.tensor.add>`
constraints. For example, the :api:`tensor.add <theano.tensor.
basic.
add>`
Op instance is written so that:
.. code-block:: python
...
...
doc/contents.txt
浏览文件 @
9b9602c6
...
...
@@ -8,7 +8,6 @@ Contents
.. toctree::
:maxdepth: 2
index
introduction
LICENSE
install
...
...
doc/install.txt
浏览文件 @
9b9602c6
...
...
@@ -125,7 +125,7 @@ Mac
- Install some kind of BLAS library (TODO: how?)
- Set ``THEANO_BLAS_LDFLAGS to something which will link against said BLAS
- Set ``THEANO_BLAS_LDFLAGS
``
to something which will link against said BLAS
library. E.g., ``THEANO_BLAS_LDFLAGS='-lcblas -latlas -lgfortran'``.
This advice has not been tested recently, so please inform us of your results.
...
...
doc/internal/how_to_release.txt
浏览文件 @
9b9602c6
...
...
@@ -23,6 +23,7 @@ Edit ``doc/index.txt`` to contain a link to what will be the download URL::
Tag the release. The syntax is something like the following::
hg tag Theano-0.X
hg push
Now, package the release and move it to the static theano directory::
...
...
@@ -30,7 +31,6 @@ Now, package the release and move it to the static theano directory::
cd ..
tar cvf Theano-0.X.tar Theano-0.X
gzip -9 Theano-0.X.tar
rm -Rf Theano-0.X
mv Theano-0.X.tar.gz www/theano_static/downloads/
~/repos/theano/.hg/refresh-epydoc.sh
...
...
@@ -42,7 +42,13 @@ directory::
Finally, use setuptools to register and upload the release::
cd Theano-0.X
python setup.py register sdist bdist_egg upload
# If you get an error message about needing to be identified, then store
# your pypi information in ~/.pypirc
# You can remove this file after upload.
cd ..
rm -Rf Theano-0.X
I wrote the above without actually running it. This needs to be
scrutinized when you are actually do a release.
...
...
doc/topics/unittest.txt
浏览文件 @
9b9602c6
...
...
@@ -393,6 +393,12 @@ Here is an example showing how to use verify_grad:
>>> # ...
>>> tensor.verify_grad(Flatten(), [a_val])
.. note::
Although ``verify_grad`` is defined in ``theano.tensor.basic``, unittests
should use the version of ``verify_grad`` defined in ``theano.tests.unittest_tools``.
This is simply a wrapper function which takes care of seeding the random
number generator appropriately before calling ``theano.tensor.basic.verify_grad``
makeTester and makeBroadcastTester
==================================
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
9b9602c6
...
...
@@ -11,7 +11,7 @@ from theano import gof
from
theano.sparse.basic
import
_is_dense
,
_is_sparse
,
_is_dense_variable
,
_is_sparse_variable
from
theano.sparse.basic
import
_mtypes
,
_mtype_to_str
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
as
utt
def
eval_outputs
(
outputs
):
...
...
@@ -19,7 +19,7 @@ def eval_outputs(outputs):
class
T_transpose
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test_transpose_csc
(
self
):
sp
=
sparse
.
csc_matrix
(
sparse
.
eye
(
5
,
3
))
...
...
@@ -126,7 +126,7 @@ class T_Add(unittest.TestCase):
class
T_conversion
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
a
=
tensor
.
as_tensor_variable
(
numpy
.
random
.
rand
(
5
))
...
...
@@ -157,7 +157,7 @@ class T_conversion(unittest.TestCase):
import
scipy.sparse
as
sp
class
test_structureddot
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test_structuredot
(
self
):
bsize
=
2
...
...
@@ -193,7 +193,7 @@ class test_structureddot(unittest.TestCase):
assert
_is_dense
(
c
)
assert
numpy
.
all
(
outvals
==
c
)
tensor
.
verify_grad
(
buildgraphCSC
,
[
kernvals
,
imvals
])
utt
.
verify_grad
(
buildgraphCSC
,
[
kernvals
,
imvals
])
##
# Test compressed-sparse row matrices ###
...
...
@@ -215,7 +215,7 @@ class test_structureddot(unittest.TestCase):
assert
_is_dense
(
c
)
assert
numpy
.
all
(
outvals
==
c
)
tensor
.
verify_grad
(
buildgraphCSR
,
[
kernvals
,
imvals
])
utt
.
verify_grad
(
buildgraphCSR
,
[
kernvals
,
imvals
])
if
__name__
==
'__main__'
:
...
...
theano/tensor/basic.py
浏览文件 @
9b9602c6
...
...
@@ -20,7 +20,6 @@ from ..gof.python25 import partial
from
..
import
compile
,
printing
from
..printing
import
pprint
,
Print
from
..tests
import
unittest_tools
### set up the external interface
from
elemwise
import
Elemwise
,
DimShuffle
,
CAReduce
,
Sum
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
9b9602c6
...
...
@@ -16,10 +16,10 @@ from theano import gof
from
theano.tensor.elemwise
import
DimShuffle
from
theano.compile.mode
import
default_mode
from
theano
import
function
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
as
utt
### seed random number generator so that unittests are deterministic ###
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
inplace_func
(
inputs
,
outputs
,
mode
=
default_mode
):
return
function
(
inputs
,
outputs
,
mode
=
mode
,
accept_inplace
=
True
)
...
...
@@ -157,7 +157,7 @@ def makeTester(name, op, expected, checks = {}, good = {}, bad_build = {}, bad_r
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
inputrs
=
[
value
(
input
)
for
input
in
inputs
]
try
:
verify_grad
(
self
.
op
,
inputs
)
utt
.
verify_grad
(
self
.
op
,
inputs
)
except
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while computing the gradient on the following inputs:
%
s"
\
...
...
@@ -599,7 +599,7 @@ class T_Cast(unittest.TestCase):
class
T_max_and_argmax
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
MaxAndArgmax
.
debug
=
0
def
test0
(
self
):
...
...
@@ -670,7 +670,7 @@ class T_max_and_argmax(unittest.TestCase):
class
T_subtensor
(
unittest
.
TestCase
):
def
setUp
(
self
):
Subtensor
.
debug
=
False
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0_err_invalid
(
self
):
#it is impossible to retrieve a view of a 0-d tensor
...
...
@@ -941,7 +941,7 @@ class T_Join_and_Split(unittest.TestCase):
want
=
numpy
.
array
([[
1
,
2
,
3
,
7
],
[
4
,
5
,
6
,
8
]],
dtype
=
'float32'
)
self
.
failUnless
((
eval_outputs
([
s
])
==
want
)
.
all
())
verify_grad
(
lambda
a
,
b
:
join
(
1
,
a
,
b
),
[
av
,
bv
],
eps
=
1.0e-4
,
tol
=
1.0e-3
)
utt
.
verify_grad
(
lambda
a
,
b
:
join
(
1
,
a
,
b
),
[
av
,
bv
],
eps
=
1.0e-4
,
tol
=
1.0e-3
)
def
test_join_matrix1_using_vertical_stack
(
self
):
a
=
as_tensor_variable
(
numpy
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]]))
...
...
@@ -963,7 +963,7 @@ class T_Join_and_Split(unittest.TestCase):
want
=
numpy
.
array
([[
1
,
2
,
3
,
7
,
3
,
2
,
1
],
[
4
,
5
,
6
,
8
,
6
,
5
,
4
]],
dtype
=
'float32'
)
self
.
failUnless
((
eval_outputs
([
s
])
==
want
)
.
all
())
verify_grad
(
lambda
a
,
b
:
join
(
1
,
a
,
b
),
[
av
,
bv
],
eps
=
1.0e-4
,
tol
=
1.0e-3
)
utt
.
verify_grad
(
lambda
a
,
b
:
join
(
1
,
a
,
b
),
[
av
,
bv
],
eps
=
1.0e-4
,
tol
=
1.0e-3
)
def
test_join_matrixV
(
self
):
"""variable join axis"""
...
...
@@ -983,8 +983,8 @@ class T_Join_and_Split(unittest.TestCase):
got
=
f
(
1
)
self
.
failUnless
((
got
==
want
)
.
all
(),
(
got
,
want
))
verify_grad
(
lambda
a
,
b
:
join
(
0
,
a
,
b
),
[
v
,
2
*
v
])
verify_grad
(
lambda
a
,
b
:
join
(
1
,
a
,
b
),
[
v
,
2
*
v
])
utt
.
verify_grad
(
lambda
a
,
b
:
join
(
0
,
a
,
b
),
[
v
,
2
*
v
])
utt
.
verify_grad
(
lambda
a
,
b
:
join
(
1
,
a
,
b
),
[
v
,
2
*
v
])
def
test_vector_len
(
self
):
x
=
lscalar
(
'x'
)
...
...
@@ -1090,7 +1090,7 @@ class test_bitwise(unittest.TestCase):
class
T_add
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test_complex_all_ops
(
self
):
for
nbits
in
(
64
,
128
):
...
...
@@ -1107,22 +1107,22 @@ class T_add(unittest.TestCase):
self
.
failUnless
(
a
.
type
.
values_eq_approx
(
fn
(
a
.
data
,
b
.
data
),
f
(
a
.
data
,
b
.
data
)))
def
test_grad_scalar_l
(
self
):
verify_grad
(
add
,
[
numpy
.
asarray
([
3.0
]),
numpy
.
random
.
rand
(
3
)])
utt
.
verify_grad
(
add
,
[
numpy
.
asarray
([
3.0
]),
numpy
.
random
.
rand
(
3
)])
def
test_grad_scalar_r
(
self
):
verify_grad
(
add
,
[
numpy
.
random
.
rand
(
3
),
numpy
.
asarray
([
3.0
])])
utt
.
verify_grad
(
add
,
[
numpy
.
random
.
rand
(
3
),
numpy
.
asarray
([
3.0
])])
def
test_grad_row
(
self
):
verify_grad
(
add
,
[
numpy
.
random
.
rand
(
3
,
5
),
numpy
.
random
.
rand
(
1
,
5
)])
utt
.
verify_grad
(
add
,
[
numpy
.
random
.
rand
(
3
,
5
),
numpy
.
random
.
rand
(
1
,
5
)])
def
test_grad_col
(
self
):
verify_grad
(
add
,
[
numpy
.
random
.
rand
(
3
,
5
),
numpy
.
random
.
rand
(
3
,
1
)])
utt
.
verify_grad
(
add
,
[
numpy
.
random
.
rand
(
3
,
5
),
numpy
.
random
.
rand
(
3
,
1
)])
class
T_exp
(
unittest
.
TestCase
):
def
test_grad_0
(
self
):
verify_grad
(
exp
,
[
utt
.
verify_grad
(
exp
,
[
numpy
.
asarray
([[
1.5089518
,
1.48439076
,
-
4.7820262
],
[
2.04832468
,
0.50791564
,
-
1.58892269
]])])
def
test_grad_1
(
self
):
verify_grad
(
inplace
.
exp_inplace
,
[
utt
.
verify_grad
(
inplace
.
exp_inplace
,
[
numpy
.
asarray
([[
1.5089518
,
1.48439076
,
-
4.7820262
],
[
2.04832468
,
0.50791564
,
-
1.58892269
]])])
...
...
@@ -1139,8 +1139,8 @@ class T_exp(unittest.TestCase):
# check_eq(self, t, abs(t), -d, abs(-d))
# def test_grad(self):
# verify_grad(Abs, [numpy.ones(())])
# verify_grad(Abs, [numpy.ones(3)])
#
utt.
verify_grad(Abs, [numpy.ones(())])
#
utt.
verify_grad(Abs, [numpy.ones(3)])
# class AbsBadGrad(Abs):
# def grad(self, (x, ), (gz, )):
...
...
@@ -1148,9 +1148,9 @@ class T_exp(unittest.TestCase):
# def test_badgrad(self):
# try:
# verify_grad(T_abs.AbsBadGrad, [numpy.ones(())])
#
utt.
verify_grad(T_abs.AbsBadGrad, [numpy.ones(())])
# except Exception, e:
# self.failUnless(str(e) == verify_grad.E_grad, str(e))
# self.failUnless(str(e) ==
utt.
verify_grad.E_grad, str(e))
# return
# self.fail()
...
...
@@ -1187,7 +1187,7 @@ class T_exp(unittest.TestCase):
# class T_mul(unittest.TestCase):
# def setUp(self):
# u
nittest_tools
.seed_rng()
# u
tt
.seed_rng()
# def test_elemwise(self):
# a = as_tensor_variable(0.0)
...
...
@@ -1219,18 +1219,18 @@ class T_exp(unittest.TestCase):
# check_eq2_both(self, [a1,a3], mul(a1,a3), [r1, r3], r1*r3)
# def test_grad_elemwise(self):
# verify_grad(Mul, [numpy.random.rand(3,4), numpy.random.rand(3,4)])
#
utt.
verify_grad(Mul, [numpy.random.rand(3,4), numpy.random.rand(3,4)])
# def test_grad_scalar_l(self):
# verify_grad(Mul, [numpy.asarray([3.0]), numpy.random.rand(3)])
#
utt.
verify_grad(Mul, [numpy.asarray([3.0]), numpy.random.rand(3)])
# def test_grad_scalar_r(self):
# verify_grad(Mul, [numpy.random.rand(3), numpy.asarray([3.0])])
#
utt.
verify_grad(Mul, [numpy.random.rand(3), numpy.asarray([3.0])])
# def test_grad_row(self):
# verify_grad(Mul, [numpy.random.rand(3, 5), numpy.random.rand(1, 5)])
#
utt.
verify_grad(Mul, [numpy.random.rand(3, 5), numpy.random.rand(1, 5)])
# def test_grad_row2(self):
# op = lambda x, y: Mul(x, DimShuffle(y, ['x', 0]).out)
# verify_grad(op, [numpy.random.rand(3, 5), numpy.random.rand(5)])
#
utt.
verify_grad(op, [numpy.random.rand(3, 5), numpy.random.rand(5)])
# def test_grad_col(self):
# verify_grad(Mul, [numpy.random.rand(3, 5), numpy.random.rand(3, 1)])
#
utt.
verify_grad(Mul, [numpy.random.rand(3, 5), numpy.random.rand(3, 1)])
# def test_wrong_shapes(self):
# a = as_tensor_variable(numpy.ones(3))
...
...
@@ -1250,28 +1250,28 @@ class T_exp(unittest.TestCase):
# class T_div(unittest.TestCase):
# def setUp(self):
# u
nittest_tools
.seed_rng()
# u
tt
.seed_rng()
# def test_grad_e(self):
# verify_grad(Div, [numpy.random.rand(3), numpy.ones(3)])
# verify_grad(Div, [numpy.random.rand(3,5), numpy.random.rand(3,5)+0.1])
# verify_grad(Div, [numpy.ones(()), numpy.ones(())])
#
utt.
verify_grad(Div, [numpy.random.rand(3), numpy.ones(3)])
#
utt.
verify_grad(Div, [numpy.random.rand(3,5), numpy.random.rand(3,5)+0.1])
#
utt.
verify_grad(Div, [numpy.ones(()), numpy.ones(())])
# def test_grad_sl(self):
# verify_grad(Div, [numpy.ones((3, 5)), numpy.ones((1, 1))])
# verify_grad(Div, [numpy.random.rand(3), numpy.ones((1, ))])
# verify_grad(Div, [numpy.random.rand(3,5), numpy.random.rand(1,1)])
#
utt.
verify_grad(Div, [numpy.ones((3, 5)), numpy.ones((1, 1))])
#
utt.
verify_grad(Div, [numpy.random.rand(3), numpy.ones((1, ))])
#
utt.
verify_grad(Div, [numpy.random.rand(3,5), numpy.random.rand(1,1)])
# class T_log2(unittest.TestCase):
# def setUp(self):
# u
nittest_tools
.seed_rng()
# u
tt
.seed_rng()
# def test0(self):
# verify_grad(Log2, [numpy.random.rand(3,1)+0.0001])
#
utt.
verify_grad(Log2, [numpy.random.rand(3,1)+0.0001])
# class T_log(unittest.TestCase):
# def setUp(self):
# u
nittest_tools
.seed_rng()
# u
tt
.seed_rng()
# def test0(self):
# verify_grad(Log, [numpy.random.rand(3,1)+0.0001])
#
utt.
verify_grad(Log, [numpy.random.rand(3,1)+0.0001])
# def test1(self):
# a = as_tensor_variable(numpy.ones(2))
# b = as_tensor_variable(numpy.ones(2))
...
...
@@ -1281,23 +1281,23 @@ class T_exp(unittest.TestCase):
# class T_pow(unittest.TestCase):
# def setUp(self):
# u
nittest_tools
.seed_rng()
# u
tt
.seed_rng()
# def test_elemwise(self):
# verify_grad(Div, [numpy.random.rand(3,4), numpy.random.rand(3,4)+0.1])
# verify_grad(Pow, [numpy.random.rand(3,4), numpy.random.rand(3,4)])
#
utt.
verify_grad(Div, [numpy.random.rand(3,4), numpy.random.rand(3,4)+0.1])
#
utt.
verify_grad(Pow, [numpy.random.rand(3,4), numpy.random.rand(3,4)])
# def test_scalar_l(self):
# verify_grad(Pow, [numpy.asarray([3.0]), numpy.random.rand(3)])
#
utt.
verify_grad(Pow, [numpy.asarray([3.0]), numpy.random.rand(3)])
# def test_scalar_r(self):
# verify_grad(Pow, [numpy.random.rand(3), numpy.asarray([3.0])])
#
utt.
verify_grad(Pow, [numpy.random.rand(3), numpy.asarray([3.0])])
# def test_row(self):
# verify_grad(Pow, [numpy.random.rand(3, 5), numpy.random.rand(1, 5)])
#
utt.
verify_grad(Pow, [numpy.random.rand(3, 5), numpy.random.rand(1, 5)])
# def test_col(self):
# verify_grad(Pow, [numpy.random.rand(3, 5), numpy.random.rand(3, 1)])
#
utt.
verify_grad(Pow, [numpy.random.rand(3, 5), numpy.random.rand(3, 1)])
class
test_matinv
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
mat_reciprocal
(
self
,
dim
):
# symbolic program
...
...
@@ -1306,7 +1306,7 @@ class test_matinv(unittest.TestCase):
# Note that TensorType's constructor does not actually allocate any memory.
# TODO: Make TensorType syntax more explicit, and maybe give shape or number of dimensions.
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
a
,
b
=
matrices
(
'ab'
)
ab
=
a
*
b
...
...
@@ -1337,7 +1337,7 @@ class test_matinv(unittest.TestCase):
"""Matrix reciprocal by gradient descent"""
ssd0
,
ssd
=
self
.
mat_reciprocal
(
3
)
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
# hand-coded numpy implementation for verification
x
=
numpy
.
random
.
rand
(
3
,
3
)
+
0.1
w
=
numpy
.
random
.
rand
(
3
,
3
)
...
...
@@ -1351,7 +1351,7 @@ class test_matinv(unittest.TestCase):
class
t_dot
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
@staticmethod
def
rand
(
*
args
):
return
numpy
.
random
.
rand
(
*
args
)
...
...
@@ -1411,13 +1411,13 @@ class t_dot(unittest.TestCase):
#def test_align_3_3(self): self.not_aligned(self.rand(5,4,3), self.rand(6,7,8))
def
test_grad
(
self
):
#verify_grad(dot, [self.rand(2,3,4), self.rand(4)])
verify_grad
(
dot
,
[
self
.
rand
(
2
,
3
),
self
.
rand
(
3
,
2
)])
verify_grad
(
dot
,
[
self
.
rand
(
2
),
self
.
rand
(
2
,
3
)])
verify_grad
(
dot
,
[
self
.
rand
(
3
,
2
),
self
.
rand
(
2
)])
verify_grad
(
dot
,
[
self
.
rand
(
2
),
self
.
rand
(
2
)])
#verify_grad(dot, [self.rand(), self.rand(2)])
#verify_grad(dot, [self.rand(), self.rand(2,5)])
#
utt.
verify_grad(dot, [self.rand(2,3,4), self.rand(4)])
utt
.
verify_grad
(
dot
,
[
self
.
rand
(
2
,
3
),
self
.
rand
(
3
,
2
)])
utt
.
verify_grad
(
dot
,
[
self
.
rand
(
2
),
self
.
rand
(
2
,
3
)])
utt
.
verify_grad
(
dot
,
[
self
.
rand
(
3
,
2
),
self
.
rand
(
2
)])
utt
.
verify_grad
(
dot
,
[
self
.
rand
(
2
),
self
.
rand
(
2
)])
#
utt.
verify_grad(dot, [self.rand(), self.rand(2)])
#
utt.
verify_grad(dot, [self.rand(), self.rand(2,5)])
class
T_tensorfromscalar
(
unittest
.
TestCase
):
def
test0
(
self
):
...
...
@@ -1464,7 +1464,7 @@ class T_tensorfromscalar(unittest.TestCase):
# class T_tensor(unittest.TestCase):
# def setUp(self):
# u
nittest_tools
.seed_rng()
# u
tt
.seed_rng()
# def test0(self): # allocate from a scalar float
# t = _tensor(1.0)
# self.failUnless(isinstance(t, TensorType))
...
...
@@ -1635,7 +1635,7 @@ class test_grad(unittest.TestCase):
class
T_op_cache
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
"""trigger bug in ticket #162"""
lr
=
constant
(
0.011
)
...
...
@@ -1679,7 +1679,7 @@ def test_reshape():
assert
numpy
.
all
(
a_val
==
a_val_copy
)
# verify gradient
tensor
.
verify_grad
(
Reshape
(
2
),
[
a_val
,
numpy
.
asarray
([
2
,
3
],
dtype
=
'float64'
)])
utt
.
verify_grad
(
Reshape
(
2
),
[
a_val
,
numpy
.
asarray
([
2
,
3
],
dtype
=
'float64'
)])
def
test_flatten_outdimNone
():
...
...
@@ -1695,7 +1695,7 @@ def test_flatten_outdimNone():
f
=
inplace_func
([
a
],
c
)
assert
numpy
.
all
(
f
(
a_val
)
==
c_val
)
tensor
.
verify_grad
(
Flatten
(),
[
a_val
])
utt
.
verify_grad
(
Flatten
(),
[
a_val
])
def
test_flatten_scalar
():
a
=
dscalar
()
...
...
@@ -1707,7 +1707,7 @@ def test_flatten_scalar():
f
=
inplace_func
([
a
],
c
)
assert
numpy
.
all
(
f
(
a_val
)
==
c_val
)
#
tensor
.verify_grad(Flatten(), [a_val]) #TODO: fix verify_grd to work on scalars
#
utt
.verify_grad(Flatten(), [a_val]) #TODO: fix verify_grd to work on scalars
def
test_flatten_outdim1
():
a
=
dmatrix
()
...
...
@@ -1719,7 +1719,7 @@ def test_flatten_outdim1():
f
=
inplace_func
([
a
],
c
)
assert
numpy
.
all
(
f
(
a_val
)
==
c_val
)
tensor
.
verify_grad
(
Flatten
(
1
),
[
a_val
])
utt
.
verify_grad
(
Flatten
(
1
),
[
a_val
])
def
test_flatten_outdim2
():
a
=
dmatrix
()
...
...
@@ -1730,7 +1730,7 @@ def test_flatten_outdim2():
f
=
inplace_func
([
a
],
c
)
assert
numpy
.
all
(
f
(
a_val
)
==
a_val
)
tensor
.
verify_grad
(
Flatten
(
2
),
[
a_val
])
utt
.
verify_grad
(
Flatten
(
2
),
[
a_val
])
def
test_flatten_outdim2_of_3
():
a
=
TensorType
(
'float64'
,
(
False
,
False
,
False
))()
...
...
@@ -1742,7 +1742,7 @@ def test_flatten_outdim2_of_3():
f
=
inplace_func
([
a
],
c
)
assert
numpy
.
all
(
f
(
a_val
)
==
c_val
)
tensor
.
verify_grad
(
Flatten
(
2
),
[
a_val
])
utt
.
verify_grad
(
Flatten
(
2
),
[
a_val
])
def
test_flatten_outdim_invalid
():
a
=
dmatrix
()
...
...
@@ -1765,7 +1765,7 @@ def test_tile():
class
test_tensordot
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
...
...
@@ -1779,7 +1779,7 @@ class test_tensordot(unittest.TestCase):
bval
=
numpy
.
random
.
rand
(
5
);
self
.
failUnless
(
numpy
.
tensordot
(
aval
,
bval
,
axes
)
==
\
f1
(
aval
,
bval
))
tensor
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
# test matrix-vector
bmat
=
dmatrix
()
...
...
@@ -1790,7 +1790,7 @@ class test_tensordot(unittest.TestCase):
bval
=
numpy
.
random
.
rand
(
8
,
5
);
self
.
failUnless
(
numpy
.
all
(
numpy
.
tensordot
(
aval
,
bval
,
axes
)
==
\
f2
(
aval
,
bval
)))
tensor
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
# test matrix-matrix
amat
=
dmatrix
()
...
...
@@ -1801,7 +1801,7 @@ class test_tensordot(unittest.TestCase):
bval
=
numpy
.
random
.
rand
(
7
,
9
);
self
.
failUnless
(
numpy
.
all
(
numpy
.
tensordot
(
aval
,
bval
,
axes
)
==
\
f3
(
aval
,
bval
)))
tensor
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
# test ndarray-matrix, sum over one dim of matrix
atens
=
TensorType
(
'float64'
,
broadcastable
=
(
False
,)
*
4
)()
...
...
@@ -1812,7 +1812,7 @@ class test_tensordot(unittest.TestCase):
bval
=
numpy
.
random
.
rand
(
2
,
3
);
self
.
failUnless
(
numpy
.
all
(
numpy
.
tensordot
(
aval
,
bval
,
axes
)
==
\
f4
(
aval
,
bval
)))
tensor
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
# test ndarray-ndarray
atens
=
TensorType
(
'float64'
,
broadcastable
=
(
False
,)
*
4
)()
...
...
@@ -1824,14 +1824,14 @@ class test_tensordot(unittest.TestCase):
bval
=
numpy
.
random
.
rand
(
3
,
4
,
2
);
self
.
failUnless
(
numpy
.
all
(
numpy
.
tensordot
(
aval
,
bval
,
axes
)
==
\
f5
(
aval
,
bval
)))
tensor
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
axes
=
(
axes
[
1
],
axes
[
0
])
c
=
tensordot
(
axes
)(
btens
,
atens
)
f6
=
inplace_func
([
btens
,
atens
],
c
)
self
.
failUnless
(
numpy
.
all
(
numpy
.
tensordot
(
bval
,
aval
,
axes
)
==
\
f6
(
bval
,
aval
)))
tensor
.
verify_grad
(
TensorDot
(
axes
),
[
bval
,
aval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
bval
,
aval
])
def
test_smallest_stack
():
sx
,
sy
=
dscalar
(),
dscalar
()
...
...
theano/tensor/tests/test_nnet.py
浏览文件 @
9b9602c6
...
...
@@ -5,86 +5,86 @@ from theano import tensor as T
from
theano
import
gof
import
test_basic
as
TT
import
numpy
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.nnet
import
*
class
T_sigmoid
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test_elemwise
(
self
):
TT
.
verify_grad
(
sigmoid
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
sigmoid
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_softplus
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test_elemwise
(
self
):
TT
.
verify_grad
(
softplus
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
softplus
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_Softmax
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
def
f
(
a
):
return
softmax
(
a
)[:,
0
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
def
test1
(
self
):
def
f
(
a
):
return
softmax
(
a
)[:,
1
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
def
test2
(
self
):
def
f
(
a
):
return
softmax
(
a
)[:,
2
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
def
test3
(
self
):
def
f
(
a
):
return
softmax
(
a
)[:,
3
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_SoftmaxWithBias
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
def
f
(
a
,
b
):
return
softmax_with_bias
(
a
,
b
)[:,
0
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
numpy
.
random
.
rand
(
4
)])
def
test1
(
self
):
def
f
(
a
,
b
):
return
softmax_with_bias
(
a
,
b
)[:,
1
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
numpy
.
random
.
rand
(
4
)])
def
test2
(
self
):
def
f
(
a
,
b
):
return
softmax_with_bias
(
a
,
b
)[:,
2
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
numpy
.
random
.
rand
(
4
)])
def
test3
(
self
):
def
f
(
a
,
b
):
return
softmax_with_bias
(
a
,
b
)[:,
3
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
numpy
.
random
.
rand
(
4
)])
class
T_CrossentropySoftmax1Hot
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
y_idx
=
[
0
,
1
,
3
]
def
f
(
a
,
b
):
return
crossentropy_softmax_1hot_with_bias
(
a
,
b
,
y_idx
)[
0
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
),
numpy
.
random
.
rand
(
4
)])
def
test1
(
self
):
y_idx
=
[
0
,
1
,
3
]
def
f
(
a
):
return
crossentropy_softmax_1hot
(
a
,
y_idx
)[
0
]
TT
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_prepend
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
"""basic functionality"""
x
=
tensor
.
matrix
(
'x'
)
...
...
@@ -110,7 +110,7 @@ class T_prepend(unittest.TestCase):
class
T_solve
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
u
nittest_tools
.
fetch_seed
(
666
))
self
.
rng
=
numpy
.
random
.
RandomState
(
u
tt
.
fetch_seed
(
666
))
def
test0
(
self
):
A
=
self
.
rng
.
randn
(
5
,
5
)
...
...
theano/tensor/tests/test_xlogx.py
浏览文件 @
9b9602c6
...
...
@@ -8,11 +8,11 @@ import test_basic as TT
import
random
import
numpy.random
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
as
utt
class
T_XlogX
(
unittest
.
TestCase
):
def
setUp
(
self
):
u
nittest_tools
.
seed_rng
()
u
tt
.
seed_rng
()
def
test0
(
self
):
x
=
as_tensor_variable
([
1
,
0
])
...
...
@@ -23,7 +23,7 @@ class T_XlogX(unittest.TestCase):
# class Dummy(object):
# def make_node(self, a):
# return [xlogx(a)[:,2]]
TT
.
verify_grad
(
xlogx
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
xlogx
,
[
numpy
.
random
.
rand
(
3
,
4
)])
if
__name__
==
'__main__'
:
...
...
theano/tests/unittest_tools.py
浏览文件 @
9b9602c6
import
unittest
import
numpy
import
theano.tensor
as
T
import
os
,
sys
...
...
@@ -40,3 +41,14 @@ def seed_rng(pseed=None):
'instead of seed
%
i given as parameter'
%
(
seed
,
pseed
)
numpy
.
random
.
seed
(
seed
)
return
seed
def
verify_grad
(
op
,
pt
,
n_tests
=
2
,
rng
=
None
,
eps
=
1.0e-7
,
tol
=
0.0001
):
"""
Wrapper for tensor/basic.py:verify_grad
Takes care of seeding the random number generator if None is given
"""
if
rng
is
None
:
seed_rng
()
rng
=
numpy
.
random
T
.
verify_grad
(
op
,
pt
,
n_tests
,
rng
,
eps
,
tol
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论