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
d49fb9b1
Commit
d49fb9b1
authored
Jul 12, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
declare XNet class
parent
f8a37184
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
94 行增加
和
3 行删除
+94
-3
source/network/Main.cpp
+4
-0
source/network/XNet.cpp
+64
-0
source/network/XNet.h
+17
-2
source/tensor/Main.cpp
+1
-1
source/tensor/XLink.cpp
+5
-0
source/tensor/XLink.h
+3
-0
没有找到文件。
source/network/Main.cpp
查看文件 @
d49fb9b1
...
...
@@ -40,6 +40,10 @@ int main( int argc, const char ** argv )
fprintf
(
stderr
,
"Run this program with
\"
-test
\"
for unit test!
\n
"
);
}
XNet
net
;
XTensor
a
;
net
.
Backward
(
a
);
//_CrtDumpMemoryLeaks();
return
0
;
...
...
source/network/XNet.cpp
查看文件 @
d49fb9b1
...
...
@@ -23,4 +23,67 @@
namespace
nts
{
/* constructor */
XNet
::
XNet
()
{
nodes
.
Clear
();
}
/* de-constructor */
XNet
::~
XNet
()
{
}
/*
backward propagation to obtain gradient wrt. the loss/error function
>> root - root node (output) of the network
>> gold - gold standard for the output
>> loss - name of loss function
*/
void
XNet
::
Backward
(
XTensor
&
root
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
)
{
XList
roots
(
1
);
roots
.
Add
(
&
root
);
XList
golds
(
1
);
golds
.
Add
(
&
gold
);
Backward
(
roots
,
golds
,
loss
);
}
/*
backward propagation to obtain gradient wrt. the loss/error function
with a number of root nodes
>> root - a list of root nodes (output) of the network
>> gold - a list of gold standard for the output
>> loss - name of loss function
*/
void
XNet
::
Backward
(
XList
&
roots
,
XList
&
golds
,
LOSS_FUNCTION_NAME
loss
)
{
Traverse
(
roots
);
}
/*
traverse the net and find the topological order by
depth-first search (Tarjan's algorithm)
>> root - root node (or output of the net)
*/
void
XNet
::
Traverse
(
XTensor
&
root
)
{
XList
roots
(
1
);
roots
.
Add
(
&
root
);
Traverse
(
roots
);
}
/*
traverse the net and find the topological order by
depth-first search (Tarjan's algorithm)
>> roots - a list of roots (or output nodes)
*/
void
XNet
::
Traverse
(
XList
&
roots
)
{
nodes
.
Clear
();
}
}
\ No newline at end of file
source/network/XNet.h
查看文件 @
d49fb9b1
...
...
@@ -30,9 +30,16 @@
namespace
nts
{
/* management of tensor net (or graph) */
class
XNet
struct
XNet
{
public
:
/* tensor nodes of the net (in order) */
XList
nodes
;
/* constructor */
XNet
();
/* de-constructor */
~
XNet
();
/* backward propagation to obtain gradient wrt. the loss/error function */
void
Backward
(
XTensor
&
root
,
XTensor
&
gold
=
NULLTensor
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
...
...
@@ -40,6 +47,14 @@ public:
/* backward propagation to obtain gradient wrt. the loss/error function
with a number of root nodes */
void
Backward
(
XList
&
roots
,
XList
&
golds
=
NULLList
,
LOSS_FUNCTION_NAME
loss
=
NOLOSS
);
/* traverse the net and find the topological order by
depth-first search (Tarjan's algorithm) */
void
Traverse
(
XTensor
&
root
);
/* traverse the net and find the topological order by
depth-first search (Tarjan's algorithm) */
void
Traverse
(
XList
&
roots
);
};
}
...
...
source/tensor/Main.cpp
查看文件 @
d49fb9b1
...
...
@@ -45,7 +45,7 @@ int main( int argc, const char ** argv )
//_CrtSetBreakAlloc(123);
/* a tiny test */
if
(
fals
e
)
if
(
tru
e
)
SmallTest
();
//_CrtDumpMemoryLeaks();
...
...
source/tensor/XLink.cpp
查看文件 @
d49fb9b1
...
...
@@ -37,6 +37,7 @@ XLink::XLink()
paramNum
=
0
;
type
[
0
]
=
0
;
typeID
=
0
;
caculator
=
NULL
;
}
/* deconstructor */
...
...
@@ -59,6 +60,8 @@ void XLink::Reset()
tailNum
=
0
;
paramNum
=
0
;
type
[
0
]
=
0
;
typeID
=
0
;
caculator
=
NULL
;
}
/* clear it */
...
...
@@ -68,6 +71,8 @@ void XLink::Clear()
tailNum
=
0
;
paramNum
=
0
;
type
[
0
]
=
0
;
typeID
=
0
;
caculator
=
NULL
;
}
/* reset tails */
...
...
source/tensor/XLink.h
查看文件 @
d49fb9b1
...
...
@@ -77,6 +77,9 @@ struct XLink
/* type id */
int
typeID
;
/* caculator (pointer to the class for computation) */
void
*
caculator
;
/* constuctor */
XLink
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论