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-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_STOPPINGCRITERIONS_VALIDATEDSTOPPINGCRITERION_H
34 #define SHARK_TRAINERS_STOPPINGCRITERIONS_VALIDATEDSTOPPINGCRITERION_H
35 
37 #include <shark/Core/ResultSets.h>
38 
39 namespace shark{
40 
41 
42 /// \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.
43 ///
44 /// Currently only implemented for functions over RealVector
45 class ValidatedStoppingCriterion: public AbstractStoppingCriterion< SingleObjectiveResultSet<RealVector> >{
46 private:
47  typedef RealVector PointType;
49 public:
50  //typedef typename base_type::ResultSet ResultSet;
54 
55 
56  ValidatedStoppingCriterion(ObjectiveFunctionType* validation, StoppingCriterionType* child)
57  :mpe_validation(validation), mpe_child(child){
58  reset();
59  }
60  /// returns true if training should stop
61  bool stop(ResultSet const& set){
62  double validationError = mpe_validation->eval(set.point);
63  return mpe_child->stop(ValidationResultSet(set,validationError));
64  }
65  void reset(){
66  mpe_child->reset();
67  }
68 protected:
69  ObjectiveFunctionType* mpe_validation;
70  StoppingCriterionType* mpe_child;
71 };
72 }
73 
74 
75 #endif