• Main Page
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • File Members

EarlyStopping.cpp

Go to the documentation of this file.
00001 
00055 #include <SharkDefs.h>
00056 #include <ReClaM/EarlyStopping.h>
00057 
00058 
00059 //===========================================================================
00081 EarlyStopping::EarlyStopping(unsigned sl = 5)
00082 {
00083     GLvalue     = 0;
00084     e_opt       = MAXDOUBLE;
00085     e_va_old    = MAXDOUBLE;
00086     time        = 0;
00087     UPvalue     = 0;
00088     striplength = sl;
00089     e_tr.resize(striplength, false);
00090 }
00091 
00092 //===========================================================================
00117 void EarlyStopping::update(double e, double e_va)
00118 {
00119     double e_tr_av,   // Average training set error.
00120     e_tr_min;  // Minimal training set error.
00121 
00122 
00123     // evaluate generalization loss: GL
00124     if (e_va < e_opt)
00125         e_opt = e_va;
00126     GLvalue = 100. * (e_va / e_opt - 1.);
00127 
00128     // evaluate trainings-progress: TP
00129     if (time == 0) e_tr = e; // initialize error memory vector with first
00130     // error value
00131     // this implies a TPvalue == 1 when time == 0
00132     // this does not affect the TP(), see below
00133     e_tr(time % striplength) = e;
00134     e_tr_av = e_tr_min = e_tr(0);
00135     for (unsigned j = 1; j < striplength; j++)
00136     {
00137         e_tr_av += e_tr(j);
00138         if (e_tr(j) < e_tr_min)
00139             e_tr_min = e_tr(j);
00140     }
00141     e_tr_av /= (double)striplength;
00142     TPvalue = 1000. * (e_tr_av / e_tr_min - 1.);
00143 
00144     // evaluate increase of generalization error: UP
00145     if (time % striplength == 0)
00146     {
00147         if (e_va_old < e_va)
00148             UPvalue++;
00149         else
00150             UPvalue = 0;
00151         e_va_old = e_va;
00152     }
00153 
00154     // update time
00155     time++;
00156 }
00157 
00158 
00159 //===========================================================================
00175 double EarlyStopping::getGL()
00176 {
00177     return GLvalue;
00178 }
00179 
00180 
00181 //===========================================================================
00202 double EarlyStopping::getTP()
00203 {
00204     if (time >= striplength)
00205         return TPvalue;
00206     else
00207         return MAXDOUBLE;
00208 }
00209 
00210 //===========================================================================
00231 double EarlyStopping::getPQ()
00232 {
00233     if (time >= striplength)
00234         return GLvalue / TPvalue;
00235     else
00236         return 0.;
00237 }
00238 
00239 
00240 //===========================================================================
00256 unsigned EarlyStopping::getUP()
00257 {
00258     return UPvalue;
00259 }
00260 
00261 
00262 //===========================================================================
00282 bool EarlyStopping::GL(double alpha = 1.0)
00283 {
00284     return (GLvalue > alpha);
00285 }
00286 
00287 
00288 //===========================================================================
00313 bool EarlyStopping::TP(double alpha = 0.1)
00314 {
00315     if (time >= striplength)
00316         return (TPvalue < alpha);
00317     else
00318         return false;
00319 }
00320 
00321 //===========================================================================
00346 bool EarlyStopping::PQ(double alpha = 0.5)
00347 {
00348     if (time >= striplength)
00349         return (GLvalue / TPvalue > alpha);
00350     else
00351         return false;
00352 }
00353 
00354 
00355 //===========================================================================
00375 bool EarlyStopping::UP(unsigned s = 3)
00376 {
00377     return (UPvalue >= s);
00378 }
00379 
00380 
00381 //===========================================================================
00424 bool EarlyStopping::one_of_all(double alpha1 = 1.0, double alpha2 = 1.0, double alpha3 = 1.0, unsigned s = 3)
00425 {
00426     return (GL(alpha1) || TP(alpha2) || PQ(alpha3) || UP(s));
00427 }
00428 
00429 
00430 
00431 
  • Shark Main Page
  • Array
  • Rng
  • LinAlg
  • FileUtil
  • EALib
  • MOO-EALib
  • ReClaM
  • Fuzzy
  • Mixture
  • Tutorials
  • FAQ