Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
bb751b7f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
bb751b7f
编写于
2月 20, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add documentation for codes.
* also remove unused getValueStr
上级
9d45aa4f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
67 addition
and
23 deletion
+67
-23
paddle/gserver/evaluators/Evaluator.h
paddle/gserver/evaluators/Evaluator.h
+55
-16
paddle/gserver/gradientmachines/NeuralNetwork.cpp
paddle/gserver/gradientmachines/NeuralNetwork.cpp
+11
-6
paddle/gserver/tests/test_Evaluator.cpp
paddle/gserver/tests/test_Evaluator.cpp
+1
-1
未找到文件。
paddle/gserver/evaluators/Evaluator.h
浏览文件 @
bb751b7f
...
...
@@ -118,33 +118,55 @@ public:
static
ClassRegistrar
<
Evaluator
>
registrar_
;
/**
* @brief getNames will return all field names of current evaluator.
*
* The format of name is `evaluator_name.evaluator_fields`. If the evaluator
* has multiple field, the name could be `evaluator_name.field1`. For example
* the PrecisionRecallEvaluator contains `precision`, `recall` fields. The get
* names will return `precision_recall_evaluator.precision`,
* `precision_recall.recal`, etc.
*
* Also, if current Evaluator is a combined evaluator. getNames will return
* all names of all evaluators inside the combined evaluator.
*
* @param names [out]: the field names of current evaluator.
* @note Never clear the names parameter inside getNames.
*/
virtual
void
getNames
(
std
::
vector
<
std
::
string
>*
names
)
{
names
->
push_back
(
config_
.
name
());
}
/**
* @brief getValue will return the current evaluate value of one field.
*
* @param name: The field name of current evaluator.
* @param err [out]: The error state. nullptr means don't care.
*
* @return The evaluate value(metric).
*/
virtual
real
getValue
(
const
std
::
string
&
name
,
paddle
::
Error
*
err
=
nullptr
)
const
{
if
(
name
!=
config_
.
name
()
&&
err
!=
nullptr
)
{
if
(
name
!=
config_
.
name
())
{
if
(
err
!=
nullptr
)
{
*
err
=
paddle
::
Error
(
"no such name of evaluator %s"
,
name
.
c_str
());
}
return
.0
f
;
}
return
this
->
getValueImpl
();
}
virtual
std
::
string
getValueStr
(
const
std
::
string
&
name
,
paddle
::
Error
*
err
=
nullptr
)
const
{
paddle
::
Error
localErr
;
if
(
err
==
nullptr
)
{
err
=
&
localErr
;
}
real
result
=
this
->
getValue
(
name
,
err
);
if
(
!
err
->
isOK
())
{
return
""
;
}
else
{
return
std
::
to_string
(
result
);
}
}
/**
* @brief getType will return the evaluator type by field name.
*
* Evaluate Type is the current type of evaluator in string. Such as 'auc',
* 'precision_recall'. In combined evaluator, different name may get different
* evaluate type because it could be evaluated by different evaluator inside.
*
* @param name: The field name of current Evaluator.
* @param err: The error state. nullptr means don't care.
* @return the evaluator type string.
*/
virtual
std
::
string
getType
(
const
std
::
string
&
name
,
paddle
::
Error
*
err
=
nullptr
)
const
{
if
(
name
!=
config_
.
name
()
&&
err
!=
nullptr
)
{
...
...
@@ -155,10 +177,22 @@ public:
}
protected:
/**
* @brief getValueImpl The simplest way to define getValue result. If this
* evaluator doesn't contain multiple fields, and do not throw any error, just
* implemented this method to get the evaluate result(metric).
* @return Evaluate result(metric).
*/
virtual
real
getValueImpl
()
const
{
return
numSamples_
!=
.0
?
totalScore_
/
numSamples_
:
.0
;
}
/**
* @brief getTypeImpl The simplest way to define getType result. If this
* evaluator doesn't combine many evaluators, the get type should only return
* itself type.
* @return Evaluator type.
*/
virtual
std
::
string
getTypeImpl
()
const
{
return
"base"
;
}
protected:
...
...
@@ -167,6 +201,11 @@ protected:
double
totalScore_
;
};
/**
* @brief The NotGetableEvaluator class is the base class of evaluator that
* cannot get value in runtime. The most NotGetableEvaluator is Printer
* Evaluator, which is only used to debug network configuration.
*/
class
NotGetableEvaluator
:
public
Evaluator
{
// Evaluator interface
public:
...
...
paddle/gserver/gradientmachines/NeuralNetwork.cpp
浏览文件 @
bb751b7f
...
...
@@ -348,24 +348,29 @@ protected:
// Evaluator interface
public:
/**
* @brief getNames will return all inside evaluators' names.
* @param names [out]: return names.
*/
void
getNames
(
std
::
vector
<
std
::
string
>*
names
)
{
for
(
auto
&
eval
:
evaluators_
)
{
eval
->
getNames
(
names
);
}
}
/**
* @brief getValue could get all inside evaluators' value.
*/
real
getValue
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
return
this
->
getMethodHelper
<
real
>
(
name
,
err
,
[
&
name
,
err
](
const
std
::
unique_ptr
<
Evaluator
>&
eval
)
{
return
eval
->
getValue
(
name
,
err
);
});
}
std
::
string
getValueStr
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
return
this
->
getMethodHelper
<
std
::
string
>
(
name
,
err
,
[
&
name
,
err
](
const
std
::
unique_ptr
<
Evaluator
>&
eval
)
{
return
eval
->
getValueStr
(
name
,
err
);
});
}
/**
* @brief getType could get all inside evaluators' type.
*/
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
return
this
->
getMethodHelper
<
std
::
string
>
(
name
,
err
,
[
&
name
,
err
](
const
std
::
unique_ptr
<
Evaluator
>&
eval
)
{
...
...
paddle/gserver/tests/test_Evaluator.cpp
浏览文件 @
bb751b7f
...
...
@@ -114,7 +114,7 @@ void testEvaluator(TestConfig testConf,
testEvaluator
->
getNames
(
&
names
);
paddle
::
Error
err
;
for
(
auto
&
name
:
names
)
{
auto
value
=
testEvaluator
->
getValue
Str
(
name
,
&
err
);
auto
value
=
testEvaluator
->
getValue
(
name
,
&
err
);
ASSERT_TRUE
(
err
.
isOK
());
LOG
(
INFO
)
<<
name
<<
" "
<<
value
;
auto
tp
=
testEvaluator
->
getType
(
name
,
&
err
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录