Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
11a57e99
Commit
11a57e99
authored
Jul 18, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backward propagation for MatrixMul
parent
e18e6358
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
65 行增加
和
12 行删除
+65
-12
source/network/Main.cpp
+3
-3
source/network/XBackwardMath.cpp
+43
-7
source/tensor/XLink.cpp
+16
-2
source/tensor/XLink.h
+3
-0
没有找到文件。
source/network/Main.cpp
查看文件 @
11a57e99
...
...
@@ -55,9 +55,9 @@ int main( int argc, const char ** argv )
b
.
SetZeroAll
();
c
.
SetZeroAll
();
SetDataFixed
(
a
,
1.0
F
);
a
.
Set2D
(
3.0
F
,
1
,
0
);
a
.
Set2D
(
4.0
F
,
1
,
1
);
SetDataFixed
(
a
,
0.1
F
);
a
.
Set2D
(
0.3
F
,
1
,
0
);
a
.
Set2D
(
0.4
F
,
1
,
1
);
b
=
a
+
a
;
c
=
HTanH
(
MMul
(
a
,
b
));
...
...
source/network/XBackwardMath.cpp
查看文件 @
11a57e99
...
...
@@ -116,10 +116,13 @@ void XMathGrad::GradMatrixMul(XTensor * node)
{
XLink
&
income
=
node
->
income
;
CheckNTErrors
(
income
.
tailNum
==
2
,
"Wrong input tensor number for MULTIPLY!"
);
CheckNTErrors
(
income
.
paramNum
==
3
,
"Wrong parameter number for MULTIPLY!"
);
XTensor
*
a
=
income
.
tails
[
0
];
XTensor
*
b
=
income
.
tails
[
1
];
DTYPE
alpha
=
income
.
GetParam
(
0
);
MATRIX_TRANS_TYPE
transA
=
income
.
GetParamTrans
(
0
);
MATRIX_TRANS_TYPE
transB
=
income
.
GetParamTrans
(
1
);
DTYPE
alpha
=
income
.
GetParam
(
2
);
XNoder
::
MakeGrad
(
a
);
XNoder
::
MakeGrad
(
b
);
...
...
@@ -127,12 +130,46 @@ void XMathGrad::GradMatrixMul(XTensor * node)
XTensor
*
dedc
=
node
->
grad
;
XTensor
*
deda
=
a
->
grad
;
XTensor
*
dedb
=
b
->
grad
;
/* c = a * b * \alpha */
if
(
transA
==
X_NOTRANS
&&
transB
==
X_NOTRANS
){
/* dE/da = dE/dc * b^T * \alpha */
_MatrixMul
(
dedc
,
X_NOTRANS
,
b
,
X_TRANS
,
deda
,
alpha
);
/* dE/da = dE/dc * b^T * \alpha */
_MatrixMul
(
dedc
,
X_NOTRANS
,
b
,
X_TRANS
,
deda
,
alpha
);
/* dE/db = a^T * dE/dc * \alpha */
_MatrixMul
(
a
,
X_TRANS
,
dedc
,
X_NOTRANS
,
dedb
,
alpha
);
/* dE/db = a^T * dE/dc * \alpha */
_MatrixMul
(
a
,
X_TRANS
,
dedc
,
X_NOTRANS
,
dedb
,
alpha
);
}
/* c = a^T * b * \alpha */
else
if
(
transA
==
X_TRANS
&&
transB
==
X_NOTRANS
){
/* dE/da = dE/dc * b^T * \alpha */
_MatrixMul
(
dedc
,
X_NOTRANS
,
b
,
X_TRANS
,
deda
,
alpha
);
/* dE/db = a * dE/dc * \alpha */
_MatrixMul
(
a
,
X_NOTRANS
,
dedc
,
X_NOTRANS
,
dedb
,
alpha
);
}
/* c = a * b^T * \alpha */
else
if
(
transA
==
X_NOTRANS
&&
transB
==
X_TRANS
){
/* dE/da = dE/dc * b * \alpha */
_MatrixMul
(
dedc
,
X_NOTRANS
,
b
,
X_NOTRANS
,
deda
,
alpha
);
/* dE/db = a^T * dE/dc * \alpha */
_MatrixMul
(
a
,
X_TRANS
,
dedc
,
X_NOTRANS
,
dedb
,
alpha
);
}
/* c = a^T * b^T * \alpha */
else
if
(
transA
==
X_TRANS
&&
transB
==
X_TRANS
){
/* dE/da = dE/dc * b * \alpha */
_MatrixMul
(
dedc
,
X_NOTRANS
,
b
,
X_NOTRANS
,
deda
,
alpha
);
/* dE/db = a * dE/dc * \alpha */
_MatrixMul
(
a
,
X_NOTRANS
,
dedc
,
X_NOTRANS
,
dedb
,
alpha
);
}
}
}
\ No newline at end of file
}
source/tensor/XLink.cpp
查看文件 @
11a57e99
...
...
@@ -240,7 +240,8 @@ void XLink::AddParam(void * param, int size)
/*
get a paramter in default type
>> i - id the of the parameter
>> i - id of the parameter
<< return - the parameter in default type
*/
DTYPE
XLink
::
GetParam
(
int
i
)
{
...
...
@@ -251,7 +252,8 @@ DTYPE XLink::GetParam(int i)
/*
get a paramter in integer
>> i - id the of the parameter
>> i - id of the parameter
<< return - the parameter in integer
*/
int
XLink
::
GetParamInt
(
int
i
)
{
...
...
@@ -259,6 +261,18 @@ int XLink::GetParamInt(int i)
char
*
p
=
(
char
*
)
params
+
i
*
paramSize
;
return
*
(
int
*
)
p
;
}
/*
get a parameter in MATRIX_TRANS_TYPE
>> i - id of the parameter
<< return - the parameter in MATRIX_TRANS_TYPE
*/
MATRIX_TRANS_TYPE
XLink
::
GetParamTrans
(
int
i
)
{
CheckNTErrors
(
params
!=
NULL
,
"parameter array cannot be empty!"
);
char
*
p
=
(
char
*
)
params
+
i
*
paramSize
;
return
*
(
MATRIX_TRANS_TYPE
*
)
p
;
}
/*
create a hyperedge with two input tensors and a output tensor
...
...
source/tensor/XLink.h
查看文件 @
11a57e99
...
...
@@ -127,6 +127,9 @@ struct XLink
/* get a paramter in integer */
int
GetParamInt
(
int
i
);
/* get a parameter in MATRIX_TRANS_TYPE */
MATRIX_TRANS_TYPE
GetParamTrans
(
int
i
);
/* create a hyper edge with two input tensors and a output tensor */
static
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论