00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cmath>
00025
00026 #include "WeakLearners/BaseLearner.h"
00027 #include "Utils/Utils.h"
00028 #include "IO/Serialization.h"
00029
00030 namespace MultiBoost {
00031
00032
00033
00034 InputData* BaseLearner::createInputData()
00035 {
00036 return new InputData();
00037 }
00038
00039
00040
00041 double BaseLearner::getAlpha(const double error)
00042 {
00043 return 0.5 * log( (1-error)/error );
00044 }
00045
00046
00047
00048 double BaseLearner::getAlpha(const double eps_min, const double eps_pls)
00049 {
00050 return 0.5 * log( (eps_pls + _smoothingVal) / (eps_min + _smoothingVal) );
00051 }
00052
00053
00054
00055 double BaseLearner::getAlpha(const double eps_min, const double eps_pls,
00056 const double theta)
00057 {
00058
00059 if ( nor_utils::is_zero(theta) )
00060 return getAlpha( eps_min, eps_pls );
00061
00062 const double eps_zero = 1 - eps_min - eps_pls;
00063
00064 if (eps_min < _smallVal)
00065 {
00066
00067 return log( ( (1-theta)* eps_pls ) / (theta * eps_zero) );
00068 }
00069 else
00070 {
00071
00072 const double denom = (1+theta) * eps_min;
00073 const double b = ((theta) * eps_zero) / (2*denom);
00074 const double c = ((1-theta) * eps_pls) / denom;
00075
00076 return log( -b + sqrt( b * b + c ) );
00077 }
00078
00079 }
00080
00081
00082
00083 void BaseLearner::save(ofstream& outputStream, const int numTabs)
00084 {
00085
00086 outputStream << Serialization::standardTag("alpha", _alpha, numTabs) << endl;
00087 }
00088
00089
00090
00091 void BaseLearner::load(nor_utils::StreamTokenizer& st)
00092 {
00093 _alpha = UnSerialization::seekAndParseEnclosedValue<double>(st, "alpha");
00094 }
00095
00096
00097
00098 }