Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2611ec31
提交
2611ec31
authored
4月 12, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
13cb7ed2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
16 行删除
+16
-16
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+16
-16
没有找到文件。
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
2611ec31
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
numpy
import
numpy
as
np
from
theano.compat
import
imap
import
theano.tensor.inplace
...
...
@@ -26,12 +26,12 @@ class T_sigmoid(unittest.TestCase):
utt
.
seed_rng
()
def
test_elemwise
(
self
):
utt
.
verify_grad
(
sigmoid
,
[
n
umpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
sigmoid
,
[
n
p
.
random
.
rand
(
3
,
4
)])
SigmoidTester
=
makeBroadcastTester
(
op
=
sigmoid
,
expected
=
upcast_int8_nfunc
(
lambda
inputs
:
check_floatX
(
inputs
,
1
/
(
1
+
n
umpy
.
exp
(
-
inputs
)))),
inputs
,
1
/
(
1
+
n
p
.
exp
(
-
inputs
)))),
good
=
copymod
(
_good_broadcast_unary_normal_no_complex
,
without
=
[
'uint16'
]),
# The reason that 'uint16' is excluted is that
# theano works well but numpy overflows resulting
...
...
@@ -43,7 +43,7 @@ SigmoidTester = makeBroadcastTester(
UltraFastSigmoidTester
=
makeBroadcastTester
(
op
=
ultra_fast_sigmoid
,
expected
=
upcast_int8_nfunc
(
lambda
inputs
:
check_floatX
(
inputs
,
1
/
(
1
+
n
umpy
.
exp
(
-
inputs
)))),
inputs
,
1
/
(
1
+
n
p
.
exp
(
-
inputs
)))),
good
=
copymod
(
_good_broadcast_unary_normal_no_complex
,
without
=
[
'uint16'
]),
# numpy fucnting overflows with uint16.
# grad=_grad_broadcast_unary_normal,
...
...
@@ -54,7 +54,7 @@ UltraFastSigmoidTester = makeBroadcastTester(
HardSigmoidTester
=
makeBroadcastTester
(
op
=
hard_sigmoid
,
expected
=
upcast_int8_nfunc
(
lambda
inputs
:
check_floatX
(
inputs
,
1
/
(
1
+
n
umpy
.
exp
(
-
inputs
)))),
inputs
,
1
/
(
1
+
n
p
.
exp
(
-
inputs
)))),
good
=
copymod
(
_good_broadcast_unary_normal_no_complex
,
without
=
[
'uint16'
]),
# numpy fucnting overflows with uint16.
# grad=_grad_broadcast_unary_normal,
...
...
@@ -66,11 +66,11 @@ HardSigmoidTester = makeBroadcastTester(
SoftplusTester
=
makeBroadcastTester
(
op
=
softplus
,
expected
=
upcast_int8_nfunc
(
lambda
inputs
:
check_floatX
(
inputs
,
n
umpy
.
log1p
(
numpy
.
exp
(
inputs
)))),
inputs
,
n
p
.
log1p
(
np
.
exp
(
inputs
)))),
good
=
dict
(
copymod
(
_good_broadcast_unary_normal_no_complex
,
without
=
[
'uint8'
,
'uint16'
]),
# numpy fucnting overflows with uint16.
uint8
=
[
n
umpy
.
arange
(
0
,
89
,
dtype
=
'uint8'
)],
# the range is different in new added uint8.
int8
=
[
n
umpy
.
arange
(
-
127
,
89
,
dtype
=
'int8'
)]),
uint8
=
[
n
p
.
arange
(
0
,
89
,
dtype
=
'uint8'
)],
# the range is different in new added uint8.
int8
=
[
n
p
.
arange
(
-
127
,
89
,
dtype
=
'int8'
)]),
# grad=_grad_broadcast_unary_normal,
name
=
'SoftplusTester'
,
)
...
...
@@ -81,7 +81,7 @@ class T_softplus(unittest.TestCase):
utt
.
seed_rng
()
def
test_elemwise
(
self
):
utt
.
verify_grad
(
softplus
,
[
n
umpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
softplus
,
[
n
p
.
random
.
rand
(
3
,
4
)])
class
T_sigmoid_opts
(
unittest
.
TestCase
):
...
...
@@ -112,7 +112,7 @@ class T_sigmoid_opts(unittest.TestCase):
m
=
self
.
get_mode
(
excluding
=
[
'local_elemwise_fusion'
])
x
=
T
.
vector
()
data
=
n
umpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
)
data
=
n
p
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
)
backup
=
config
.
warn
.
identify_1pexp_bug
config
.
warn
.
identify_1pexp_bug
=
False
...
...
@@ -321,7 +321,7 @@ class T_sigmoid_opts(unittest.TestCase):
if
not
isinstance
(
mode
,
theano
.
compile
.
DebugMode
):
f
=
theano
.
function
([
x
,
lr
],
ux
,
mode
=
mode
)
ux_v
=
f
([[
50
]],
0.1
)
assert
not
n
umpy
.
isnan
(
ux_v
)
assert
not
n
p
.
isnan
(
ux_v
)
def
test_local_ultra_fast_sigmoid
(
self
):
x
=
tensor
.
matrix
(
'x'
)
...
...
@@ -391,7 +391,7 @@ class T_softplus_opts(unittest.TestCase):
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
n
umpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
f
(
n
p
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
def
test_log1msigm_to_softplus
(
self
):
x
=
T
.
matrix
()
...
...
@@ -404,7 +404,7 @@ class T_softplus_opts(unittest.TestCase):
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
# assert check_stack_trace(f, ops_to_check='all')
f
(
n
umpy
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
f
(
n
p
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
# Same test with a flatten
out
=
T
.
log
(
1
-
T
.
flatten
(
sigmoid
(
x
)))
...
...
@@ -417,7 +417,7 @@ class T_softplus_opts(unittest.TestCase):
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
n
umpy
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
f
(
n
p
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
# Same test with a reshape
out
=
T
.
log
(
1
-
sigmoid
(
x
)
.
reshape
([
x
.
size
]))
...
...
@@ -428,7 +428,7 @@ class T_softplus_opts(unittest.TestCase):
assert
any
(
isinstance
(
getattr
(
node
.
op
,
'scalar_op'
,
None
),
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
for
node
in
topo
)
f
(
n
umpy
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
f
(
n
p
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
def
test_log1pexp_to_softplus
(
self
):
m
=
theano
.
config
.
mode
...
...
@@ -446,7 +446,7 @@ class T_softplus_opts(unittest.TestCase):
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
f
(
n
umpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
f
(
n
p
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
))
class
T_sigmoid_utils
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论