PLearn 0.1
|
00001 00002 // -*- C++ -*- 00003 00004 // HyperOptimize.h 00005 // 00006 // Copyright (C) 2003-2006 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 // Documentation: Nicolas Chapados 00038 00039 /* ******************************************************* 00040 * $Id: HyperOptimize.h 9133 2008-06-16 20:41:53Z plearner $ 00041 ******************************************************* */ 00042 00044 #ifndef HyperOptimize_INC 00045 #define HyperOptimize_INC 00046 00047 #include "HyperCommand.h" 00048 #include "OptionsOracle.h" 00049 #include <plearn/misc/PTimer.h> 00050 #include <plearn/vmat/Splitter.h> 00051 00052 namespace PLearn { 00053 using namespace std; 00106 class HyperOptimize: public HyperCommand 00107 { 00108 typedef HyperCommand inherited; 00109 00110 protected: 00112 VMat resultsmat; 00113 real best_objective; 00114 Vec best_results; 00115 PP<PLearner> best_learner; 00116 int trialnum; 00117 TVec<string> option_vals; 00118 PP<PTimer> auto_save_timer; 00119 00120 public: 00121 00122 PLEARN_DECLARE_OBJECT(HyperOptimize); 00123 00124 // ************************ 00125 // * public build options * 00126 // ************************ 00127 00128 int which_cost_pos; 00129 string which_cost; 00130 int min_n_trials; 00131 PP<OptionsOracle> oracle; 00132 bool provide_tester_expdir; // should tester be provided with an expdir for each test run 00133 TVec< PP<HyperCommand> > sub_strategy; 00134 bool rerun_after_sub; 00135 bool provide_sub_expdir; // should sub_strategy be provided an expdir 00136 bool save_best_learner; 00137 int auto_save; 00138 int auto_save_test; 00139 int auto_save_diff_time; 00140 PP<Splitter> splitter; // (if not specified, use default splitter specified in PTester) 00141 00142 // **************** 00143 // * Constructors * 00144 // **************** 00145 00146 // Default constructor, make sure the implementation in the .cc 00147 // initializes all fields to reasonable default values. 00148 HyperOptimize(); 00149 00150 00151 // ****************** 00152 // * HyperCommand methods * 00153 // ****************** 00154 00155 private: 00157 void build_(); 00158 00159 protected: 00161 static void declareOptions(OptionList& ol); 00162 00163 void getResultsMat(); 00164 void reportResult(int trialnum, const Vec& results); 00165 Vec runTest(int trialnum); 00166 00167 /* 00169 void launchTest(int trialnum, PP<RemotePLearnServer> server, 00170 map<PP<RemotePLearnServer>, int>& testers_ids); 00171 */ 00172 00173 public: 00174 00176 virtual void setExperimentDirectory(const PPath& the_expdir); 00177 00179 virtual TVec<string> getResultNames() const; 00180 00181 virtual void forget(); 00182 00183 virtual Vec optimize(); 00184 00185 // simply calls inherited::build() then build_() 00186 virtual void build(); 00187 00189 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00190 00191 }; 00192 00193 // Declares a few other classes and functions related to this class 00194 DECLARE_OBJECT_PTR(HyperOptimize); 00195 00196 } // end of namespace PLearn 00197 00198 #endif 00199 00200 00201 /* 00202 Local Variables: 00203 mode:c++ 00204 c-basic-offset:4 00205 c-file-style:"stroustrup" 00206 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00207 indent-tabs-mode:nil 00208 fill-column:79 00209 End: 00210 */ 00211 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :