00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __plLear1dNormal_h_
00019 #define __plLear1dNormal_h_
00020
00021 #include <plLearn.h>
00022 #include <plNormal.h>
00023 #include <plBellShape.h>
00024
00025 #define PL_NORMAL_RANGE_PROPORTION 3.0
00026
00028 class plLearn1dNormal :public plNonCndLearnObject
00029 {
00030 public:
00031
00033 plLearn1dNormal(const plVariablesConjunction &vars)
00034 :plNonCndLearnObject(vars),
00035 _s(0.0), _s2(0.0),
00036 _init_mean(0.0), _init_std_dev(0.0), _init_weight(0.0)
00037 {};
00038
00040 plLearn1dNormal(const plVariablesConjunction &vars, double init_mean,
00041 double init_std_dev, double init_weight = 1.0)
00042 :plNonCndLearnObject(vars),_init_mean(init_mean), _init_std_dev(init_std_dev), _init_weight(init_weight)
00043 {
00044 _total_weight = _init_weight;
00045 _s = _init_weight*_init_mean;
00046 _s2 = _init_weight*(_init_mean*_init_mean + _init_std_dev*_init_std_dev);
00047 };
00048
00050 plLearn1dNormal()
00051 :plNonCndLearnObject(),_s(0.0), _s2(0.0),
00052 _init_mean(0.0), _init_std_dev(0.0), _init_weight(0.0)
00053 {};
00054
00056 virtual ~plLearn1dNormal(){};
00057
00059 void reset()
00060 {
00061 _nsamples = 0;
00062 _total_weight = _init_weight;
00063 _s = _init_weight*_init_mean;
00064 _s2 = _init_weight*(_init_mean*_init_mean + _init_std_dev*_init_std_dev);
00065 }
00066
00070 void internal_addPoint(const plDataValues &point, double weight)
00071 {
00072 _nsamples++;
00073 _total_weight += weight;
00074 double x = double(point[0]);
00075 _s += weight*x;
00076 _s2 += (weight*x*x);
00077 }
00078
00080 double get_mu()const
00081 {
00082 if( 0.0 != _total_weight ) return _s/_total_weight;
00083 return 0.0;
00084 }
00085
00087 double get_var() const
00088 {
00089 if( 0.0 != _total_weight ) return _s2/_total_weight;
00090 return 0.0;
00091 }
00092
00093
00095 double get_sigma()const
00096 {
00097 if(0.0 == _total_weight) return 0.0;
00098
00099 double mu = get_mu();
00100 double v = _s2/_total_weight - mu*mu;
00101
00102 if(v <= 0.0) return 0.0;
00103
00104 return sqrt(v);
00105 }
00106
00108 void get_params(plValues ¶ms) const
00109 {
00110 params[0] = get_mu();
00111 params[1] = get_sigma();
00112 }
00113
00115 void get_actual_min_max(double &min, double &max) const
00116 {
00117 double mu = get_mu();
00118 double sigma = get_sigma();
00119
00120 min = mu - PL_NORMAL_RANGE_PROPORTION*sigma;
00121 max = mu + PL_NORMAL_RANGE_PROPORTION*sigma;
00122 }
00123
00125 plKernel get_distribution( const void *parameters = NULL ) const
00126 {
00127 return plNormal(_left_vars, get_mu(), get_sigma());
00128 }
00129
00130
00131 protected:
00132 double _s;
00133 double _s2;
00134
00135
00136 double _init_mean;
00137 double _init_std_dev;
00138 double _init_weight;
00139 };
00140
00141 class plLearnBellShape :public plLearn1dNormal
00142 {
00143 public:
00145 plLearnBellShape(const plVariablesConjunction &vars)
00146 :plLearn1dNormal(vars)
00147 {}
00148
00150 plLearnBellShape(const plVariablesConjunction &vars, double init_mean,
00151 double init_std_dev, double init_weight = 1.0)
00152 :plLearn1dNormal(vars, init_mean, init_std_dev, init_weight)
00153 {}
00154
00155
00157 plLearnBellShape()
00158 :plLearn1dNormal()
00159 {}
00160
00162 plKernel get_distribution( const void *parameters = NULL ) const
00163 {
00164 return plBellShape(_left_vars, get_mu(), get_sigma());
00165 }
00166
00167 };
00168
00169
00170 #endif