Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ba333e8a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ba333e8a
编写于
5月 22, 2017
作者:
E
emailweixu
提交者:
GitHub
5月 22, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2219 from emailweixu/sqrt-reciprocal
Add Sqrt and Reciprocal activation
上级
d3e003be
a0a3a685
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
100 addition
and
2 deletion
+100
-2
paddle/gserver/activations/ActivationFunction.cpp
paddle/gserver/activations/ActivationFunction.cpp
+38
-0
python/paddle/trainer_config_helpers/activations.py
python/paddle/trainer_config_helpers/activations.py
+25
-1
python/paddle/trainer_config_helpers/layer_math.py
python/paddle/trainer_config_helpers/layer_math.py
+2
-0
python/paddle/trainer_config_helpers/tests/configs/math_ops.py
...n/paddle/trainer_config_helpers/tests/configs/math_ops.py
+2
-0
python/paddle/trainer_config_helpers/tests/configs/protostr/math_ops.protostr
...r_config_helpers/tests/configs/protostr/math_ops.protostr
+33
-1
未找到文件。
paddle/gserver/activations/ActivationFunction.cpp
浏览文件 @
ba333e8a
...
...
@@ -396,6 +396,44 @@ Error __must_check backward(Argument& act) {
}
END_DEFINE_ACTIVATION
(
exponential
)
/**
* @brief Reciprocal Activation.
* \f[
* f(z) = 1/z
* \f]
*/
BEGIN_DEFINE_ACTIVATION
(
reciprocal
)
Error
__must_check
forward
(
Argument
&
act
)
{
act
.
value
->
reciprocal2
();
return
Error
();
}
Error
__must_check
backward
(
Argument
&
act
)
{
act
.
grad
->
dotMulSquare
(
*
act
.
value
);
act
.
grad
->
neg
();
return
Error
();
}
END_DEFINE_ACTIVATION
(
reciprocal
)
/**
* @brief Square Root Activation.
* \f[
* f(z) = sqrt(z)
* \f]
*/
BEGIN_DEFINE_ACTIVATION
(
sqrt
)
Error
__must_check
forward
(
Argument
&
act
)
{
act
.
value
->
sqrt2
();
return
Error
();
}
Error
__must_check
backward
(
Argument
&
act
)
{
act
.
grad
->
dotDiv
(
*
act
.
grad
,
*
act
.
value
);
act
.
grad
->
mulScalar
(
0.5
);
return
Error
();
}
END_DEFINE_ACTIVATION
(
sqrt
)
/**
* @brief Logarithm Activation.
* \f[
...
...
python/paddle/trainer_config_helpers/activations.py
浏览文件 @
ba333e8a
...
...
@@ -17,7 +17,7 @@ __all__ = [
"IdentityActivation"
,
"LinearActivation"
,
'SequenceSoftmaxActivation'
,
'ExpActivation'
,
"ReluActivation"
,
"BReluActivation"
,
"SoftReluActivation"
,
"STanhActivation"
,
"AbsActivation"
,
"SquareActivation"
,
"BaseActivation"
,
"LogActivation"
"LogActivation"
,
"SqrtActivation"
,
"ReciprocalActivation"
]
...
...
@@ -224,3 +224,27 @@ class LogActivation(BaseActivation):
def
__init__
(
self
):
BaseActivation
.
__init__
(
self
,
'log'
,
False
)
class
SqrtActivation
(
BaseActivation
):
"""
Square Root Activation.
.. math::
f(z) = sqrt(z)
"""
def
__init__
(
self
):
BaseActivation
.
__init__
(
self
,
'sqrt'
,
False
)
class
ReciprocalActivation
(
BaseActivation
):
"""
Reciprocal Activation.
.. math::
f(z) = 1/z
"""
def
__init__
(
self
):
BaseActivation
.
__init__
(
self
,
'reciprocal'
,
False
)
python/paddle/trainer_config_helpers/layer_math.py
浏览文件 @
ba333e8a
...
...
@@ -40,6 +40,8 @@ register_unary_math_op('sigmoid', act.SigmoidActivation())
register_unary_math_op
(
'tanh'
,
act
.
TanhActivation
())
register_unary_math_op
(
'square'
,
act
.
SquareActivation
())
register_unary_math_op
(
'relu'
,
act
.
ReluActivation
())
register_unary_math_op
(
'sqrt'
,
act
.
SqrtActivation
())
register_unary_math_op
(
'reciprocal'
,
act
.
ReciprocalActivation
())
def
add
(
layeroutput
,
other
):
...
...
python/paddle/trainer_config_helpers/tests/configs/math_ops.py
浏览文件 @
ba333e8a
...
...
@@ -4,6 +4,8 @@ settings(batch_size=1000, learning_rate=1e-5)
x
=
data_layer
(
name
=
'data'
,
size
=
100
)
x
=
layer_math
.
exp
(
x
)
x
=
layer_math
.
sqrt
(
x
)
x
=
layer_math
.
reciprocal
(
x
)
x
=
layer_math
.
log
(
x
)
x
=
layer_math
.
abs
(
x
)
x
=
layer_math
.
sigmoid
(
x
)
...
...
python/paddle/trainer_config_helpers/tests/configs/protostr/math_ops.protostr
浏览文件 @
ba333e8a
...
...
@@ -20,13 +20,43 @@ layers {
}
}
}
layers {
name: "__sqrt_0__"
type: "mixed"
size: 100
active_type: "sqrt"
inputs {
input_layer_name: "__exp_0__"
proj_conf {
type: "identity"
name: "___sqrt_0__.w0"
input_size: 100
output_size: 100
}
}
}
layers {
name: "__reciprocal_0__"
type: "mixed"
size: 100
active_type: "reciprocal"
inputs {
input_layer_name: "__sqrt_0__"
proj_conf {
type: "identity"
name: "___reciprocal_0__.w0"
input_size: 100
output_size: 100
}
}
}
layers {
name: "__log_0__"
type: "mixed"
size: 100
active_type: "log"
inputs {
input_layer_name: "__
exp
_0__"
input_layer_name: "__
reciprocal
_0__"
proj_conf {
type: "identity"
name: "___log_0__.w0"
...
...
@@ -351,6 +381,8 @@ sub_models {
name: "root"
layer_names: "data"
layer_names: "__exp_0__"
layer_names: "__sqrt_0__"
layer_names: "__reciprocal_0__"
layer_names: "__log_0__"
layer_names: "__abs_0__"
layer_names: "__sigmoid_0__"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录