MaxIterations.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Stopping Criterion which stops after a fixed number of iterations
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  * <http://shark-ml.org/>
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_STOPPINGCRITERIA_MAXITERATIONS_H
34 #define SHARK_TRAINERS_STOPPINGCRITERIA_MAXITERATIONS_H
35 
37 #include <shark/Core/ResultSets.h>
38 #include <shark/LinAlg/Base.h>
39 namespace shark{
40 
41 /// This stopping criterion stops after a fixed number of iterations
42 template<class ResultSet = SingleObjectiveResultSet<RealVector> >
43 class MaxIterations: public AbstractStoppingCriterion< ResultSet >{
44 public:
45  ///constructs the MaxIterations stopping criterion
46  ///@param maxIterations maximum iterations before training should stop
47  MaxIterations(unsigned int maxIterations){
48  m_maxIterations = maxIterations;
49  m_iteration = 0;
50  }
51 
52  void setMaxIterations(unsigned int newIterations){
53  m_maxIterations = newIterations;
54  }
55  /// returns true if training should stop
56  bool stop(const ResultSet& set){
57  ++m_iteration;
59  }
60  ///reset iteration counter
61  void reset(){
62  m_iteration = 0;
63  }
64 protected:
65  ///current number of iterations
66  unsigned int m_iteration;
67  ///maximum number of iteration allowed
68  unsigned int m_maxIterations;
69 };
70 }
71 
72 
73 #endif