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
Algorithms
StoppingCriteria
TrainingProgress.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief Stopping Criterion which stops, when the training error seems to converge
5
*
6
*
7
*
8
* \author O. Krause
9
* \date 2010
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
33
#ifndef SHARK_TRAINERS_STOPPINGCRITERA_TRAININGPROGRESS_H
34
#define SHARK_TRAINERS_STOPPINGCRITERA_TRAININGPROGRESS_H
35
36
#include "
AbstractStoppingCriterion.h
"
37
#include <
shark/Core/ResultSets.h
>
38
#include <queue>
39
#include <numeric>
40
41
namespace
shark
{
42
43
44
///\brief This stopping criterion tracks the improvement of the training error over an interval of iterations.
45
///
46
///If the mean performance over this strip divided by the minimum is too low, training is stopped. The difference to TrainingError
47
///is, that this class tests the relative improvement of the error compared to the minimum training error,
48
///while the TrainingError measures the absolute difference. This class is a bit better tuned to noisy error functions since it takes the
49
///mean of the interval as comparison.
50
///
51
/// Terminology for this and other stopping criteria is taken from (and also see):
52
///
53
/// Lutz Prechelt. Early Stopping - but when? In Genevieve B. Orr and
54
/// Klaus-Robert Müller: Neural Networks: Tricks of the Trade, volume
55
/// 1524 of LNCS, Springer, 1997.
56
///
57
template
<
class
Po
int
Type = RealVector>
58
class
TrainingProgress
:
public
AbstractStoppingCriterion
< SingleObjectiveResultSet<PointType> >{
59
public
:
60
typedef
SingleObjectiveResultSet<PointType>
ResultSet
;
61
///constructs the TrainingProgress
62
///@param intervalSize the size of the interval which is checked
63
///@param minImprovement minimum relative improvement of the interval to the minimum training error before training stops
64
TrainingProgress
(
size_t
intervalSize,
double
minImprovement){
65
m_minImprovement
= minImprovement;
66
m_intervalSize
= intervalSize;
67
reset
();
68
}
69
/// returns true if training should stop
70
bool
stop
(
const
ResultSet&
set
){
71
m_minTraining
=
std::min
(
m_minTraining
,
set
.
value
);
72
73
m_meanPerformance
+=
set
.value;
74
m_interval
.push(
set
.
value
);
75
if
(
m_interval
.size()>
m_intervalSize
){
76
m_meanPerformance
-=
m_interval
.front();
77
m_interval
.pop();
78
}
79
m_progress
= (
m_meanPerformance
/(
m_minTraining
*
m_interval
.size()))-1;
80
81
if
(
m_interval
.size()<
m_intervalSize
){
82
return
false
;
83
}
84
85
86
return
m_progress
<
m_minImprovement
;
87
}
88
///resets the internal state
89
void
reset
(){
90
m_interval
= std::queue<double>();
91
m_minTraining
= 1.e10;
92
m_meanPerformance
= 0;
93
m_progress
= 0.0;
94
}
95
///returns current value of progress
96
double
value
()
const
{
97
return
m_progress
;
98
}
99
protected
:
100
///minimum training error encountered
101
double
m_minTraining
;
102
///minimum improvement allowed before training stops
103
double
m_minImprovement
;
104
///mean performance over the last intervalSize timesteps
105
double
m_meanPerformance
;
106
///current progress measure. if it is below minTraining, stop() will return true
107
double
m_progress
;
108
109
///current interval
110
std::queue<double>
m_interval
;
111
///size of the interval
112
size_t
m_intervalSize
;
113
};
114
}
115
116
117
#endif