Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
dadace31
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
dadace31
编写于
9月 14, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more activation functors
上级
e515f18d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
1 deletion
+61
-1
paddle/operators/activation_op.h
paddle/operators/activation_op.h
+61
-1
未找到文件。
paddle/operators/activation_op.h
浏览文件 @
dadace31
...
@@ -55,6 +55,8 @@ class ActivationGradKernel : public framework::OpKernel {
...
@@ -55,6 +55,8 @@ class ActivationGradKernel : public framework::OpKernel {
}
}
};
};
// sigmoid = 1 / (1 + exp(-x)
template
<
typename
T
>
struct
SigmoidFunctor
{
struct
SigmoidFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
...
@@ -69,6 +71,7 @@ struct SigmoidGradFunctor {
...
@@ -69,6 +71,7 @@ struct SigmoidGradFunctor {
}
}
};
};
// exp(x) = e^x
struct
ExpFunctor
{
struct
ExpFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
...
@@ -79,10 +82,11 @@ struct ExpFunctor {
...
@@ -79,10 +82,11 @@ struct ExpFunctor {
struct
ExpGradFunctor
{
struct
ExpGradFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
dY
,
typename
dX
>
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
dY
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
dY
dy
,
dX
dx
)
{
void
operator
()(
Device
d
,
X
x
,
Y
y
,
dY
dy
,
dX
dx
)
{
dx
.
device
(
d
)
=
y
;
dx
.
device
(
d
)
=
dy
*
y
;
}
}
};
};
// relu(x) = max(x, 0)
template
<
typename
T
>
template
<
typename
T
>
struct
ReluFunctor
{
struct
ReluFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
template
<
typename
Device
,
typename
X
,
typename
Y
>
...
@@ -99,6 +103,7 @@ struct ReluGradFunctor {
...
@@ -99,6 +103,7 @@ struct ReluGradFunctor {
}
}
};
};
// tanh = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
struct
TanhFunctor
{
struct
TanhFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
...
@@ -114,6 +119,7 @@ struct TanhGradFunctor {
...
@@ -114,6 +119,7 @@ struct TanhGradFunctor {
}
}
};
};
// sqrt(x) = x^(1/2)
struct
SqrtFunctor
{
struct
SqrtFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
...
@@ -130,5 +136,59 @@ struct SqrtGradFunctor {
...
@@ -130,5 +136,59 @@ struct SqrtGradFunctor {
}
}
};
};
// abs(x) = |x|
struct
AbsFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
y
.
device
(
d
)
=
x
.
abs
();
}
};
// reciprocal(x) = 1 / x
template
<
typename
T
>
struct
ReciprocalFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
y
.
device
(
d
)
=
1.
/
x
;
}
};
struct
ReciprocalGradFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
dY
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
dY
dy
,
dX
dx
)
{
dx
.
device
(
d
)
=
dy
*
(
-
1.0
)
*
y
*
y
;
}
};
// log(x) = natural logarithm of x
struct
LogFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
y
.
device
(
d
)
=
x
.
log
();
}
};
struct
LogGradFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
dY
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
dY
dy
,
dX
dx
)
{
dx
.
device
(
d
)
=
dy
*
(
1.
/
x
);
}
};
// square(x) = x^2
struct
SquareFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
>
void
operator
()(
Device
d
,
X
x
,
Y
y
)
{
y
.
device
(
d
)
=
x
.
square
();
}
}
struct
SquareGradFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
dY
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
dY
dy
,
dX
dx
)
{
dx
.
device
(
d
)
=
dy
*
2
*
x
;
}
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录