PLearn 0.1
|
00001 00002 // -*- C++ -*- 00003 00004 // EarlyStoppingOracle.h 00005 // 00006 // Copyright (C) 2003-2004 ApSTAT Technologies Inc. 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 // Author: Pascal Vincent 00037 00038 /* ******************************************************* 00039 * $Id: EarlyStoppingOracle.h 5677 2006-05-25 23:43:50Z lamblin $ 00040 ******************************************************* */ 00041 00043 #ifndef EarlyStoppingOracle_INC 00044 #define EarlyStoppingOracle_INC 00045 00046 #include "OptionsOracle.h" 00047 00048 namespace PLearn { 00049 using namespace std; 00050 00051 class EarlyStoppingOracle: public OptionsOracle 00052 { 00053 protected: 00054 // ********************* 00055 // * protected options * 00056 // ********************* 00057 00061 TVec<string> option_values; 00062 00065 int nreturned; 00066 00067 // these are used by checkEarlyStoppingCondition 00068 real previous_objective; // objective value reached at previous step 00069 real best_objective; // the best objective value reached so far 00070 int best_step; // the "step" for which best result was obtained (i.e. the value of nreturned when we got the best) 00071 00072 bool met_early_stopping; // will be set to true as soon as we meet the early stopping conditions 00073 00074 public: 00075 00076 typedef OptionsOracle inherited; 00077 00078 // ************************ 00079 // * public build options * 00080 // ************************ 00081 00082 string option; 00083 TVec<string> values; 00084 Vec range; 00085 00087 real min_value; 00088 real max_value; 00089 real max_degradation; 00090 real relative_max_degradation; 00091 real min_improvement; 00092 real relative_min_improvement; 00093 int max_degraded_steps; 00094 int min_n_steps; 00095 00096 // **************** 00097 // * Constructors * 00098 // **************** 00099 00100 // Default constructor, make sure the implementation in the .cc 00101 // initializes all fields to reasonable default values. 00102 EarlyStoppingOracle(); 00103 00104 00105 // ****************** 00106 // * OptionsOracle methods * 00107 // ****************** 00108 00109 private: 00111 // (Please implement in .cc) 00112 void build_(); 00113 00114 protected: 00116 // (Please implement in .cc) 00117 static void declareOptions(OptionList& ol); 00118 00119 public: 00120 00122 virtual TVec<string> getOptionNames() const; 00123 00124 virtual TVec<string> generateNextTrial(const TVec<string>& older_trial, real obtained_objective); 00125 00126 virtual void forget(); 00127 00128 // simply calls inherited::build() then build_() 00129 virtual void build(); 00130 00132 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00133 00135 PLEARN_DECLARE_OBJECT(EarlyStoppingOracle); 00136 00137 }; 00138 00139 // Declares a few other classes and functions related to this class 00140 DECLARE_OBJECT_PTR(EarlyStoppingOracle); 00141 00142 } // end of namespace PLearn 00143 00144 #endif 00145 00146 00147 /* 00148 Local Variables: 00149 mode:c++ 00150 c-basic-offset:4 00151 c-file-style:"stroustrup" 00152 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00153 indent-tabs-mode:nil 00154 fill-column:79 00155 End: 00156 */ 00157 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :