Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7624f7d6
提交
7624f7d6
authored
12月 19, 2011
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #303 from nouiz/test_sigm_opt
Test sigm opt
上级
9286ae17
adaf2584
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
98 行增加
和
35 行删除
+98
-35
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+98
-35
没有找到文件。
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
7624f7d6
...
@@ -16,14 +16,18 @@ from theano.tensor.nnet.sigm import (
...
@@ -16,14 +16,18 @@ from theano.tensor.nnet.sigm import (
class
T_sigmoid
(
unittest
.
TestCase
):
class
T_sigmoid
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
def
test_elemwise
(
self
):
def
test_elemwise
(
self
):
utt
.
verify_grad
(
sigmoid
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
sigmoid
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_softplus
(
unittest
.
TestCase
):
class
T_softplus
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
def
test_elemwise
(
self
):
def
test_elemwise
(
self
):
utt
.
verify_grad
(
softplus
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
softplus
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_sigmoid_opts
(
unittest
.
TestCase
):
class
T_sigmoid_opts
(
unittest
.
TestCase
):
...
@@ -50,31 +54,89 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -50,31 +54,89 @@ class T_sigmoid_opts(unittest.TestCase):
def
test_exp_over_1_plus_exp
(
self
):
def
test_exp_over_1_plus_exp
(
self
):
m
=
self
.
get_mode
(
excluding
=
[
'local_elemwise_fusion'
])
m
=
self
.
get_mode
(
excluding
=
[
'local_elemwise_fusion'
])
x
=
T
.
dvector
()
x
=
T
.
vector
()
data
=
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
)
# tests exp_over_1_plus_exp
# tests exp_over_1_plus_exp
f
=
theano
.
function
([
x
],
T
.
exp
(
x
)
/
(
1
+
T
.
exp
(
x
)),
mode
=
m
)
f
=
theano
.
function
([
x
],
T
.
exp
(
x
)
/
(
1
+
T
.
exp
(
x
)),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
]
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
exp
(
x
)
/
(
2
+
T
.
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
exp
(
x
)
/
(
1
-
T
.
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
exp
(
x
+
1
)
/
(
1
+
T
.
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
# tests inv_1_plus_exp
# tests inv_1_plus_exp
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
]
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
1.0
)
/
(
2
+
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
1.0
)
/
(
1
-
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
1.1
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
# tests inv_1_plus_exp with neg
# tests inv_1_plus_exp with neg
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
,
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
,
theano
.
tensor
.
inplace
.
neg_inplace
]
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.0
)
/
(
1
-
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.0
)
/
(
2
+
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.1
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
# tests double inv_1_plus_exp with neg
# tests double inv_1_plus_exp with neg
# (-1)(exp(x)) / (1+exp(x))(1+exp(-x))
# (-1)(exp(x)) / (1+exp(x))(1+exp(-x))
# = (-1)/(1+exp(-x)) * exp(x)/(1+exp(x))
# = (-1)/(1+exp(-x)) * exp(x)/(1+exp(x))
# = - (sigm(x) * sigm(x))
# = - (sigm(x) * sigm(x))
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
-
x
))),
mode
=
m
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
theano
.
printing
.
debugprint
(
f
)
((
1
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
-
x
))),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
,
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
,
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.1
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
-
x
))),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
2
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
-
x
))),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
2
+
T
.
exp
(
-
x
))),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
x
))),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
2
+
T
.
exp
(
-
x
))),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
!=
[
sigmoid
,
T
.
mul
,
theano
.
tensor
.
inplace
.
neg_inplace
]
f
(
data
)
def
test_1msigmoid
(
self
):
def
test_1msigmoid
(
self
):
if
not
register_local_1msigmoid
:
if
not
register_local_1msigmoid
:
...
@@ -84,13 +146,12 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -84,13 +146,12 @@ class T_sigmoid_opts(unittest.TestCase):
x
=
T
.
fmatrix
()
x
=
T
.
fmatrix
()
# tests exp_over_1_plus_exp
# tests exp_over_1_plus_exp
f
=
theano
.
function
([
x
],
1
-
T
.
exp
(
x
)
/
(
1
+
T
.
exp
(
x
)),
mode
=
m
)
f
=
theano
.
function
([
x
],
1
-
T
.
exp
(
x
)
/
(
1
+
T
.
exp
(
x
)),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
tensor
.
neg
,
sigmoid_inplace
]
tensor
.
neg
,
sigmoid_inplace
]
# tests inv_1_plus_exp
# tests inv_1_plus_exp
f
=
theano
.
function
([
x
],
1
-
T
.
fill
(
x
,
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
f
=
theano
.
function
([
x
],
1
-
T
.
fill
(
x
,
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
tensor
.
neg
,
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
tensor
.
neg
,
sigmoid_inplace
]
sigmoid_inplace
]
...
@@ -107,23 +168,19 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -107,23 +168,19 @@ class T_sigmoid_opts(unittest.TestCase):
x
,
y
=
tensor
.
vectors
(
'x'
,
'y'
)
x
,
y
=
tensor
.
vectors
(
'x'
,
'y'
)
f
=
theano
.
function
([
x
],
sigmoid
(
-
x
)
*
tensor
.
exp
(
x
),
mode
=
m
)
f
=
theano
.
function
([
x
],
sigmoid
(
-
x
)
*
tensor
.
exp
(
x
),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
match
(
f
,
[
sigmoid
])
match
(
f
,
[
sigmoid
])
f
=
theano
.
function
([
x
],
sigmoid
(
x
)
*
tensor
.
exp
(
-
x
),
mode
=
m
)
f
=
theano
.
function
([
x
],
sigmoid
(
x
)
*
tensor
.
exp
(
-
x
),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
match
(
f
,
[
tensor
.
neg
,
sigmoid
])
match
(
f
,
[
tensor
.
neg
,
sigmoid
])
f
=
theano
.
function
([
x
],
-
(
-
(
-
(
sigmoid
(
x
))))
*
tensor
.
exp
(
-
x
),
mode
=
m
)
f
=
theano
.
function
([
x
],
-
(
-
(
-
(
sigmoid
(
x
))))
*
tensor
.
exp
(
-
x
),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
match
(
f
,
[
tensor
.
neg
,
sigmoid
,
tensor
.
neg
])
match
(
f
,
[
tensor
.
neg
,
sigmoid
,
tensor
.
neg
])
f
=
theano
.
function
(
f
=
theano
.
function
(
[
x
,
y
],
[
x
,
y
],
(
sigmoid
(
x
)
*
sigmoid
(
-
y
)
*
-
tensor
.
exp
(
-
x
)
*
tensor
.
exp
(
x
*
y
)
*
(
sigmoid
(
x
)
*
sigmoid
(
-
y
)
*
-
tensor
.
exp
(
-
x
)
*
tensor
.
exp
(
y
)),
tensor
.
exp
(
x
*
y
)
*
tensor
.
exp
(
y
)),
mode
=
m
)
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
match
(
f
,
[
sigmoid
,
tensor
.
mul
,
tensor
.
neg
,
tensor
.
exp
,
sigmoid
,
match
(
f
,
[
sigmoid
,
tensor
.
mul
,
tensor
.
neg
,
tensor
.
exp
,
sigmoid
,
tensor
.
mul
,
tensor
.
neg
])
tensor
.
mul
,
tensor
.
neg
])
...
@@ -136,6 +193,7 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -136,6 +193,7 @@ class T_sigmoid_opts(unittest.TestCase):
"""
"""
x
,
y
,
z
,
t
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
,
't'
)
x
,
y
,
z
,
t
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
,
't'
)
exp
=
tensor
.
exp
exp
=
tensor
.
exp
def
ok
(
expr1
,
expr2
):
def
ok
(
expr1
,
expr2
):
trees
=
[
parse_mul_tree
(
e
)
for
e
in
(
expr1
,
expr2
)]
trees
=
[
parse_mul_tree
(
e
)
for
e
in
(
expr1
,
expr2
)]
perform_sigm_times_exp
(
trees
[
0
])
perform_sigm_times_exp
(
trees
[
0
])
...
@@ -170,32 +228,36 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -170,32 +228,36 @@ class T_sigmoid_opts(unittest.TestCase):
class
T_softplus_opts
(
unittest
.
TestCase
):
class
T_softplus_opts
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
m
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'local_elemwise_fusion'
)
m
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'local_elemwise_fusion'
)
else
:
else
:
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'local_elemwise_fusion'
)
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'local_elemwise_fusion'
)
self
.
m
=
m
self
.
m
=
m
utt
.
seed_rng
()
utt
.
seed_rng
()
def
test_logsigm_to_softplus
(
self
):
def
test_logsigm_to_softplus
(
self
):
x
=
T
.
vector
()
x
=
T
.
vector
()
out
=
T
.
log
(
sigmoid
(
x
))
out
=
T
.
log
(
sigmoid
(
x
))
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
print
topo
assert
len
(
topo
)
==
3
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
def
test_log1msigm_to_softplus
(
self
):
def
test_log1msigm_to_softplus
(
self
):
x
=
T
.
vector
()
x
=
T
.
vector
()
out
=
T
.
log
(
1
-
sigmoid
(
x
))
out
=
T
.
log
(
1
-
sigmoid
(
x
))
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
...
@@ -206,11 +268,12 @@ class T_softplus_opts(unittest.TestCase):
...
@@ -206,11 +268,12 @@ class T_softplus_opts(unittest.TestCase):
x
=
T
.
vector
()
x
=
T
.
vector
()
out
=
T
.
log
(
1
+
T
.
exp
(
x
))
out
=
T
.
log
(
1
+
T
.
exp
(
x
))
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论