Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

HyperOptimizer.h

Go to the documentation of this file.
00001 // -*- C++ -*-4 2002/09/08 21:59:21 morinf 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 2002 Pascal Vincent, Frederic Morin 00005 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // 00009 // 1. Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // 00012 // 2. Redistributions in binary form must reproduce the above copyright 00013 // notice, this list of conditions and the following disclaimer in the 00014 // documentation and/or other materials provided with the distribution. 00015 // 00016 // 3. The name of the authors may not be used to endorse or promote 00017 // products derived from this software without specific prior written 00018 // permission. 00019 // 00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 // 00031 // This file is part of the PLearn library. For more information on the PLearn 00032 // library, go to the PLearn Web site at www.plearn.org 00033 00034 00035 00036 /* ******************************************************* 00037 * $Id: HyperOptimizer.h,v 1.7 2004/07/21 16:30:54 chrish42 Exp $ 00038 * This file is part of the PLearn library. 00039 ******************************************************* */ 00040 00041 00044 #ifndef HyperOptimizer_INC 00045 #define HyperOptimizer_INC 00046 00047 #include <plearn_learners/generic/Learner.h> 00048 #include <plearn_learners/testers/TestMethod.h> 00049 00050 namespace PLearn { 00051 using namespace std; 00052 00053 // ###### HyperOptimizer ###################################################### 00054 // 00055 // This is the generic definition of an HyperOptimizer. 00056 // NOTE: This is _BETA_ stuff, things may change... 00057 00058 class HyperOptimizer; 00059 typedef Array<PP<HyperOptimizer> > HStrategy; 00060 typedef map<string, string> HAliases; 00061 00062 class HyperOptimizer: public Object 00063 { 00064 typedef Object inherited; 00065 public: 00066 HyperOptimizer() 00067 {}; 00068 00071 virtual void optimize(PP<Learner> learner, const VMat &dataset, const HAliases &aliases) = 0; 00072 00073 PP<TestMethod> objective; 00074 HStrategy substrategy; 00075 00076 PLEARN_DECLARE_ABSTRACT_OBJECT(HyperOptimizer); 00077 static void declareOptions(OptionList &ol); 00078 00079 protected: 00080 private: 00081 }; // class HyperOptimizer 00082 00083 DECLARE_OBJECT_PTR(HyperOptimizer); 00084 00085 00086 // ###### HSetVal ############################################################# 00087 // 00088 // This is a dummy HyperOptimizer in the sense that it doesn't optimize 00089 // anything but sets a given hyperparameter's value explicitly. 00090 00091 class HSetVal: public HyperOptimizer 00092 { 00093 typedef HyperOptimizer inherited; 00094 public: 00095 HSetVal() 00096 {}; 00097 00098 virtual void optimize(PP<Learner> learner, const VMat &dataset, const HAliases &aliases); 00099 00100 PLEARN_DECLARE_OBJECT(HSetVal); 00101 static void declareOptions(OptionList &ol); 00102 protected: 00103 string param; 00104 string value; 00105 }; // class HSetVal 00106 00107 DECLARE_OBJECT_PTR(HSetVal); 00108 00109 00110 // ###### HTryAll ############################################################# 00111 // 00112 // Optimization consists of trying all values given in a list and choosing the 00113 // best performing one. 00114 00115 class HTryAll: public HyperOptimizer 00116 { 00117 typedef HyperOptimizer inherited; 00118 public: 00119 HTryAll() 00120 {}; 00121 00122 virtual void optimize(PP<Learner> learner, const VMat &dataset, const HAliases &aliases); 00123 00124 PLEARN_DECLARE_OBJECT(HTryAll); 00125 static void declareOptions(OptionList &ol); 00126 00127 string param; 00128 Array<string> values; 00129 }; // class HTryAll 00130 00131 DECLARE_OBJECT_PTR(HTryAll); 00132 00133 00134 // ###### HCoordinateDescent ################################################## 00135 // 00136 // Perform a coordinate descent into a list of HyperOptimizers 00137 00138 class HCoordinateDescent: public HyperOptimizer 00139 { 00140 typedef HyperOptimizer inherited; 00141 public: 00142 HCoordinateDescent() 00143 : max_iterations(10) 00144 {}; 00145 00146 virtual void optimize(PP<Learner> learner, const VMat &dataset, const HAliases &aliases); 00147 00148 PLEARN_DECLARE_OBJECT(HCoordinateDescent); 00149 static void declareOptions(OptionList &ol); 00150 protected: 00151 int max_iterations; 00152 HStrategy substragegy; 00153 00154 }; // class HCoordinateDescent 00155 00156 DECLARE_OBJECT_PTR(HCoordinateDescent); 00157 00158 // ###### HTryCombinations ################################################## 00159 // 00160 // Try a list of combinations of values of multiple hyperparameters. 00161 00162 class HTryCombinations: public HyperOptimizer 00163 { 00164 typedef HyperOptimizer inherited; 00165 public: 00166 HTryCombinations() 00167 {}; 00168 00169 virtual void optimize(PP<Learner> learner, const VMat &dataset, const HAliases &aliases); 00170 00171 PLEARN_DECLARE_OBJECT(HTryCombinations); 00172 static void declareOptions(OptionList &ol); 00173 00174 virtual void build(); // We put these here to perform error checking on the specifications 00175 void _build(); 00176 00177 protected: 00178 real recursive_optimize(PP<Learner> learner, const VMat &dataset, const Array<string> &aliases, int i); 00179 00180 Array<Array<string> > values; 00181 Array<string> params; 00182 00183 }; // class HTryCombinations 00184 00185 DECLARE_OBJECT_PTR(HTryCombinations); 00186 00187 00188 }; // end of namespace PLearn 00189 00190 #endif // HyperOptimizer_INC

Generated on Tue Aug 17 15:55:15 2004 for PLearn by doxygen 1.3.7