AutomaticParameterTuner.h

00001 #ifndef __AUTOMATIC_PARAMETER_TUNER_
00002 #define __AUTOMATIC_PARAMETER_TUNER_
00003 
00004 #include "Data.h"
00005 #include "StreamOutput.h"
00006 #include "NumericalTools.h"
00007 #include "Framework.h"
00008 
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <limits.h>
00012 #include <float.h>
00013 #include <math.h>
00014 #include <fstream>
00015 #include <string>
00016 
00017 using namespace std;
00018 
00037 class AutomaticParameterTuner : public Framework
00038 {
00039 public:
00040     AutomaticParameterTuner();
00041     virtual ~AutomaticParameterTuner();
00042 
00043     void addEpochParameter ( int *param, string name );  // for epoch-wise training
00044     void addIntegerParameter ( int *param, string name, int min=INT_MIN, int max=INT_MAX );
00045     void addDoubleParameter ( double *param, string name, double min=-DBL_MAX, double max=DBL_MAX );
00046     void removeEpochParameter ( string name );
00047     void removeIntegerParameter ( string name );
00048     void removeDoubleParameter ( string name );
00049     virtual double calcRMSEonProbe() = 0;
00050     virtual double calcRMSEonBlend() = 0;
00051     virtual void saveBestPrediction() = 0;
00052 
00053     // ====================== stochastic tuner ======================
00054 
00055     void simpleStochasticParameterFinder ( double minProbeImpro=0.00002, int maxProbeEpochsWithoutImpro=100, double minBlendImpro=0.000001, int maxBlendEpochsWithoutImpro=200, double stdDev = 0.1 );
00056 
00057     void setOptimizeProbeRmse ( bool enable );
00058     void setOptimizeBlendRmse ( bool enable );
00059 
00060     void setDebug ( bool en );
00061 
00062     // ====================== structured tuner ======================
00063 
00064 
00065     // example for outside call
00066     //
00067     // AutomaticParameterTuner APT;
00068     // double param0 = 1.23;
00069     // APT.addDoubleParameter(&param0, "double");
00070     // APT.expSearchParams(100);
00071     // while(APT.expSearchChangeParams())
00072     // {
00073     //     double error = function(param0);
00074     //     expSearchCheckErr(error);
00075     // }
00076 
00077 public:
00078     void expSearcher ( int minEpochs=0, int maxEpochs=200, int paramEpochs=3, int accelerationEpochs=2, double expInit=0.8, bool enableProbe=true, bool enableBlend=true );
00079     void expSearchParams ( int minEpochs=0, int maxEpochs=100, int paramEpochs=3, int accelerationEpochs=10000, double expInit=0.8 );
00080     bool expSearchChangeParams();
00081     void expSearchCheckErr ( double error );
00082     void expSearchReinitStepSize();
00083     void expSearchSetEpochsToMinimizeBlend ( int epochs );
00084     double expSearchGetLowestError();
00085 
00086 protected:
00087 
00088     int m_expSearchMinEpochs;
00089     int m_expSearchMaxEpochs;
00090     int m_expSearchMaxEpochsBlend;
00091     int m_expSearchParamEpochs;
00092     int m_expSearchParamAccelerationEpochs;
00093     int m_expSearchEpoch;
00094     int m_epochParamPos;
00095     bool m_epochParamBreak;
00096     int m_expSearchDoubleParamPos;
00097     int m_expSearchIntParamPos;
00098     int m_expSearchVariationCnt;
00099     double m_expInit;
00100     double m_expSearchErrorBest;
00101     double m_expSearchAcceleration;
00102     int m_expSearchAccelerationEpoch;
00103     time_t m_expSearchTime;
00104 
00105     vector<int> m_epochParamBest;
00106     vector<double> m_expSearchExponent;
00107     vector<double> m_expSearchDoubleParamBest;
00108     vector<int> m_expSearchIntParamBest;
00109     vector<double> m_expSearchParamDirection;
00110 
00111 
00112     vector<int*> m_epochParam;
00113     vector<string> m_epochName;
00114     vector<double*> m_doubleParam;
00115     vector<string> m_doubleName;
00116     vector<int*> m_intParam;
00117     vector<string> m_intName;
00118 
00119     // set the range
00120     vector<double> m_doubleMin;
00121     vector<double> m_doubleMax;
00122     vector<int> m_intMin;
00123     vector<int> m_intMax;
00124 
00125     bool m_optimizeProbeRMSE;
00126     bool m_optimizeBlendRMSE;
00127 
00128     bool m_enableDebug;
00129 
00130 
00131     // ====================== nelder-mead tuner ======================
00132 public:
00133     void NelderMeadSearch ( int maxEpochs=200 );
00134 protected:
00135     double calcError ( const vector<double> &paramVector );
00136     void setCurrentParameter ( const vector<double> &paramVector );
00137     void calcCenter ( const vector<pair<double,vector<double> > > &simplexPoints, vector<double> &center );
00138     double getReflectionPoint ( const vector<double> &center, const vector<double> &worstPoint, vector<double> &reflectionPoint, double alpha );
00139     void plotParameters ( int epoch, const vector<pair<double,vector<double> > > &simplexPoints );
00140     void calcMinMax ( const vector<pair<double,vector<double> > > &simplexPoints, int paramNr, double &min, double &max );
00141 
00142 };
00143 
00144 #endif

Generated on Tue Jan 26 09:20:58 2010 for ELF by  doxygen 1.5.8