Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
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-2017 Shark Development Team
13
*
14
* <BR><HR>
15
* This file is part of Shark.
16
* <https://shark-ml.github.io/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
#include <
shark/LinAlg/Base.h
>
41
42
namespace
shark
{
43
44
45
///\brief This stopping criterion tracks the improvement of the training error over an interval of iterations.
46
///
47
///If the mean performance over this strip divided by the minimum is too low, training is stopped. The difference to TrainingError
48
///is, that this class tests the relative improvement of the error compared to the minimum training error,
49
///while the TrainingError measures the absolute difference. This class is a bit better tuned to noisy error functions since it takes the
50
///mean of the interval as comparison.
51
///
52
/// Terminology for this and other stopping criteria is taken from (and also see):
53
///
54
/// Lutz Prechelt. Early Stopping - but when? In Genevieve B. Orr and
55
/// Klaus-Robert Müller: Neural Networks: Tricks of the Trade, volume
56
/// 1524 of LNCS, Springer, 1997.
57
///
58
template
<
class
Po
int
Type = RealVector>
59
class
TrainingProgress
:
public
AbstractStoppingCriterion
< SingleObjectiveResultSet<PointType> >{
60
public
:
61
typedef
SingleObjectiveResultSet<PointType>
ResultSet
;
62
///constructs the TrainingProgress
63
///@param intervalSize the size of the interval which is checked
64
///@param minImprovement minimum relative improvement of the interval to the minimum training error before training stops
65
TrainingProgress
(
size_t
intervalSize,
double
minImprovement){
66
m_minImprovement
= minImprovement;
67
m_intervalSize
= intervalSize;
68
reset
();
69
}
70
/// returns true if training should stop
71
bool
stop
(
const
ResultSet
& set){
72
m_minTraining
= std::min(
m_minTraining
, set.
value
);
73
74
m_meanPerformance
+= set.
value
;
75
m_interval
.push(set.
value
);
76
if
(
m_interval
.size()>
m_intervalSize
){
77
m_meanPerformance
-=
m_interval
.front();
78
m_interval
.pop();
79
}
80
m_progress
= (
m_meanPerformance
/(
m_minTraining
*
m_interval
.size()))-1;
81
82
if
(
m_interval
.size()<
m_intervalSize
){
83
return
false
;
84
}
85
86
87
return
m_progress
<
m_minImprovement
;
88
}
89
///resets the internal state
90
void
reset
(){
91
m_interval
= std::queue<double>();
92
m_minTraining
= 1.e10;
93
m_meanPerformance
= 0;
94
m_progress
= 0.0;
95
}
96
///returns current value of progress
97
double
value
()
const
{
98
return
m_progress
;
99
}
100
protected
:
101
///minimum training error encountered
102
double
m_minTraining
;
103
///minimum improvement allowed before training stops
104
double
m_minImprovement
;
105
///mean performance over the last intervalSize timesteps
106
double
m_meanPerformance
;
107
///current progress measure. if it is below minTraining, stop() will return true
108
double
m_progress
;
109
110
///current interval
111
std::queue<double>
m_interval
;
112
///size of the interval
113
size_t
m_intervalSize
;
114
};
115
}
116
117
118
#endif