Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d5c0893a
提交
d5c0893a
authored
5月 27, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added doc about ultra_fast_sigmoid.
上级
6361bb2b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
57 行增加
和
0 行删除
+57
-0
nnet.txt
doc/library/tensor/nnet/nnet.txt
+13
-0
sigm.py
theano/tensor/nnet/sigm.py
+31
-0
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+13
-0
没有找到文件。
doc/library/tensor/nnet/nnet.txt
浏览文件 @
d5c0893a
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
:Parameters: *x* - symbolic Tensor (or compatible)
:Parameters: *x* - symbolic Tensor (or compatible)
:Return type: same as x
:Return type: same as x
:Returns: element-wise sigmoid: :math:`sigmoid(x) = \frac{1}{1 + \exp(-x)}`.
:Returns: element-wise sigmoid: :math:`sigmoid(x) = \frac{1}{1 + \exp(-x)}`.
:note: see :func:`ultra_fast_sigmoid` for a faster version
Example:
Example:
...
@@ -26,6 +27,18 @@ Example:
...
@@ -26,6 +27,18 @@ Example:
.. note:: The underlying code will return an exact 0 or 1 if an element of x is too small or too big.
.. note:: The underlying code will return an exact 0 or 1 if an element of x is too small or too big.
.. function:: ultra_fast_sigmoid(x)
Returns the standard sigmoid nonlinearity applied to x
:Parameters: *x* - symbolic Tensor (or compatible)
:Return type: same as x
:Returns: approximated element-wise sigmoid: :math:`sigmoid(x) = \frac{1}{1 + \exp(-x)}`.
:note: To automatically change all sigmoid op to this version, use
the Theano optimization ``local_ultra_fast_sigmoid``. This can be done
with the Theano flag ``optimizer_including=local_ultra_fast_sigmoid``.
This optimization is done late, so it shouldn't affect
stabilization optimization.
.. function:: softplus(x)
.. function:: softplus(x)
Returns the softplus nonlinearity applied to x
Returns the softplus nonlinearity applied to x
...
...
theano/tensor/nnet/sigm.py
浏览文件 @
d5c0893a
...
@@ -192,6 +192,37 @@ pprint.assign(ultra_fast_sigmoid,
...
@@ -192,6 +192,37 @@ pprint.assign(ultra_fast_sigmoid,
printing
.
FunctionPrinter
(
'ultra_fast_sigmoid'
))
printing
.
FunctionPrinter
(
'ultra_fast_sigmoid'
))
#@opt.register_uncanonicalize
@gof.local_optimizer
([
sigmoid
])
def
local_ultra_fast_sigmoid
(
node
):
"""
When enabled, change all sigmoid to ultra_fast_sigmoid.
To example do mode.including('local_ultra_fast_sigmoid')
or use the Theano flag optimizer_including=local_ultra_fast_sigmoid
This speed up the sigmoid op by using an approximation.
This is done after the stabilization and specialize phase
to don't interact with them.
"""
if
(
isinstance
(
node
.
op
,
tensor
.
Elemwise
)
and
node
.
op
.
scalar_op
==
scalar_sigmoid
):
out
=
ultra_fast_sigmoid
(
node
.
inputs
[
0
])
out2
=
ultra_fast_sigmoid
(
node
.
inputs
[
0
])
def
values_eq_approx_remove_low_prec
(
a
,
b
):
# atol is found by trial/error.
# Other test could fail without good reason.
return
tensor
.
TensorType
.
values_eq_approx
(
a
,
b
,
atol
=
0.02
)
# Let DebugMode know that there this opt approx the values.
out
.
values_eq_approx
=
values_eq_approx_remove_low_prec
return
[
out
]
theano
.
compile
.
optdb
[
'uncanonicalize'
]
.
register
(
"local_ultra_fast_sigmoid"
,
local_ultra_fast_sigmoid
)
class
ScalarSoftplus
(
scalar
.
UnaryScalarOp
):
class
ScalarSoftplus
(
scalar
.
UnaryScalarOp
):
@staticmethod
@staticmethod
def
static_impl
(
x
):
def
static_impl
(
x
):
...
...
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
d5c0893a
...
@@ -289,6 +289,19 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -289,6 +289,19 @@ class T_sigmoid_opts(unittest.TestCase):
ux_v
=
f
([[
50
]],
0.1
)
ux_v
=
f
([[
50
]],
0.1
)
assert
not
numpy
.
isnan
(
ux_v
)
assert
not
numpy
.
isnan
(
ux_v
)
def
test_local_ultra_fast_sigmoid
(
self
):
x
=
tensor
.
matrix
(
'x'
)
s
=
sigmoid
(
x
)
mode
=
self
.
get_mode
(
'local_ultra_fast_sigmoid'
)
f
=
theano
.
function
([
x
],
s
,
mode
=
mode
)
assert
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
==
sigmoid
mode
=
self
.
get_mode
()
.
including
(
'local_ultra_fast_sigmoid'
)
f
=
theano
.
function
([
x
],
s
,
mode
=
mode
)
assert
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
==
ultra_fast_sigmoid
ux_v
=
f
([[
-
50
,
-
10
,
-
4
,
-
1
,
0
,
1
,
4
,
10
,
50
]])
class
T_softplus_opts
(
unittest
.
TestCase
):
class
T_softplus_opts
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论