SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
loss
HingeLoss.cpp
浏览该文件的文档.
1
/*
2
Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights
3
embodied in the content of this file are licensed under the BSD
4
(revised) open source license.
5
6
Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society.
7
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
12
13
Modifications (w) 2011 Shashwat Lal Das
14
Modifications (w) 2012 Fernando José Iglesias García
15
*/
16
17
#include <
shogun/loss/HingeLoss.h
>
18
#include <
shogun/mathematics/Math.h
>
19
20
using namespace
shogun;
21
22
float64_t
CHingeLoss::loss
(
float64_t
prediction,
float64_t
label)
23
{
24
float64_t
e = 1 - label * prediction;
25
26
return
(e > 0) ? e : 0;
27
}
28
29
float64_t
CHingeLoss::loss
(
float64_t
z)
30
{
31
return
CMath::max
(0.0, z);
32
}
33
34
float64_t
CHingeLoss::first_derivative
(
float64_t
prediction,
float64_t
label)
35
{
36
return
(label * prediction >= label * label) ? 0 : -label;
37
}
38
39
float64_t
CHingeLoss::first_derivative
(
float64_t
z)
40
{
41
return
z > 0.0 ? 1.0 : 0.0;
42
}
43
44
float64_t
CHingeLoss::second_derivative
(
float64_t
prediction,
float64_t
label)
45
{
46
return
0.;
47
}
48
49
float64_t
CHingeLoss::second_derivative
(
float64_t
z)
50
{
51
return
0;
52
}
53
54
float64_t
CHingeLoss::get_update
(
float64_t
prediction,
float64_t
label,
float64_t
eta_t,
float64_t
norm
)
55
{
56
if
(label * prediction >= label * label)
57
return
0;
58
float64_t
err = (label*label - label*prediction)/(label * label);
59
float64_t
normal = eta_t;
60
return
label * (normal < err ? normal : err)/norm;
61
}
62
63
float64_t
CHingeLoss::get_square_grad
(
float64_t
prediction,
float64_t
label)
64
{
65
return
first_derivative
(prediction, label);
66
}
SHOGUN
机器学习工具包 - 项目文档