- Timestamp:
- Dec 26, 2006, 10:56:26 AM (16 years ago)
- Location:
- trunk/yat
- Files:
-
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/random/random.cc
r706 r718 34 34 RNG* RNG::instance_ = NULL; 35 35 36 37 36 RNG::RNG(void) 38 37 { … … 50 49 51 50 51 u_long RNG::max(void) const 52 { 53 return gsl_rng_max(rng_); 54 } 55 56 57 u_long RNG::min(void) const 58 { 59 return gsl_rng_min(rng_); 60 } 61 62 63 std::string RNG::name(void) const 64 { 65 return gsl_rng_name(rng_); 66 } 67 68 69 const gsl_rng* RNG::rng(void) const 70 { 71 return rng_; 72 } 73 74 75 void RNG::seed(u_long s) const 76 { 77 gsl_rng_set(rng_,s); 78 } 79 80 52 81 u_long RNG::seed_from_devurandom(void) 53 82 { … … 72 101 } 73 102 103 // --------------------- RNG_state ---------------------------------- 74 104 75 105 RNG_state::RNG_state(const RNG* rng) … … 85 115 } 86 116 117 const gsl_rng* RNG_state::rng(void) const 118 { 119 return rng_; 120 } 121 87 122 // --------------------- Discrete distribtuions --------------------- 88 123 … … 95 130 Discrete::~Discrete(void) 96 131 { 132 } 133 134 135 void Discrete::seed(u_long s) const 136 { 137 rng_->seed(s); 97 138 } 98 139 … … 116 157 117 158 159 u_long DiscreteGeneral::operator()(void) const 160 { 161 return gsl_ran_discrete(rng_->rng(), gen_); 162 } 163 164 165 DiscreteUniform::DiscreteUniform(void) 166 : range_(rng_->max()) 167 { 168 } 169 170 DiscreteUniform::DiscreteUniform(const u_long n) 171 : range_(n) 172 { 173 if (range_>rng_->max()) 174 range_=rng_->max(); 175 } 176 177 178 u_long DiscreteUniform::operator()(void) const 179 { 180 return gsl_rng_uniform_int(rng_->rng(), range_); 181 } 182 183 184 u_long DiscreteUniform::operator()(const u_long n) const 185 { 186 return gsl_rng_uniform_int(rng_->rng(), n); 187 } 188 189 118 190 Poisson::Poisson(const double m) 119 191 : m_(m) … … 121 193 } 122 194 195 u_long Poisson::operator()(void) const 196 { 197 return gsl_ran_poisson(rng_->rng(), m_); 198 } 199 200 201 u_long Poisson::operator()(const double m) const 202 { 203 return gsl_ran_poisson(rng_->rng(), m); 204 } 205 123 206 // --------------------- Continuous distribtuions --------------------- 124 207 … … 134 217 135 218 219 void Continuous::seed(u_long s) const 220 { 221 rng_->seed(s); 222 } 223 224 136 225 ContinuousGeneral::ContinuousGeneral(const statistics::Histogram& hist) 137 226 : discrete_(DiscreteGeneral(hist)), hist_(hist) … … 140 229 141 230 231 double ContinuousGeneral::operator()(void) const 232 { 233 return hist_.observation_value(discrete_())+(u_()-0.5)*hist_.spacing(); 234 } 235 236 double ContinuousUniform::operator()(void) const 237 { 238 return gsl_rng_uniform(rng_->rng()); 239 } 240 241 142 242 Exponential::Exponential(const double m) 143 243 : m_(m) … … 146 246 147 247 248 double Exponential::operator()(void) const 249 { 250 return gsl_ran_exponential(rng_->rng(), m_); 251 } 252 253 254 double Exponential::operator()(const double m) const 255 { 256 return gsl_ran_exponential(rng_->rng(), m); 257 } 258 259 148 260 Gaussian::Gaussian(const double s, const double m) 149 261 : m_(m), s_(s) … … 151 263 } 152 264 265 266 double Gaussian::operator()(void) const 267 { 268 return gsl_ran_gaussian(rng_->rng(), s_)+m_; 269 } 270 271 272 double Gaussian::operator()(const double s) const 273 { 274 return gsl_ran_gaussian(rng_->rng(), s); 275 } 276 277 278 double Gaussian::operator()(const double s, const double m) const 279 { 280 return gsl_ran_gaussian(rng_->rng(), s)+m; 281 } 282 153 283 }}} // of namespace random, yat, and theplu -
trunk/yat/random/random.h
r706 r718 98 98 /// generator can return. 99 99 /// 100 inline u_long max(void) const { return gsl_rng_max(rng_); }100 u_long max(void) const; 101 101 102 102 /// … … 104 104 /// generator can return. 105 105 /// 106 inline u_long min(void) const { return gsl_rng_min(rng_); }106 u_long min(void) const; 107 107 108 108 /// 109 109 /// @brief Returns the name of the random number generator 110 110 /// 111 inline std::string name(void) const { return gsl_rng_name(rng_); }111 std::string name(void) const; 112 112 113 113 /// 114 114 /// @return const pointer to underlying GSL random generator. 115 115 /// 116 inline const gsl_rng* rng(void) const { return rng_; }116 const gsl_rng* rng(void) const; 117 117 118 118 /// … … 125 125 /// @see seed_from_devurandom 126 126 /// 127 inline void seed(u_long s) const { gsl_rng_set(rng_,s); }127 void seed(u_long s) const; 128 128 129 129 /// … … 168 168 /// @return const pointer to underlying GSL random generator. 169 169 /// 170 inline const gsl_rng* rng(void) const { return rng_; } 171 170 const gsl_rng* rng(void) const; 172 171 173 172 private: … … 209 208 /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed 210 209 /// 211 inline void seed(u_long s) const { rng_->seed(s); }210 void seed(u_long s) const; 212 211 213 212 /// … … 256 255 /// @return A random number. 257 256 /// 258 inline u_long 259 operator()(void) const { return gsl_ran_discrete(rng_->rng(), gen_); } 257 u_long operator()(void) const; 260 258 261 259 private: … … 281 279 /// @brief Default constructor. 282 280 /// 283 DiscreteUniform(void) : range_(rng_->max()) {}281 DiscreteUniform(void); 284 282 285 283 /// … … 296 294 /// functionality will not return). 297 295 /// 298 DiscreteUniform(const u_long n) : range_(n) 299 { if ( range_>rng_->max() ) range_=rng_->max(); } 296 DiscreteUniform(const u_long n); 300 297 301 298 /// … … 304 301 /// likely. n is set in constructor. 305 302 /// 306 inline u_long 307 operator()(void) const { return gsl_rng_uniform_int(rng_->rng(), range_); } 303 u_long operator()(void) const; 308 304 309 305 /// … … 312 308 /// likely. 313 309 /// 314 inline u_long operator()(const u_long n) const 315 { return gsl_rng_uniform_int(rng_->rng(), n); } 310 u_long operator()(const u_long n) const; 316 311 317 312 private: … … 347 342 /// @return A Poisson distributed number. 348 343 /// 349 inline u_long 350 operator()(void) const { return gsl_ran_poisson(rng_->rng(), m_); } 351 352 /// 353 /// @return A Poisson distributed number with expectation value \a 354 /// m 344 u_long operator()(void) const; 345 346 /// 347 /// @return A Poisson distributed number with expectation value 348 /// \a m 355 349 /// 356 350 /// @note this operator ignores parameters set in Constructor 357 351 /// 358 inline u_long 359 operator()(const double m) const { return gsl_ran_poisson(rng_->rng(), m); } 352 u_long operator()(const double m) const; 360 353 361 354 private: … … 393 386 /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed 394 387 /// 395 inline void seed(u_long s) const { rng_->seed(s); }388 void seed(u_long s) const; 396 389 397 390 /// … … 414 407 }; 415 408 409 // ContinuousUniform is declared before ContinuousGeneral to avoid 410 // forward declaration 416 411 /// 417 412 /// @brief Uniform distribution … … 427 422 { 428 423 public: 429 inline double operator()(void) const { return gsl_rng_uniform(rng_->rng());}424 double operator()(void) const; 430 425 }; 431 426 … … 451 446 /// @return A random number. 452 447 /// 453 inline double operator()(void) const 454 { return hist_.observation_value(discrete_())+(u_()-0.5)*hist_.spacing(); } 448 double operator()(void) const; 455 449 456 450 private: … … 476 470 /// @param m is the expectation value of the distribution. 477 471 /// 478 inlineExponential(const double m=1);472 Exponential(const double m=1); 479 473 480 474 /// 481 475 /// @return A random number from exponential distribution. 482 476 /// 483 inline double 484 operator()(void) const { return gsl_ran_exponential(rng_->rng(), m_); } 477 double operator()(void) const; 485 478 486 479 /// … … 490 483 /// @note This operator ignores parameters given in constructor. 491 484 /// 492 inline double operator()(const double m) const 493 { return gsl_ran_exponential(rng_->rng(), m); } 485 double operator()(const double m) const; 494 486 495 487 private: … … 524 516 /// @return A random Gaussian number 525 517 /// 526 inline double 527 operator()(void) const { return gsl_ran_gaussian(rng_->rng(), s_)+m_; } 518 double operator()(void) const; 528 519 529 520 /// … … 533 524 /// @note this operator ignores parameters given in Constructor 534 525 /// 535 inline double 536 operator()(const double s) const { return gsl_ran_gaussian(rng_->rng(), s); } 526 double operator()(const double s) const; 537 527 538 528 /// … … 542 532 /// @note this operator ignores parameters given in Constructor 543 533 /// 544 inline double operator()(const double s, const double m) const 545 { return gsl_ran_gaussian(rng_->rng(), s)+m; } 534 double operator()(const double s, const double m) const; 546 535 547 536 private: -
trunk/yat/regression/Linear.cc
r713 r718 41 41 { 42 42 } 43 43 44 double Linear::alpha(void) const 45 { 46 return alpha_; 47 } 48 49 double Linear::alpha_err(void) const 50 { 51 return sqrt(alpha_var_); 52 } 53 54 double Linear::beta(void) const 55 { 56 return beta_; 57 } 58 59 double Linear::beta_err(void) const 60 { 61 return sqrt(beta_var_); 62 } 44 63 45 64 double Linear::chisq(void) const … … 47 66 return chisq_; 48 67 } 49 50 68 51 69 void Linear::fit(const utility::vector& x, const utility::vector& y) … … 73 91 } 74 92 93 double Linear::r2(void) const 94 { 95 return r2_; 96 } 97 75 98 double Linear::standard_error(const double x) const 76 99 { -
trunk/yat/regression/Linear.h
r713 r718 62 62 @return the parameter \f$ \alpha \f$ 63 63 */ 64 inline double alpha(void) const { return alpha_; }64 double alpha(void) const; 65 65 66 66 /** … … 70 70 @return standard deviation of parameter \f$ \alpha \f$ 71 71 */ 72 inline double alpha_err(void) const { return sqrt(alpha_var_); }72 double alpha_err(void) const; 73 73 74 74 /** … … 78 78 @return the parameter \f$ \beta \f$ 79 79 */ 80 inline double beta(void) const { return beta_; }80 double beta(void) const; 81 81 82 82 /** … … 86 86 @return standard deviation of parameter \f$ \beta \f$ 87 87 */ 88 inline double beta_err(void) const { return sqrt(beta_var_); } 89 90 88 double beta_err(void) const; 89 91 90 /** 92 91 @brief Mean Squared Error … … 109 108 double predict(const double x) const; 110 109 110 /// 111 /// Function returning the coefficient of determination, 112 /// i.e. fraction of variance explained by the linear model. 113 /// 114 double r2(void) const; 115 111 116 /** 112 117 The error of the model is estimated as \f$ \sqrt{ … … 117 122 double standard_error(const double x) const; 118 123 119 ///120 /// Function returning the coefficient of determination,121 /// i.e. fraction of variance explained by the linear model.122 ///123 inline double r2(void) const { return r2_; }124 124 125 125 private: -
trunk/yat/regression/LinearWeighted.cc
r703 r718 42 42 } 43 43 44 double LinearWeighted::alpha(void) const 45 { 46 return alpha_; 47 } 48 49 double LinearWeighted::alpha_err(void) const 50 { 51 return sqrt(alpha_var_); 52 } 53 54 double LinearWeighted::beta(void) const 55 { 56 return beta_; 57 } 58 59 double LinearWeighted::beta_err(void) const 60 { 61 return sqrt(beta_var_); 62 } 63 44 64 void LinearWeighted::fit(const utility::vector& x, 45 65 const utility::vector& y, … … 64 84 } 65 85 86 double LinearWeighted::m_x(void) const 87 { 88 return ap_.x_averager().mean(); 89 } 90 91 double LinearWeighted::m_y(void) const 92 { 93 return ap_.y_averager().mean(); 94 } 95 96 double LinearWeighted::mse(void) const 97 { 98 return mse_; 99 } 100 101 double LinearWeighted::prediction_error(const double x, const double w) const 102 { 103 return sqrt(alpha_var_ + beta_var_*(x-m_x_)*(x-m_x_)+s2(w)); 104 } 105 106 double LinearWeighted::s2(double w) const 107 { 108 return s2_/w; 109 } 110 111 double LinearWeighted::standard_error(const double x) const 112 { 113 return sqrt(alpha_var_ + beta_var_*(x-m_x_)*(x-m_x_) ); 114 } 115 116 double LinearWeighted::sxx(void) const 117 { 118 return ap_.x_averager().sum_xx_centered(); 119 } 120 121 double LinearWeighted::sxy(void) const 122 { 123 return ap_.sum_xy_centered(); 124 } 125 126 double LinearWeighted::syy(void) const 127 { 128 return ap_.y_averager().sum_xx_centered(); 129 } 130 66 131 }}} // of namespaces regression, yat, and theplu -
trunk/yat/regression/LinearWeighted.h
r703 r718 58 58 /// @return the parameter \f$ \alpha \f$ 59 59 /// 60 inline double alpha(void) const { return alpha_; }60 double alpha(void) const; 61 61 62 62 /// 63 63 /// @return standard deviation of parameter \f$ \alpha \f$ 64 64 /// 65 inline double alpha_err(void) const { return sqrt(alpha_var_); }65 double alpha_err(void) const; 66 66 67 67 /// 68 68 /// @return the parameter \f$ \beta \f$ 69 69 /// 70 inline double beta(void) const { return beta_; }70 double beta(void) const; 71 71 72 72 /// 73 73 /// @return standard deviation of parameter \f$ \beta \f$ 74 74 /// 75 inline double beta_err(void) const { return sqrt(beta_var_); }75 double beta_err(void) const; 76 76 77 77 /** … … 90 90 /// @brief Mean Squared Error 91 91 /// 92 inline double mse(void) const { return mse_; }92 double mse(void) const; 93 93 94 94 /// … … 102 102 /// in @a x with weight @a w 103 103 /// 104 inline double prediction_error(const double x, const double w=1) const 105 { return sqrt(alpha_var_ + beta_var_*(x-m_x_)*(x-m_x_)+s2(w)); } 104 double prediction_error(const double x, const double w=1) const; 105 106 /** 107 Noise level for points with weight @a w. 108 */ 109 double s2(double w=1) const; 106 110 107 111 /** … … 109 113 Var(\beta)*(x-m)} \f$. 110 114 */ 111 inline double standard_error(const double x) const 112 { return sqrt(alpha_var_ + beta_var_*(x-m_x_)*(x-m_x_) ); } 113 114 /** 115 Noise level for points with weight @a w. 116 */ 117 inline double s2(double w=1) const { return s2_/w; } 115 double standard_error(const double x) const; 118 116 119 117 private: … … 123 121 LinearWeighted(const LinearWeighted&); 124 122 125 inline double m_x(void) const {return ap_.x_averager().mean(); }126 inline double m_y(void) const {return ap_.y_averager().mean(); }127 inline double sxx(void) const {return ap_.x_averager().sum_xx_centered(); }128 inline double syy(void) const {return ap_.y_averager().sum_xx_centered(); }129 inline double sxy(void) const {return ap_.sum_xy_centered(); }123 double m_x(void) const; 124 double m_y(void) const; 125 double sxx(void) const; 126 double syy(void) const; 127 double sxy(void) const; 130 128 131 129 double alpha_; -
trunk/yat/regression/Local.cc
r703 r718 42 42 Local::~Local(void) 43 43 { 44 } 45 46 void Local::add(const double x, const double y) 47 { 48 data_.push_back(std::make_pair(x,y)); 44 49 } 45 50 … … 114 119 } 115 120 121 const utility::vector& Local::x(void) const 122 { 123 return x_; 124 } 125 126 const utility::vector& Local::y_predicted(void) const 127 { 128 return y_predicted_; 129 } 130 131 const utility::vector& Local::y_err(void) const 132 { 133 return y_err_; 134 } 135 116 136 std::ostream& operator<<(std::ostream& os, const Local& r) 117 137 { -
trunk/yat/regression/Local.h
r703 r718 64 64 /// adding a data point 65 65 /// 66 inline void add(const double x, const double y) 67 { data_.push_back(std::make_pair(x,y)); } 66 void add(const double x, const double y); 68 67 69 ///70 /// Function returning predicted values71 ///72 inline const utility::vector& y_predicted(void) const73 { return y_predicted_; }74 75 ///76 /// Function returning error of predictions77 ///78 inline const utility::vector& y_err(void) const { return y_err_; }79 80 68 /// 81 69 /// @param nof_points Number of points used in each fit … … 87 75 /// @return x-values where fitting was performed. 88 76 /// 89 inline const utility::vector& x(void) const { return x_; } 77 const utility::vector& x(void) const; 78 79 /// 80 /// Function returning predicted values 81 /// 82 const utility::vector& y_predicted(void) const; 83 84 /// 85 /// Function returning error of predictions 86 /// 87 const utility::vector& y_err(void) const; 90 88 91 89 private: -
trunk/yat/regression/MultiDimensional.cc
r713 r718 68 68 69 69 70 double MultiDimensional::predict(const utility::vector& x) const 71 { 72 return fit_parameters_ * x; 73 } 74 75 70 76 double MultiDimensional::prediction_error(const utility::vector& x) const 71 77 { -
trunk/yat/regression/MultiDimensional.h
r713 r718 70 70 /// @return value in @a x according to fitted model 71 71 /// 72 inline double predict(const utility::vector& x) const 73 { return fit_parameters_ * x; } 72 double predict(const utility::vector& x) const; 74 73 75 74 /// -
trunk/yat/regression/MultiDimensionalWeighted.cc
r703 r718 60 60 } 61 61 62 double MultiDimensionalWeighted::predict(const utility::vector& x) const 63 { 64 return fit_parameters_ * x; 65 } 66 62 67 double MultiDimensionalWeighted::prediction_error(const utility::vector& x, 63 68 const double w) const -
trunk/yat/regression/MultiDimensionalWeighted.h
r703 r718 60 60 /// @return value in @a x according to fitted model 61 61 /// 62 inline double predict(const utility::vector& x) const 63 { return fit_parameters_ * x; } 62 double predict(const utility::vector& x) const; 64 63 65 64 /// -
trunk/yat/regression/NaiveWeighted.cc
r703 r718 52 52 } 53 53 54 double NaiveWeighted::predict(const double x) const 55 { 56 return ap_.y_averager().mean(); 57 } 58 59 double NaiveWeighted::mse(void) const 60 { 61 return ap_.y_averager().std(); 62 } 63 64 double NaiveWeighted::standard_error(const double x) const 65 { 66 return ap_.y_averager().standard_error(); 67 } 68 54 69 }}} // of namespaces regression, yat, and theplu -
trunk/yat/regression/NaiveWeighted.h
r703 r718 71 71 /// weighted average. 72 72 /// 73 inline double predict(const double x) const 74 { return ap_.y_averager().mean(); } 73 double predict(const double x) const; 75 74 76 75 /// … … 79 78 /// @see AveragerWeighted 80 79 /// 81 inline double mse(void) const { return ap_.y_averager().std(); }80 double mse(void) const; 82 81 83 82 /// 84 83 /// @return estimation of error of model value in @a x 85 84 /// 86 inline double standard_error(const double x) const 87 { return ap_.y_averager().standard_error(); } 85 double standard_error(const double x) const; 88 86 89 87 private: -
trunk/yat/regression/OneDimensional.cc
r713 r718 62 62 } 63 63 64 65 double OneDimensional::r_squared(void) const 66 { 67 return chisq()/variance(); 68 } 69 70 double OneDimensional::variance(void) const 71 { 72 return ap_.y_averager().variance(); 73 } 74 64 75 }}} // of namespaces regression, yat, and theplu -
trunk/yat/regression/OneDimensional.h
r713 r718 113 113 fraction of the variance explained by the regression model. 114 114 */ 115 inline double r_squared(void) const { return chisq()/variance(); }115 double r_squared(void) const; 116 116 117 117 /** … … 127 127 /// Variance of y 128 128 /// 129 inline double variance(void) const { return ap_.y_averager().variance(); }129 double variance(void) const; 130 130 131 131 /// -
trunk/yat/regression/PolynomialWeighted.cc
r703 r718 54 54 } 55 55 56 double PolynomialWeighted::mse(void) const 57 { 58 return mse_; 59 } 60 56 61 double PolynomialWeighted::predict(const double x) const 57 62 { -
trunk/yat/regression/PolynomialWeighted.h
r703 r718 68 68 69 69 /// 70 /// @todo71 70 /// @brief Mean Squared Error 72 71 /// 73 inline double mse(void) const { return mse_; }72 double mse(void) const; 74 73 75 74 /// -
trunk/yat/statistics/Averager.cc
r703 r718 50 50 } 51 51 52 double Averager::cv(void) const 53 { 54 return x_ ? std()/mean() : 0; 55 } 56 57 double Averager::mean(void) const 58 { 59 return n_ ? x_/n_ : 0; 60 } 61 62 u_long Averager::n(void) const 63 { 64 return n_; 65 } 66 52 67 void Averager::rescale(double a) 53 68 { … … 60 75 n_=0; 61 76 x_=xx_=0.0; 77 } 78 79 double Averager::standard_error(void) const 80 { 81 return sqrt(variance()/n_); 82 } 83 84 double Averager::std(void) const 85 { 86 return sqrt(variance()); 87 } 88 89 double Averager::std(double m) const 90 { 91 return sqrt(variance(m)); 92 } 93 94 double Averager::sum_x(void) const 95 { 96 return x_; 97 } 98 99 double Averager::sum_xx(void) const 100 { 101 return xx_; 102 } 103 104 double Averager::sum_xx_centered(void) const 105 { 106 return xx_-x_*x_/n_; 107 } 108 109 double Averager::variance(double m) const 110 { 111 return n_ ? (xx_ - 2*m*x_ + m*m*n()) /n_ : 0; 112 } 113 114 double Averager::variance(void) const 115 { 116 return n_>1 ? sum_xx_centered()/n_ : 0; 117 } 118 119 double Averager::variance_unbiased(void) const 120 { 121 return (n_>1) ? sum_xx_centered()/(n_-1) : 0; 62 122 } 63 123 -
trunk/yat/statistics/Averager.h
r704 r718 72 72 /// 73 73 template <typename T> 74 void 74 void add_values(const T& v, u_long n=1); 75 75 76 76 /** … … 82 82 @return standard deviation divided by mean. 83 83 */ 84 inline double cv(void) const { return x_ ? std()/mean() : 0; }84 double cv(void) const; 85 85 86 86 /// 87 87 /// @return Mean of presented data, \f$ \frac{1}{n}\sum x_i \f$ 88 88 /// 89 inline double mean(void) const { return n_ ? x_/n_ : 0; }89 double mean(void) const; 90 90 91 91 /// 92 92 /// @return Number of data points 93 93 /// 94 inline u_long n(void) const { return n_; }94 u_long n(void) const; 95 95 96 96 /// … … 106 106 /// \f$ \sqrt{variance()/n} \f$ 107 107 /// 108 inline double standard_error(void) const { return sqrt(variance()/n_); }108 double standard_error(void) const; 109 109 110 110 /// … … 114 114 /// @return The standard deviation, root of the variance(). 115 115 /// 116 inline double std(void) const { return sqrt(variance()); }116 double std(void) const; 117 117 118 118 /// … … 122 122 /// @return Standard deviation around \a m, root of the variance(m). 123 123 /// 124 inline double std(double m) const { return sqrt(variance(m)); }124 double std(double m) const; 125 125 126 126 /// 127 127 /// @return The sum of x 128 128 /// 129 inline double sum_x(void) const { return x_; }129 double sum_x(void) const; 130 130 131 131 /// 132 132 /// @return The sum of squares 133 133 /// 134 inline double sum_xx(void) const { return xx_; }134 double sum_xx(void) const; 135 135 136 136 /// 137 137 /// @return \f$ \sum_i (x_i-m)^2 \f$ 138 138 /// 139 inline double sum_xx_centered(void) const { return xx_-x_*x_/n_; }139 double sum_xx_centered(void) const; 140 140 141 141 /// … … 147 147 /// @return Variance when the mean is known to be \a m. 148 148 /// 149 inline double variance(double m) const 150 { return n_ ? (xx_ - 2*m*x_ + m*m*n()) /n_ : 0; } 149 double variance(double m) const; 151 150 152 151 /// … … 158 157 /// @return Estimation of variance 159 158 /// 160 inline double variance(void) const 161 { return n_>1 ? sum_xx_centered()/n_ : 0; } 159 double variance(void) const; 162 160 163 161 /// … … 169 167 /// @return unbiased estimation of variance 170 168 /// 171 inline double variance_unbiased(void) const 172 { return (n_>1) ? sum_xx_centered()/(n_-1) : 0; } 169 double variance_unbiased(void) const; 173 170 174 171 /// -
trunk/yat/statistics/AveragerPair.cc
r703 r718 47 47 } 48 48 49 double AveragerPair::ccc(void) const 50 { 51 return ( (x_.variance() && y_.variance() && (x_.mean()-y_.mean()) ) ? 52 ((2*covariance()) / 53 ((x_.variance()+y_.variance()) + 54 (x_.mean()-y_.mean())*(x_.mean()-y_.mean()))) : 0); 55 } 56 57 double AveragerPair::correlation(void) const 58 { return ((x_.std()>0 && y_.std()>0) ? 59 (covariance() / (x_.std()*y_.std()) ) : 0); 60 } 61 62 double AveragerPair::covariance(void) const 63 { 64 return (n()>1) ? (xy_ - x_.sum_x()*y_.mean()) / n(): 0; 65 } 66 67 double AveragerPair::mean_xy(void) const 68 { 69 return xy_/n(); 70 } 71 72 double AveragerPair::msd(void) const 73 { 74 return ( x_averager().sum_xx()+y_averager().sum_xx()-2*sum_xy() )/n(); 75 } 76 77 unsigned long AveragerPair::n(void) const 78 { 79 return x_.n(); 80 } 81 49 82 void AveragerPair::reset(void) 50 83 { … … 58 91 } 59 92 93 double AveragerPair::sum_xy(void) const 94 { 95 return xy_; 96 } 97 98 double AveragerPair::sum_xy_centered(void) const 99 { 100 return xy_-x_.sum_x()*y_.mean(); 101 } 102 103 const Averager& AveragerPair::x_averager(void) const 104 { 105 return x_; 106 } 107 108 const Averager& AveragerPair::y_averager(void) const 109 { 110 return y_; 111 } 112 60 113 const AveragerPair& AveragerPair::operator+=(const AveragerPair& a) 61 114 { -
trunk/yat/statistics/AveragerPair.h
r705 r718 85 85 /// @return Concordence correlation coefficient. 86 86 /// 87 inline double ccc(void) const 88 { return ( (x_.variance() && y_.variance() && (x_.mean()-y_.mean()) ) ? 89 ((2*covariance()) / 90 ((x_.variance()+y_.variance()) + 91 (x_.mean()-y_.mean())*(x_.mean()-y_.mean()))) : 0); } 92 87 double ccc(void) const; 88 93 89 /// 94 90 /// \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sqrt{\sum_i … … 97 93 /// @return Pearson correlation coefficient. 98 94 /// 99 inline double correlation(void) const 100 { return ((x_.std()>0 && y_.std()>0) ? 101 (covariance() / (x_.std()*y_.std()) ) : 0); } 95 double correlation(void) const; 102 96 103 97 /// … … 108 102 /// @return The covariance. 109 103 /// 110 inline double covariance(void) const 111 { return (n()>1) ? (xy_ - x_.sum_x()*y_.mean()) / n(): 0; } 104 double covariance(void) const; 112 105 113 106 /// 114 107 /// @return The mean of xy. 115 108 /// 116 inline double mean_xy(void) const { return xy_/n(); }109 double mean_xy(void) const; 117 110 118 111 /// … … 120 113 /// \frac{1}{N} \sum (x-y)^2 \f$ 121 114 /// 122 inline double msd() const 123 {return ( x_averager().sum_xx()+y_averager().sum_xx()-2*sum_xy() )/n();} 115 double msd(void) const; 124 116 125 117 /// 126 118 /// @return The number of pair of data points. 127 119 /// 128 inline unsigned long n(void) const { return x_.n(); }120 unsigned long n(void) const; 129 121 130 122 /// … … 136 128 /// @return The sum of xy. 137 129 /// 138 inline double sum_xy(void) const { return xy_; }130 double sum_xy(void) const; 139 131 140 132 /// 141 133 /// @return \f$ \sum_i (x_i-m_x)(y_i-m_y) \f$ 142 134 /// 143 inline double sum_xy_centered(void) const {return xy_-x_.sum_x()*y_.mean();}135 double sum_xy_centered(void) const; 144 136 145 137 /// 146 138 /// @return A const refencer to the averager object for x. 147 139 /// 148 inline const Averager& x_averager(void) const { return x_; }140 const Averager& x_averager(void) const; 149 141 150 142 /// 151 143 /// @return A const reference to the averager object for y 152 144 /// 153 inline const Averager& y_averager(void) const { return y_; }145 const Averager& y_averager(void) const; 154 146 155 147 /// -
trunk/yat/statistics/AveragerPairWeighted.cc
r703 r718 63 63 64 64 void AveragerPairWeighted::add(const classifier::DataLookupWeighted1D& x, 65 const classifier::DataLookup1D& y) 66 { 67 add(y,x); 68 } 69 70 71 void AveragerPairWeighted::add(const classifier::DataLookupWeighted1D& x, 65 72 const classifier::DataLookupWeighted1D& y) 66 73 { … … 71 78 72 79 80 double AveragerPairWeighted::correlation(void) const 81 { 82 return covariance() / ( x_.std()*y_.std() ); 83 } 84 85 86 double AveragerPairWeighted::covariance(void) const 87 { 88 return sum_xy_centered()/sum_w(); 89 } 90 91 73 92 void AveragerPairWeighted::reset(void) 74 93 { … … 76 95 } 77 96 97 double AveragerPairWeighted::sum_w(void) const 98 { 99 return w_; 100 } 101 102 103 double AveragerPairWeighted::sum_xy(void) const 104 { 105 return wxy_; 106 } 107 108 109 double AveragerPairWeighted::sum_xy_centered(void) const 110 { 111 return sum_xy() - x_.sum_wx()*y_.mean(); 112 } 113 114 115 const AveragerWeighted& AveragerPairWeighted::x_averager(void) const 116 { 117 return x_; 118 } 119 120 121 const AveragerWeighted& AveragerPairWeighted::y_averager(void) const 122 { 123 return y_; 124 } 125 78 126 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/AveragerPairWeighted.h
r703 r718 81 81 /// @a y will be treated as having all weights equal to unity 82 82 /// 83 inlinevoid add(const classifier::DataLookupWeighted1D& x,84 const classifier::DataLookup1D& y){ add(y,x); }83 void add(const classifier::DataLookupWeighted1D& x, 84 const classifier::DataLookup1D& y); 85 85 86 86 /// … … 112 112 /// calculated as \f$ m_x = \frac {\sum w_xw_yx}{\sum w} \f$ 113 113 /// 114 inline double correlation(void) const 115 { return covariance() / ( x_.std()*y_.std() ); } 114 double correlation(void) const; 116 115 117 116 /// … … 119 118 /// is calculated as \f$ m_x = \frac {\sum w_xw_yx}{\sum w} \f$ 120 119 /// 121 inline double covariance(void) const { return sum_xy_centered()/sum_w(); }120 double covariance(void) const; 122 121 123 122 /// … … 129 128 /// @return \f$ \sum w_xw_y \f$ 130 129 /// 131 inline double sum_w(void) const { return w_; }130 double sum_w(void) const; 132 131 133 132 /// 134 133 /// @return \f$ \sum w_xw_yxy \f$ 135 134 /// 136 inline double sum_xy(void) const { return wxy_; }135 double sum_xy(void) const; 137 136 138 137 /// … … 140 139 /// \f$ m_x = \frac {\sum w_xw_yx}{\sum w} \f$ 141 140 /// 142 inline double sum_xy_centered(void) const 143 { return sum_xy() - x_.sum_wx()*y_.mean(); } 141 double sum_xy_centered(void) const; 144 142 145 143 /// … … 148 146 /// @return AveragerWeighted for x 149 147 /// 150 inline const AveragerWeighted& x_averager(void) const { return x_; }148 const AveragerWeighted& x_averager(void) const; 151 149 152 150 /// … … 155 153 /// @return AveragerWeighted for y 156 154 /// 157 inline const AveragerWeighted& y_averager(void) const { return y_; }155 const AveragerWeighted& y_averager(void) const; 158 156 159 157 private: -
trunk/yat/statistics/AveragerWeighted.cc
r703 r718 23 23 24 24 #include "AveragerWeighted.h" 25 #include "Averager.h" 25 26 26 27 namespace theplu { … … 48 49 } 49 50 51 double AveragerWeighted::mean(void) const 52 { 53 return sum_w() ? sum_wx()/sum_w() : 0; 54 } 55 56 double AveragerWeighted::n(void) const 57 { 58 return sum_w()*sum_w()/sum_ww(); 59 } 60 50 61 void AveragerWeighted::rescale(double a) 51 62 { … … 60 71 } 61 72 73 double AveragerWeighted::std(void) const 74 { 75 return sqrt(variance()); 76 } 77 78 double AveragerWeighted::standard_error(void) const 79 { 80 return sqrt(sum_ww()/(sum_w()*sum_w()*sum_w()) * sum_xx_centered()); 81 } 82 83 double AveragerWeighted::sum_w(void) const 84 { 85 return w_.sum_x(); 86 } 87 88 double AveragerWeighted::sum_ww(void) const 89 { 90 return w_.sum_xx(); 91 } 92 93 double AveragerWeighted::sum_wwx(void) const 94 { 95 return wwx_; 96 } 97 98 double AveragerWeighted::sum_wwxx(void) const 99 { 100 return wx_.sum_xx(); 101 } 102 103 double AveragerWeighted::sum_wx(void) const 104 { 105 return wx_.sum_x(); 106 } 107 108 double AveragerWeighted::sum_wxx(void) const 109 { 110 return wxx_; 111 } 112 113 double AveragerWeighted::sum_xx_centered(void) const 114 { 115 return sum_wxx() - mean()*mean()*sum_w(); 116 } 117 118 double AveragerWeighted::variance(const double m) const 119 { 120 return (sum_wxx()-2*m*sum_wx())/sum_w()+m*m; 121 } 122 123 double AveragerWeighted::variance(void) const 124 { 125 return sum_xx_centered()/sum_w(); 126 } 127 128 const Averager& AveragerWeighted::wx(void) const 129 { 130 return wx_; 131 } 132 133 const Averager& AveragerWeighted::w(void) const 134 { 135 return w_; 136 } 137 62 138 const AveragerWeighted& AveragerWeighted::operator+=(const AveragerWeighted& a) 63 139 { -
trunk/yat/statistics/AveragerWeighted.h
r703 r718 95 95 /// @return \f$ \frac{\sum w_ix_i}{\sum w_i} \f$ 96 96 /// 97 inline double mean(void) const { return sum_w() ? sum_wx()/sum_w() : 0; }97 double mean(void) const; 98 98 99 99 /// … … 108 108 /// @return \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$ 109 109 /// 110 inline double n(void) const { return sum_w()*sum_w()/sum_ww(); }110 double n(void) const; 111 111 112 112 /// … … 128 128 /// @return The standard deviation, root of the variance(). 129 129 /// 130 inline double std(void) const { return sqrt(variance()); }130 double std(void) const; 131 131 132 132 /// … … 141 141 /// where \f$ m \f$ is the mean() 142 142 /// 143 inline double standard_error(void) const 144 { return sqrt(sum_ww()/(sum_w()*sum_w()*sum_w()) * 145 sum_xx_centered()); } 143 double standard_error(void) const; 146 144 147 145 /// … … 150 148 /// @return \f$ \sum w_i \f$ 151 149 /// 152 inline double sum_w(void) const 153 { return w_.sum_x(); } 150 double sum_w(void) const; 154 151 155 152 /// 156 153 /// @return \f$ \sum w_i^2 \f$ 157 154 /// 158 inline double sum_ww(void) const 159 { return w_.sum_xx(); } 155 double sum_ww(void) const; 160 156 161 157 /// … … 164 160 /// @return weighted sum of x 165 161 /// 166 inline double sum_wx(void) const 167 { return wx_.sum_x(); } 162 double sum_wx(void) const; 168 163 169 164 /// 170 165 /// @return \f$ \sum_i w_i (x_i-m)^2\f$ 171 166 /// 172 inline double sum_xx_centered(void) const 173 { return sum_wxx() - mean()*mean()*sum_w(); } 167 double sum_xx_centered(void) const; 174 168 175 169 /** … … 179 173 @return Variance when the mean is known to be \a m. 180 174 */ 181 inline double variance(const double m) const 182 { return (sum_wxx()-2*m*sum_wx())/sum_w()+m*m; } 175 double variance(const double m) const; 183 176 184 177 /** … … 191 184 @return The variance. 192 185 */ 193 inline double variance(void) const 194 { return sum_xx_centered()/sum_w(); } 186 double variance(void) const; 195 187 196 188 197 189 private: 198 190 /// 191 /// @return \f$ \sum w_i^2x_i \f$ 192 /// 193 double sum_wwx(void) const; 194 195 /// 199 196 /// @return \f$ \sum w_i^2x_i^2 \f$ 200 197 /// 201 inline double sum_wwxx(void) const 202 { return wx_.sum_xx(); } 198 double sum_wwxx(void) const; 203 199 204 200 /// 205 /// @return \f$ \sum w_i^2x_i \f$206 ///207 inline double sum_wwx(void) const208 { return wwx_; }209 210 ///211 201 /// @return \f$ \sum w_i x_i^2 \f$ 212 202 /// 213 inline double sum_wxx(void) const { return wxx_; } 203 double sum_wxx(void) const; 204 205 const Averager& wx(void) const; 206 const Averager& w(void) const; 214 207 215 208 /// … … 222 215 double wwx_; 223 216 double wxx_; 224 225 inline Averager wx(void) const { return wx_; }226 inline Averager w(void) const { return w_; }227 217 }; 228 218 -
trunk/yat/statistics/Fisher.cc
r683 r718 59 59 d =((c_+d_)*(b_+d_)) / N; 60 60 } 61 62 63 u_int& Fisher::minimum_size(void) 64 { 65 return minimum_size_; 66 } 67 61 68 62 69 double Fisher::oddsratio(const double a, … … 133 140 134 141 135 136 142 double Fisher::score(const classifier::Target& target, 143 const utility::vector& value) 137 144 { 138 145 weighted_=false; … … 186 193 } 187 194 188 189 190 195 double Fisher::score(const classifier::Target& target, 196 const utility::vector& value, 197 const utility::vector& weight) 191 198 { 192 199 weighted_=true; … … 224 231 } 225 232 233 234 double& Fisher::value_cutoff(void) 235 { 236 return value_cutoff_; 237 } 238 226 239 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/Fisher.h
r683 r718 86 86 87 87 /// 88 /// Cutoff sets the limit whether a value should go into the left89 /// or the right row. @see score90 ///91 /// @return reference to cutoff for row92 ///93 inline double& value_cutoff(void) { return value_cutoff_; }94 95 ///96 88 /// Calculates the expected values under the null hypothesis. 97 89 /// a' = (a+c)(a+b)/(a+b+c+d) … … 105 97 /// @return reference to minimum_size 106 98 /// 107 inline u_int& minimum_size(void){ return minimum_size_; }99 u_int& minimum_size(void); 108 100 109 101 /// … … 166 158 const u_int c, const u_int d); 167 159 168 160 /// 161 /// Cutoff sets the limit whether a value should go into the left 162 /// or the right row. @see score 163 /// 164 /// @return reference to cutoff for row 165 /// 166 double& value_cutoff(void); 167 169 168 private: 170 169 double oddsratio(const double a, const double b, -
trunk/yat/statistics/Histogram.cc
r680 r718 32 32 33 33 34 Histogram::Histogram(void)35 36 {37 }34 Histogram::Histogram(void) 35 : xmax_(0), xmin_(0), sum_all_(), sum_histogram_() 36 { 37 } 38 38 39 39 40 41 Histogram::Histogram(const Histogram& b) 42 { 43 *this=b; 44 } 40 Histogram::Histogram(const Histogram& b) 41 { 42 *this=b; 43 } 45 44 46 45 47 48 Histogram::Histogram(const double min, const double max, const size_t n) 49 : histogram_(std::vector<double>(n,0.0)), 50 xmax_(max), xmin_(min), 51 sum_all_(), sum_histogram_() 52 { 53 } 46 Histogram::Histogram(const double min, const double max, const size_t n) 47 : histogram_(std::vector<double>(n,0.0)), 48 xmax_(max), xmin_(min), 49 sum_all_(), sum_histogram_() 50 { 51 } 54 52 55 53 56 57 Histogram::~Histogram(void) 58 { 59 } 54 Histogram::~Histogram(void) 55 { 56 } 60 57 61 58 59 int Histogram::add(const double x, const double w) 60 { 61 sum_all_.add(x,w); 62 if (x<xmin_) 63 return -1; 64 else if (x>=xmax_) 65 return 1; 62 66 63 int Histogram::add(const double x, const double w) 64 { 65 sum_all_.add(x,w); 66 if (x<xmin_) 67 return -1; 68 else if (x>=xmax_) 69 return 1; 70 71 sum_histogram_.add(x,w); 72 histogram_[bin(x)] += w; 73 return 0; 74 } 67 sum_histogram_.add(x,w); 68 histogram_[bin(x)] += w; 69 return 0; 70 } 75 71 76 72 77 78 void Histogram::normalize(bool choice) 79 { 80 double scale_factor; 81 if (choice) 82 scale_factor = sum_all_.sum_w(); 83 else 84 scale_factor = sum_all_.sum_w()*spacing(); 85 for (size_t i=0; i<histogram_.size(); i++) 86 histogram_[i]/=scale_factor; 87 88 } 73 const statistics::AveragerWeighted& Histogram::averager_all(void) const 74 { 75 return sum_all_; 76 } 89 77 90 78 91 void Histogram::reset(void) 92 { 93 for (u_int i=0; i<histogram_.size(); i++) 94 histogram_[i]=0; 95 sum_all_.reset(); 96 sum_histogram_.reset(); 97 } 79 const statistics::AveragerWeighted& Histogram::averager_histogram(void) const 80 { 81 return sum_histogram_; 82 } 98 83 99 84 100 101 const Histogram& Histogram::operator=(const Histogram& b) 102 { 103 if (this==&b) 104 return *this; 105 histogram_=b.histogram_; 106 xmax_=b.xmax_; 107 xmin_=b.xmin_; 108 sum_all_=b.sum_all_; 109 sum_histogram_=b.sum_histogram_; 110 return *this; 111 } 85 size_t Histogram::bin(double d) 86 { 87 return (((d<xmin_) || (d>xmax_)) ? 0 : 88 static_cast<size_t>(floor((d-xmin_)/spacing() ))); 89 } 112 90 113 91 92 size_t Histogram::nof_bins(void) const 93 { 94 return histogram_.size(); 95 } 114 96 115 std::ostream& operator<<(std::ostream& s,const Histogram& histogram)116 {117 s << "# histogram min : " << histogram.xmin() << '\n';118 s << "# histogram max : " << histogram.xmax() << '\n';119 s << "# number of bins: " << histogram.nof_bins() << '\n';120 s << "# nof points in histogram : "121 << histogram.averager_histogram().sum_w() << '\n';122 s << "# nof points in total: "123 << histogram.averager_all().sum_w() << '\n';124 s << "# column 1: center of observation bin\n"125 << "# column 2: frequency\n";126 97 127 for (u_int i=0; i<histogram.nof_bins(); i++) { 128 s.width(12); 129 s << histogram.observation_value(i); 130 s.width(12); 131 s << histogram[i] << '\n'; 132 } 98 void Histogram::normalize(bool choice) 99 { 100 double scale_factor; 101 if (choice) 102 scale_factor = sum_all_.sum_w(); 103 else 104 scale_factor = sum_all_.sum_w()*spacing(); 105 for (size_t i=0; i<histogram_.size(); i++) 106 histogram_[i]/=scale_factor; 107 } 133 108 134 return s; 135 } 109 110 double Histogram::observation_value(const size_t k) const 111 { 112 return xmin_+spacing()*(k+0.5); 113 } 114 115 116 void Histogram::reset(void) 117 { 118 for (u_int i=0; i<histogram_.size(); i++) 119 histogram_[i]=0; 120 sum_all_.reset(); 121 sum_histogram_.reset(); 122 } 123 124 125 double Histogram::spacing(void) const 126 { 127 return (xmax_-xmin_)/nof_bins(); 128 } 129 130 131 double Histogram::xmax(void) const 132 { 133 return xmax_; 134 } 135 136 137 double Histogram::xmin(void) const 138 { 139 return xmin_; 140 } 141 142 143 double Histogram::operator[](size_t k) const 144 { 145 return histogram_[k]; 146 } 147 148 149 const Histogram& Histogram::operator=(const Histogram& b) 150 { 151 if (this==&b) 152 return *this; 153 histogram_=b.histogram_; 154 xmax_=b.xmax_; 155 xmin_=b.xmin_; 156 sum_all_=b.sum_all_; 157 sum_histogram_=b.sum_histogram_; 158 return *this; 159 } 160 161 162 std::ostream& operator<<(std::ostream& s,const Histogram& histogram) 163 { 164 s << "# histogram min : " << histogram.xmin() << '\n'; 165 s << "# histogram max : " << histogram.xmax() << '\n'; 166 s << "# number of bins: " << histogram.nof_bins() << '\n'; 167 s << "# nof points in histogram : " 168 << histogram.averager_histogram().sum_w() << '\n'; 169 s << "# nof points in total: " 170 << histogram.averager_all().sum_w() << '\n'; 171 s << "# column 1: center of observation bin\n" 172 << "# column 2: frequency\n"; 173 174 for (u_int i=0; i<histogram.nof_bins(); i++) { 175 s.width(12); 176 s << histogram.observation_value(i); 177 s.width(12); 178 s << histogram[i] << '\n'; 179 } 180 181 return s; 182 } 136 183 137 184 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/Histogram.h
r683 r718 86 86 /// @return A const reference to an AveragerWeighted object. 87 87 /// 88 inline const statistics::AveragerWeighted& averager_all(void) const 89 { return sum_all_; } 88 const statistics::AveragerWeighted& averager_all(void) const; 90 89 91 90 /// … … 98 97 /// @return A const reference to an AveragerWeighted object. 99 98 /// 100 inline const statistics::AveragerWeighted& averager_histogram(void) const 101 { return sum_histogram_; } 99 const statistics::AveragerWeighted& averager_histogram(void) const; 102 100 103 101 /// 104 102 /// @return The number of bins in the histogram 105 103 /// 106 inline size_t nof_bins(void) const { return histogram_.size(); }104 size_t nof_bins(void) const; 107 105 108 106 /// … … 140 138 /// histogram. 141 139 /// 142 inline double observation_value(const size_t k) const 143 { return xmin_+spacing()*(k+0.5); } 140 double observation_value(const size_t k) const; 144 141 145 142 /// … … 152 149 /// @return The width of the bins in the histogram. 153 150 /// 154 inline double spacing(void) const { return (xmax_-xmin_)/nof_bins(); }151 double spacing(void) const; 155 152 156 153 /// … … 159 156 /// @note The upper boundary value is outside the histogram. 160 157 /// 161 inline double xmax(void) const { return xmax_; }158 double xmax(void) const; 162 159 163 160 /// … … 166 163 /// @note The lower boundary value is inside the histogram. 167 164 /// 168 inline double xmin(void) const { return xmin_; }165 double xmin(void) const; 169 166 170 167 /// 171 168 /// @return The count of bin \a k in the histogram. 172 169 /// 173 inline double operator[](size_t k) const { return histogram_[k]; }170 double operator[](size_t k) const; 174 171 175 172 /// … … 180 177 private: 181 178 // Returns zero if outside boundaries 182 inline size_t bin(double d) 183 { return (((d<xmin_) || (d>xmax_)) ? 0 : 184 static_cast<size_t>(floor((d-xmin_)/spacing() ))); } 179 size_t bin(double d); 185 180 186 181 std::vector<double> histogram_; -
trunk/yat/statistics/ROC.cc
r703 r718 77 77 } 78 78 return p; 79 } 80 81 u_int& ROC::minimum_size(void) 82 { 83 return minimum_size_; 84 } 85 86 size_t ROC::n(void) const 87 { 88 return vec_pair_.size(); 89 } 90 91 size_t ROC::n_pos(void) const 92 { 93 return nof_pos_; 79 94 } 80 95 -
trunk/yat/statistics/ROC.h
r703 r718 59 59 virtual ~ROC(void); 60 60 61 /// 62 /// minimum_size is the threshold for when a normal 63 /// approximation is used for the p-value calculation. 64 /// 65 /// @return reference to minimum_size 66 /// 67 u_int& minimum_size(void); 68 69 /// 70 /// @return number of samples 71 /// 72 size_t n(void) const; 73 74 /// 75 /// @return number of positive samples (Target.binary()==true) 76 /// 77 size_t n_pos(void) const; 78 79 /// 80 ///Calculates the p-value, i.e. the probability of observing an 81 ///area equally or larger if the null hypothesis is true. If P is 82 ///near zero, this casts doubt on this hypothesis. The null 83 ///hypothesis is that the values from the 2 classes are generated 84 ///from 2 identical distributions. The alternative is that the 85 ///median of the first distribution is shifted from the median of 86 ///the second distribution by a non-zero amount. If the smallest 87 ///group size is larger than minimum_size (default = 10), then P 88 ///is calculated using a normal approximation. @return the 89 ///one-sided p-value( if absolute true is used this is equivalent 90 ///to the two-sided p-value.) 91 /// 92 double p_value(void) const; 93 61 94 /// Function taking \a value, \a target (+1 or -1) and vector 62 95 /// defining what samples to use. The score is equivalent to … … 83 116 double score(const classifier::Target& target, 84 117 const classifier::DataLookupWeighted1D& value); 85 86 118 87 119 /** … … 100 132 const utility::vector& value, 101 133 const utility::vector& weight); 102 103 104 ///105 ///Calculates the p-value, i.e. the probability of observing an106 ///area equally or larger if the null hypothesis is true. If P is107 ///near zero, this casts doubt on this hypothesis. The null108 ///hypothesis is that the values from the 2 classes are generated109 ///from 2 identical distributions. The alternative is that the110 ///median of the first distribution is shifted from the median of111 ///the second distribution by a non-zero amount. If the smallest112 ///group size is larger than minimum_size (default = 10), then P113 ///is calculated using a normal approximation. @return the114 ///one-sided p-value( if absolute true is used this is equivalent115 ///to the two-sided p-value.)116 ///117 double p_value(void) const;118 119 ///120 /// minimum_size is the threshold for when a normal121 /// approximation is used for the p-value calculation.122 ///123 /// @return reference to minimum_size124 ///125 inline u_int& minimum_size(void){ return minimum_size_; }126 134 127 135 /// … … 132 140 /// 133 141 bool target(const size_t i) const; 134 135 ///136 /// @return number of samples137 ///138 inline size_t n(void) const { return vec_pair_.size(); }139 140 ///141 /// @return number of positive samples (Target.binary()==true)142 ///143 inline size_t n_pos(void) const { return nof_pos_; }144 142 145 143 private: -
trunk/yat/statistics/Score.cc
r703 r718 46 46 } 47 47 48 void Score::absolute(bool absolute) 49 { 50 absolute_=absolute; 51 } 52 48 53 double Score::score(const classifier::Target& target, 49 54 const classifier::DataLookup1D& value, … … 57 62 } 58 63 64 bool Score::weighted(void) const 65 { 66 return weighted_; 67 } 68 59 69 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/Score.h
r703 r718 64 64 /// @brief Function changing mode of Score 65 65 /// 66 inline void absolute(bool absolute) {absolute_=absolute;}66 void absolute(bool absolute); 67 67 68 68 /// … … 126 126 protected: 127 127 /// return true if method is weighted 128 inline bool weighted(void) const { return weighted_; }128 bool weighted(void) const; 129 129 130 130 /// true if method is absolute, which means if score is below -
trunk/yat/statistics/utility.h
r703 r718 104 104 /// 105 105 template <class T> 106 inlinedouble median(const std::vector<T>& v, const bool sorted=false)106 double median(const std::vector<T>& v, const bool sorted=false) 107 107 { return percentile(v, 50.0, sorted); } 108 108 -
trunk/yat/utility/CommandLine.cc
r687 r718 2 2 3 3 /* 4 Copyright (C) 2006 Peter Johansson 4 Copyright (C) 2006 Peter Johansson, Jari Hakkinen 5 5 6 6 This file is part of the yat library, http://lev.thep.lu.se/trac/yat … … 98 98 add('\0', name, arg, description); 99 99 } 100 100 101 101 102 102 void CommandLine::add_parameter(char name, … … 107 107 } 108 108 109 110 void CommandLine::add_parameter(char short_name, const std::string& long_name, 111 Option::argument_type arg, 112 const std::string& description) 113 { 114 add(short_name, long_name, arg, description); 115 } 116 117 118 bool CommandLine::is_long_option(const std::string& str) 119 { 120 return (str.size()>3 && str[0]=='-' && str[1]=='-'); 121 } 122 123 124 bool CommandLine::is_short_option(const std::string& str) 125 { 126 return (str.size()==2 && str[0]=='-' && isalpha(str[1])); 127 } 128 129 130 u_int& CommandLine::max_argument(void) 131 { 132 return max_argument_; 133 } 134 135 136 u_int& CommandLine::min_argument(void) 137 { 138 return min_argument_; 139 } 140 109 141 110 142 void CommandLine::parse(int argc,const char* argv[]) … … 147 179 } 148 180 } 149 181 182 183 void CommandLine::set_general_description(const std::string& description) 184 { 185 general_description_=description; 186 } 187 150 188 151 189 bool CommandLine::update(const std::string& key, -
trunk/yat/utility/CommandLine.h
r703 r718 5 5 6 6 /* 7 Copyright (C) 2006 Peter Johansson 7 Copyright (C) 2006 Peter Johansson, Jari Hakkinen 8 8 9 9 This file is part of the yat library, http://lev.thep.lu.se/trac/yat … … 136 136 /// @param description string used in help display 137 137 /// 138 inline void add_parameter(const char short_name, 139 const std::string& long_name, 140 Option::argument_type arg = Option::no_arg, 141 const std::string& description = std::string()) 142 { add(short_name, long_name, arg, description); } 138 void add_parameter(char short_name, const std::string& long_name, 139 Option::argument_type arg = Option::no_arg, 140 const std::string& description = std::string()); 143 141 144 142 /// … … 153 151 /// @return maximal number of arguments allowed. 154 152 /// 155 inline u_int& max_argument(void) { return max_argument_; }153 u_int& max_argument(void); 156 154 157 155 /// … … 161 159 /// @return minimal number of arguments allowed. 162 160 /// 163 inline u_int& min_argument(void) { return min_argument_; }161 u_int& min_argument(void); 164 162 165 163 /// … … 184 182 /// giving a general explanation what program is doing. 185 183 /// 186 inline void set_general_description(const std::string& description) 187 { general_description_=description; } 184 void set_general_description(const std::string& description); 188 185 189 186 /// … … 222 219 void usage(void) const; 223 220 224 221 private: 225 222 Option* add(char short_name, 226 223 const std::string& long_name, 227 224 Option::argument_type arg, 228 225 const std::string& describtion); 229 230 inline bool is_long_option(const std::string& str) 231 { return (str.size()>3 && str[0]=='-' && str[1]=='-'); } 232 233 inline bool is_short_option(const std::string& str) 234 { return (str.size()==2 && str[0]=='-' && isalpha(str[1])); } 235 226 bool is_long_option(const std::string& str); 227 bool is_short_option(const std::string& str); 236 228 void print_try_help(void) const; 237 229 std::string split(std::string&, char) const; 238 230 bool update(const std::string& key, const std::string& value); 239 240 231 241 232 typedef std::map<std::string, Option*> key2option; -
trunk/yat/utility/Exception.h
r687 r718 42 42 /// Default constructor 43 43 /// 44 IO_error(void) throw() : std::runtime_error("IO_error:") {}44 inline IO_error(void) throw() : std::runtime_error("IO_error:") {} 45 45 46 46 /// 47 47 /// Constructor for exception with message 48 48 /// 49 IO_error(std::string message) throw()49 inline IO_error(std::string message) throw() 50 50 : std::runtime_error("IO_error: " + message) {} 51 51 }; -
trunk/yat/utility/NNI.cc
r687 r718 75 75 76 76 77 const utility::matrix& NNI::imputed_data(void) const 78 { 79 return imputed_data_; 80 } 81 82 83 const std::vector<size_t>& NNI::not_imputed(void) const 84 { 85 return not_imputed_; 86 } 87 77 88 78 89 // Contributing nearest neighbours are added up to the user set … … 92 103 } 93 104 94 95 105 }}} // of namespace utility, yat, and theplu -
trunk/yat/utility/NNI.h
r687 r718 103 103 /// @return A const reference to the modified data. 104 104 /// 105 const utility::matrix& imputed_data(void) const { return imputed_data_; }105 const utility::matrix& imputed_data(void) const; 106 106 107 107 /// 108 108 /// @return indices of rows in data matrix not imputed 109 109 /// 110 inline std::vector<size_t> not_imputed(void) const { return not_imputed_; }110 const std::vector<size_t>& not_imputed(void) const; 111 111 112 112 protected:
Note: See TracChangeset
for help on using the changeset viewer.