Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c8e60308
提交
c8e60308
authored
4月 11, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
6c87a2e9
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
12 行删除
+12
-12
sigm.py
theano/tensor/nnet/sigm.py
+12
-12
没有找到文件。
theano/tensor/nnet/sigm.py
浏览文件 @
c8e60308
...
...
@@ -9,7 +9,7 @@ from __future__ import absolute_import, print_function, division
import
warnings
import
numpy
import
numpy
as
np
import
theano
from
theano
import
config
,
gof
,
printing
,
scalar
...
...
@@ -41,8 +41,8 @@ class ScalarSigmoid(scalar.UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
1.0
/
(
1.0
+
n
umpy
.
exp
(
-
x
,
sig
=
'f'
))
return
1.0
/
(
1.0
+
n
umpy
.
exp
(
-
x
))
return
1.0
/
(
1.0
+
n
p
.
exp
(
-
x
,
sig
=
'f'
))
return
1.0
/
(
1.0
+
n
p
.
exp
(
-
x
))
def
impl
(
self
,
x
):
return
ScalarSigmoid
.
st_impl
(
x
)
...
...
@@ -134,8 +134,8 @@ class ScalarSigmoid(scalar.UnaryScalarOp):
This method was used to generate the graph: sigmoid_prec.png in the doc.
"""
data
=
n
umpy
.
arange
(
-
15
,
15
,
.
1
)
val
=
1
/
(
1
+
n
umpy
.
exp
(
-
data
))
data
=
n
p
.
arange
(
-
15
,
15
,
.
1
)
val
=
1
/
(
1
+
n
p
.
exp
(
-
data
))
def
hard_sigmoid
(
x
):
return
theano
.
tensor
.
nnet
.
hard_sigmoid
(
x
)
...
...
@@ -330,8 +330,8 @@ class ScalarSoftplus(scalar.UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
log1p
(
numpy
.
exp
(
x
,
sig
=
'f'
))
return
n
umpy
.
log1p
(
numpy
.
exp
(
x
))
return
n
p
.
log1p
(
np
.
exp
(
x
,
sig
=
'f'
))
return
n
p
.
log1p
(
np
.
exp
(
x
))
def
impl
(
self
,
x
):
return
ScalarSoftplus
.
static_impl
(
x
)
...
...
@@ -399,7 +399,7 @@ def _is_1(expr):
"""
try
:
v
=
opt
.
get_scalar_constant_value
(
expr
)
return
n
umpy
.
allclose
(
v
,
1
)
return
n
p
.
allclose
(
v
,
1
)
except
tensor
.
NotScalarConstantError
:
return
False
...
...
@@ -457,7 +457,7 @@ def is_1pexp(t, only_process_constants=True):
scal_sum
=
scalars
[
0
]
for
s
in
scalars
[
1
:]:
scal_sum
=
scal_sum
+
s
if
n
umpy
.
allclose
(
scal_sum
,
1
):
if
n
p
.
allclose
(
scal_sum
,
1
):
return
False
,
maybe_exp
.
owner
.
inputs
[
0
]
# Before 7987b51 there used to be a bug where *any* constant
# was considered as if it was equal to 1, and thus this
...
...
@@ -569,7 +569,7 @@ def is_neg(var):
for
idx
,
mul_input
in
enumerate
(
apply
.
inputs
):
try
:
constant
=
opt
.
get_scalar_constant_value
(
mul_input
)
is_minus_1
=
n
umpy
.
allclose
(
constant
,
-
1
)
is_minus_1
=
n
p
.
allclose
(
constant
,
-
1
)
except
NotScalarConstantError
:
is_minus_1
=
False
if
is_minus_1
:
...
...
@@ -968,7 +968,7 @@ def local_inv_1_plus_exp(node):
# scalar_inputs are potentially dimshuffled and fill'd scalars
if
len
(
nonconsts
)
==
1
:
if
nonconsts
[
0
]
.
owner
and
nonconsts
[
0
]
.
owner
.
op
==
tensor
.
exp
:
if
scalars
and
n
umpy
.
allclose
(
numpy
.
sum
(
scalars
),
1
):
if
scalars
and
n
p
.
allclose
(
np
.
sum
(
scalars
),
1
):
out
=
opt
.
_fill_chain
(
sigmoid
(
tensor
.
neg
(
nonconsts
[
0
]
.
owner
.
inputs
[
0
])),
...
...
@@ -999,7 +999,7 @@ def local_1msigmoid(node):
val_l
=
opt
.
get_scalar_constant_value
(
sub_l
)
except
Exception
:
return
if
n
umpy
.
allclose
(
numpy
.
sum
(
val_l
),
1
):
if
n
p
.
allclose
(
np
.
sum
(
val_l
),
1
):
out
=
sigmoid
(
-
sub_r
.
owner
.
inputs
[
0
])
copy_stack_trace
([
sub_r
,
node
.
outputs
[
0
]],
out
)
return
[
out
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论