ValidatedStoppingCriterion.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Stopping Criterion which evaluates the validation error and hands the result over to another stopping criterion.
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_STOPPINGCRITERIONS_VALIDATEDSTOPPINGCRITERION_H
34 #define SHARK_TRAINERS_STOPPINGCRITERIONS_VALIDATEDSTOPPINGCRITERION_H
35 
37 #include <shark/Core/ResultSets.h>
38 #include <shark/LinAlg/Base.h>
40 
41 namespace shark{
42 
43 
44 /// \brief Given the current Result set of the optimizer, calculates the validation error using a validation function and hands the results over to the underlying stopping criterion.
45 ///
46 /// Currently only implemented for functions over RealVector
47 class ValidatedStoppingCriterion: public AbstractStoppingCriterion< SingleObjectiveResultSet<RealVector> >{
48 private:
49  typedef RealVector PointType;
51 public:
52  //typedef typename base_type::ResultSet ResultSet;
56 
57 
58  ValidatedStoppingCriterion(ObjectiveFunctionType* validation, StoppingCriterionType* child)
59  :mpe_validation(validation), mpe_child(child){
60  reset();
61  }
62  /// returns true if training should stop
63  bool stop(ResultSet const& set){
64  double validationError = mpe_validation->eval(set.point);
65  return mpe_child->stop(ValidationResultSet(set,validationError));
66  }
67  void reset(){
68  mpe_child->reset();
69  }
70 protected:
71  ObjectiveFunctionType* mpe_validation;
72  StoppingCriterionType* mpe_child;
73 };
74 }
75 
76 
77 #endif