Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1d017d25
提交
1d017d25
authored
2月 12, 2016
作者:
carriepl
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4009 from AnishShah/elu
Exponential Linear Units (ELUs)
上级
d9e0d1c5
2055feec
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
2 行删除
+46
-2
__init__.py
theano/tensor/nnet/__init__.py
+1
-1
nnet.py
theano/tensor/nnet/nnet.py
+27
-0
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+18
-1
没有找到文件。
theano/tensor/nnet/__init__.py
浏览文件 @
1d017d25
...
@@ -16,7 +16,7 @@ from .nnet import (
...
@@ -16,7 +16,7 @@ from .nnet import (
graph_merge_softmax_with_crossentropy_softmax
,
h_softmax
,
graph_merge_softmax_with_crossentropy_softmax
,
h_softmax
,
logsoftmax
,
logsoftmax_op
,
prepend_0_to_each_row
,
prepend_1_to_each_row
,
logsoftmax
,
logsoftmax_op
,
prepend_0_to_each_row
,
prepend_1_to_each_row
,
prepend_scalar_to_each_row
,
relu
,
softmax
,
softmax_grad
,
softmax_graph
,
prepend_scalar_to_each_row
,
relu
,
softmax
,
softmax_grad
,
softmax_graph
,
softmax_op
,
softmax_simplifier
,
softmax_with_bias
)
softmax_op
,
softmax_simplifier
,
softmax_with_bias
,
elu
)
from
.
import
opt
from
.
import
opt
from
.conv
import
ConvOp
from
.conv
import
ConvOp
from
.Conv3D
import
*
from
.Conv3D
import
*
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
1d017d25
...
@@ -2329,3 +2329,30 @@ def h_softmax(x, batch_size, n_outputs, n_classes, n_outputs_per_class,
...
@@ -2329,3 +2329,30 @@ def h_softmax(x, batch_size, n_outputs, n_classes, n_outputs_per_class,
output_probs
=
target_class_probs
*
output_probs
output_probs
=
target_class_probs
*
output_probs
return
output_probs
return
output_probs
def
elu
(
x
,
alpha
=
1
):
"""
Compute the element-wise exponential linear activation function.
.. versionadded:: 0.8.0
Parameters
----------
x : symbolic tensor
Tensor to compute the activation function for.
alpha : scalar
Returns
-------
symbolic tensor
Element-wise exponential linear activation function applied to `x`.
References
-----
.. [1] Djork-Arne Clevert, Thomas Unterthiner, Sepp Hochreiter
"Fast and Accurate Deep Network Learning by
Exponential Linear Units (ELUs)" <http://arxiv.org/abs/1511.07289>`.
"""
return
tensor
.
switch
(
x
>
0
,
x
,
alpha
*
(
tensor
.
exp
(
x
)
-
1
))
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
1d017d25
...
@@ -29,7 +29,8 @@ from theano.tensor.nnet import (categorical_crossentropy,
...
@@ -29,7 +29,8 @@ from theano.tensor.nnet import (categorical_crossentropy,
Prepend_scalar_constant_to_each_row
,
Prepend_scalar_constant_to_each_row
,
Prepend_scalar_to_each_row
,
Prepend_scalar_to_each_row
,
relu
,
relu
,
h_softmax
)
h_softmax
,
elu
)
from
theano.tensor
import
matrix
,
vector
,
lvector
,
scalar
from
theano.tensor
import
matrix
,
vector
,
lvector
,
scalar
...
@@ -1625,3 +1626,19 @@ def test_h_softmax():
...
@@ -1625,3 +1626,19 @@ def test_h_softmax():
# computed by fun_output.
# computed by fun_output.
utt
.
assert_allclose
(
utt
.
assert_allclose
(
all_outputs
[
numpy
.
arange
(
0
,
batch_size
),
y_mat
],
tg_output
)
all_outputs
[
numpy
.
arange
(
0
,
batch_size
),
y_mat
],
tg_output
)
def
test_elu
():
x
=
matrix
(
'x'
)
seed
=
theano
.
tests
.
unittest_tools
.
fetch_seed
()
rng
=
numpy
.
random
.
RandomState
(
seed
)
X
=
rng
.
randn
(
20
,
30
)
.
astype
(
config
.
floatX
)
# test the base case, without custom alpha value
y
=
elu
(
x
)
.
eval
({
x
:
X
})
utt
.
assert_allclose
(
y
,
numpy
.
where
(
X
>
0
,
X
,
numpy
.
exp
(
X
)
-
1
))
# test for different constant alpha values
for
alpha
in
1.5
,
2
,
-
1
,
-
1.5
,
-
2
:
y
=
elu
(
x
,
alpha
)
.
eval
({
x
:
X
})
utt
.
assert_allclose
(
y
,
numpy
.
where
(
X
>
0
,
X
,
alpha
*
(
numpy
.
exp
(
X
)
-
1
)))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论