Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7987b518
提交
7987b518
authored
12月 18, 2011
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed bug in identification of sigmoid
It used to think that (any_constant + exp(x)) was equal to (1 + exp(x)).
上级
177f1296
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
3 行删除
+26
-3
sigm.py
theano/tensor/nnet/sigm.py
+10
-2
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+16
-1
没有找到文件。
theano/tensor/nnet/sigm.py
浏览文件 @
7987b518
...
@@ -148,8 +148,10 @@ opt.register_stabilize(log1msigm_to_softplus, name = 'log1msigm_to_softplus')
...
@@ -148,8 +148,10 @@ opt.register_stabilize(log1msigm_to_softplus, name = 'log1msigm_to_softplus')
opt
.
register_stabilize
(
log1pexp_to_softplus
,
name
=
'log1pexp_to_softplus'
)
opt
.
register_stabilize
(
log1pexp_to_softplus
,
name
=
'log1pexp_to_softplus'
)
def
is_1pexp
(
t
):
def
is_1pexp
(
t
):
# if t is of form (1+exp(x)), return x
"""
# else return None
If 't' is of the form (1+exp(x)), return (False, x).
Else return None.
"""
if
t
.
owner
and
t
.
owner
.
op
==
tensor
.
add
:
if
t
.
owner
and
t
.
owner
.
op
==
tensor
.
add
:
scalars
,
scalar_inputs
,
nonconsts
=
\
scalars
,
scalar_inputs
,
nonconsts
=
\
opt
.
scalarconsts_rest
(
t
.
owner
.
inputs
)
opt
.
scalarconsts_rest
(
t
.
owner
.
inputs
)
...
@@ -157,6 +159,12 @@ def is_1pexp(t):
...
@@ -157,6 +159,12 @@ def is_1pexp(t):
if
len
(
nonconsts
)
==
1
:
if
len
(
nonconsts
)
==
1
:
maybe_exp
=
nonconsts
[
0
]
maybe_exp
=
nonconsts
[
0
]
if
maybe_exp
.
owner
and
maybe_exp
.
owner
.
op
==
tensor
.
exp
:
if
maybe_exp
.
owner
and
maybe_exp
.
owner
.
op
==
tensor
.
exp
:
# Verify that the constant terms sum to 1.
if
scalars
:
scal_sum
=
scalars
[
0
]
for
s
in
scalars
[
1
:]:
scal_sum
=
scal_sum
+
s
if
numpy
.
allclose
(
scal_sum
,
1
):
return
False
,
maybe_exp
.
owner
.
inputs
[
0
]
return
False
,
maybe_exp
.
owner
.
inputs
[
0
]
return
None
return
None
...
...
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
7987b518
import
unittest
import
unittest
from
itertools
import
imap
import
numpy
import
numpy
...
@@ -8,7 +9,7 @@ from theano import config
...
@@ -8,7 +9,7 @@ from theano import config
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.nnet
import
sigmoid
,
sigmoid_inplace
,
softplus
,
tensor
from
theano.tensor.nnet
import
sigmoid
,
sigmoid_inplace
,
softplus
,
tensor
from
theano.tensor.nnet.sigm
import
(
from
theano.tensor.nnet.sigm
import
(
compute_mul
,
parse_mul_tree
,
perform_sigm_times_exp
,
compute_mul
,
is_1pexp
,
parse_mul_tree
,
perform_sigm_times_exp
,
register_local_1msigmoid
,
simplify_mul
)
register_local_1msigmoid
,
simplify_mul
)
...
@@ -235,3 +236,17 @@ class T_sigmoid_utils(unittest.TestCase):
...
@@ -235,3 +236,17 @@ class T_sigmoid_utils(unittest.TestCase):
assert
parse_mul_tree
(
-
x
)
==
[
True
,
x
]
assert
parse_mul_tree
(
-
x
)
==
[
True
,
x
]
assert
parse_mul_tree
((
x
*
y
)
*
-
z
)
==
[
assert
parse_mul_tree
((
x
*
y
)
*
-
z
)
==
[
False
,
[[
False
,
[[
False
,
x
],
[
False
,
y
]]],
[
True
,
z
]]]
False
,
[[
False
,
[[
False
,
x
],
[
False
,
y
]]],
[
True
,
z
]]]
def
test_is_1pexp
(
self
):
x
=
tensor
.
vector
(
'x'
)
exp
=
tensor
.
exp
assert
is_1pexp
(
1
+
exp
(
x
))
==
(
False
,
x
)
assert
is_1pexp
(
exp
(
x
)
+
1
)
==
(
False
,
x
)
for
neg
,
exp_arg
in
imap
(
is_1pexp
,
[(
1
+
exp
(
-
x
)),
(
exp
(
-
x
)
+
1
)]):
assert
not
neg
and
theano
.
gof
.
graph
.
is_same_graph
(
exp_arg
,
-
x
)
assert
is_1pexp
(
1
-
exp
(
x
))
is
None
assert
is_1pexp
(
2
+
exp
(
x
))
is
None
assert
is_1pexp
(
exp
(
x
)
+
2
)
is
None
assert
is_1pexp
(
exp
(
x
)
-
1
)
is
None
assert
is_1pexp
(
-
1
+
exp
(
x
))
is
None
assert
is_1pexp
(
1
+
2
*
exp
(
x
))
is
None
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论