Shark machine learning library
About Shark
News!
Contribute
Credits and copyright
Downloads
Getting Started
Installation
Using the docs
Documentation
Tutorials
Quick references
Class list
Global functions
FAQ
Showroom
include
shark
ObjectiveFunctions
ErrorFunction.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief error function for supervised learning
5
*
6
*
7
*
8
* \author T.Voss, T. Glasmachers, O.Krause
9
* \date 2010-2011
10
*
11
*
12
* \par Copyright 1995-2015 Shark Development Team
13
*
14
* <BR><HR>
15
* This file is part of Shark.
16
* <http://image.diku.dk/shark/>
17
*
18
* Shark is free software: you can redistribute it and/or modify
19
* it under the terms of the GNU Lesser General Public License as published
20
* by the Free Software Foundation, either version 3 of the License, or
21
* (at your option) any later version.
22
*
23
* Shark is distributed in the hope that it will be useful,
24
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
* GNU Lesser General Public License for more details.
27
*
28
* You should have received a copy of the GNU Lesser General Public License
29
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
30
*
31
*/
32
#ifndef SHARK_OBJECTIVEFUNCTIONS_ERRORFUNCTION_H
33
#define SHARK_OBJECTIVEFUNCTIONS_ERRORFUNCTION_H
34
35
36
#include <
shark/Models/AbstractModel.h
>
37
#include <
shark/ObjectiveFunctions/Loss/AbstractLoss.h
>
38
#include <
shark/ObjectiveFunctions/AbstractObjectiveFunction.h
>
39
#include <
shark/Data/Dataset.h
>
40
#include "Impl/FunctionWrapperBase.h"
41
42
#include <boost/scoped_ptr.hpp>
43
44
namespace
shark
{
45
46
///
47
/// \brief Objective function for supervised learning
48
///
49
/// \par
50
/// An ErrorFunction object is an objective function for
51
/// learning the parameters of a model from data by means
52
/// of minimization of a cost function. The value of the
53
/// objective function is the cost of the model predictions
54
/// on the training data, given the targets.
55
///
56
/// \par
57
/// The class detects automatically when an AbstractLoss is used
58
/// as Costfunction. In this case, it uses faster algorithms
59
/// for empirical risk minimization
60
///
61
///\par
62
/// It also automatically infers the input und label type from the given dataset and the output type
63
/// of the model in the constructor and ensures that Model and loss match. Thus the user does
64
/// not need to provide the types as template parameters.
65
class
ErrorFunction
:
public
SingleObjectiveFunction
66
{
67
public
:
68
template
<
class
InputType,
class
LabelType,
class
OutputType>
69
ErrorFunction
(
70
LabeledData<InputType, LabelType>
const
& dataset,
71
AbstractModel<InputType,OutputType>
* model,
72
AbstractLoss<LabelType, OutputType>
* loss
73
74
);
75
ErrorFunction
(
const
ErrorFunction
& op);
76
ErrorFunction
&
operator=
(
const
ErrorFunction
& op);
77
78
std::string
name
()
const
79
{
return
"ErrorFunction"
; }
80
81
void
setRegularizer
(
double
factor,
SingleObjectiveFunction
* regularizer){
82
m_regularizer = regularizer;
83
m_regularizationStrength = factor;
84
}
85
86
SearchPointType
proposeStartingPoint
()
const
{
87
return
mp_wrapper ->
proposeStartingPoint
();
88
}
89
std::size_t
numberOfVariables
()
const
{
90
return
mp_wrapper ->
numberOfVariables
();
91
}
92
93
double
eval
(RealVector
const
& input)
const
;
94
ResultType
evalDerivative
(
const
SearchPointType
& input,
FirstOrderDerivative
& derivative )
const
;
95
96
friend
void
swap
(
ErrorFunction
& op1,
ErrorFunction
& op2);
97
98
private
:
99
boost::scoped_ptr<detail::FunctionWrapperBase > mp_wrapper;
100
SingleObjectiveFunction
* m_regularizer;
101
double
m_regularizationStrength;
102
};
103
104
}
105
#include "Impl/ErrorFunction.inl"
106
#endif