SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
loss
SquaredLoss.cpp
Go to the documentation of this file.
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/mathematics/Math.h
>
18
#include <
shogun/loss/SquaredLoss.h
>
19
20
using namespace
shogun;
21
22
float64_t
CSquaredLoss::loss
(
float64_t
prediction,
float64_t
label)
23
{
24
return
(prediction - label) * (prediction - label);
25
}
26
27
float64_t
CSquaredLoss::loss
(
float64_t
z)
28
{
29
return
z*z;
30
}
31
32
float64_t
CSquaredLoss::first_derivative
(
float64_t
prediction,
float64_t
label)
33
{
34
return
2. * (prediction - label);
35
}
36
37
float64_t
CSquaredLoss::first_derivative
(
float64_t
z)
38
{
39
return
2. * z;
40
}
41
42
float64_t
CSquaredLoss::second_derivative
(
float64_t
prediction,
float64_t
label)
43
{
44
return
2;
45
}
46
47
float64_t
CSquaredLoss::second_derivative
(
float64_t
z)
48
{
49
return
2;
50
}
51
52
float64_t
CSquaredLoss::get_update
(
float64_t
prediction,
float64_t
label,
float64_t
eta_t,
float64_t
norm
)
53
{
54
if
(eta_t < 1e-6)
55
{
56
/* When exp(-eta_t)~= 1 we replace 1-exp(-eta_t)
57
* with its first order Taylor expansion around 0
58
* to avoid catastrophic cancellation.
59
*/
60
return
(label - prediction)*eta_t/
norm
;
61
}
62
return
(label - prediction)*(1-exp(-eta_t))/norm;
63
}
64
65
float64_t
CSquaredLoss::get_square_grad
(
float64_t
prediction,
float64_t
label)
66
{
67
return
(prediction - label) * (prediction - label);
68
}
SHOGUN
Machine Learning Toolbox - Documentation