Changeset 718


Ignore:
Timestamp:
Dec 26, 2006, 10:56:26 AM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses #170.

Location:
trunk/yat
Files:
40 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/random/random.cc

    r706 r718  
    3434  RNG* RNG::instance_ = NULL;
    3535
    36 
    3736  RNG::RNG(void)
    3837  {
     
    5049
    5150 
     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
    5281  u_long RNG::seed_from_devurandom(void)
    5382  {
     
    72101  }
    73102
     103  // --------------------- RNG_state ----------------------------------
    74104
    75105  RNG_state::RNG_state(const RNG* rng)
     
    85115  }
    86116
     117  const gsl_rng* RNG_state::rng(void) const
     118  {
     119    return rng_;
     120  }
     121
    87122  // --------------------- Discrete distribtuions ---------------------
    88123
     
    95130  Discrete::~Discrete(void)
    96131  {
     132  }
     133
     134
     135  void Discrete::seed(u_long s) const
     136  {
     137    rng_->seed(s);
    97138  }
    98139
     
    116157
    117158
     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
    118190  Poisson::Poisson(const double m)
    119191    : m_(m)
     
    121193  }
    122194
     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
    123206  // --------------------- Continuous distribtuions ---------------------
    124207
     
    134217
    135218
     219  void Continuous::seed(u_long s) const
     220  {
     221    rng_->seed(s);
     222  }
     223
     224
    136225  ContinuousGeneral::ContinuousGeneral(const statistics::Histogram& hist)
    137226    : discrete_(DiscreteGeneral(hist)), hist_(hist)
     
    140229
    141230
     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
    142242  Exponential::Exponential(const double m)
    143243    : m_(m)
     
    146246
    147247
     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
    148260  Gaussian::Gaussian(const double s, const double m)
    149261    : m_(m), s_(s)
     
    151263  }
    152264
     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
    153283}}} // of namespace random, yat, and theplu
  • trunk/yat/random/random.h

    r706 r718  
    9898    /// generator can return.
    9999    ///
    100     inline u_long max(void) const { return gsl_rng_max(rng_); }
     100    u_long max(void) const;
    101101
    102102    ///
     
    104104    /// generator can return.
    105105    ///
    106     inline u_long min(void) const { return gsl_rng_min(rng_); }
     106    u_long min(void) const;
    107107
    108108    ///
    109109    /// @brief Returns the name of the random number generator
    110110    ///
    111     inline std::string name(void) const { return gsl_rng_name(rng_); }
     111    std::string name(void) const;
    112112
    113113    ///
    114114    /// @return const pointer to underlying GSL random generator.
    115115    ///
    116     inline const gsl_rng* rng(void) const { return rng_; }
     116    const gsl_rng* rng(void) const;
    117117
    118118    ///
     
    125125    /// @see seed_from_devurandom
    126126    ///
    127     inline void seed(u_long s) const { gsl_rng_set(rng_,s); }
     127    void seed(u_long s) const;
    128128
    129129    ///
     
    168168    /// @return const pointer to underlying GSL random generator.
    169169    ///
    170     inline const gsl_rng* rng(void) const { return rng_; }
    171 
     170    const gsl_rng* rng(void) const;
    172171
    173172  private:
     
    209208    /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed
    210209    ///
    211     inline void seed(u_long s) const { rng_->seed(s); }
     210    void seed(u_long s) const;
    212211
    213212    ///
     
    256255    /// @return A random number.
    257256    ///
    258     inline u_long
    259     operator()(void) const { return gsl_ran_discrete(rng_->rng(), gen_); }
     257    u_long operator()(void) const;
    260258
    261259  private:
     
    281279    /// @brief Default constructor.
    282280    ///
    283     DiscreteUniform(void) : range_(rng_->max()) {}
     281    DiscreteUniform(void);
    284282
    285283    ///
     
    296294    /// functionality will not return).
    297295    ///
    298     DiscreteUniform(const u_long n) : range_(n)
    299     { if ( range_>rng_->max() ) range_=rng_->max(); }
     296    DiscreteUniform(const u_long n);
    300297
    301298    ///
     
    304301    /// likely. n is set in constructor.
    305302    ///
    306     inline u_long
    307     operator()(void) const { return gsl_rng_uniform_int(rng_->rng(), range_); }
     303    u_long operator()(void) const;
    308304
    309305    ///
     
    312308    /// likely.
    313309    ///
    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;
    316311
    317312  private:
     
    347342    /// @return A Poisson distributed number.
    348343    ///
    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
    355349    ///
    356350    /// @note this operator ignores parameters set in Constructor
    357351    ///
    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;
    360353
    361354  private:
     
    393386    /// @see seed_from_devurandom, RNG::seed_from_devurandom, RNG::seed
    394387    ///
    395     inline void seed(u_long s) const { rng_->seed(s); }
     388    void seed(u_long s) const;
    396389
    397390    ///
     
    414407  };
    415408
     409  // ContinuousUniform is declared before ContinuousGeneral to avoid
     410  // forward declaration
    416411  ///
    417412  /// @brief Uniform distribution
     
    427422  {
    428423  public:
    429     inline double operator()(void) const { return gsl_rng_uniform(rng_->rng());}
     424    double operator()(void) const;
    430425  };
    431426
     
    451446    /// @return A random number.
    452447    ///
    453     inline double operator()(void) const
    454     { return hist_.observation_value(discrete_())+(u_()-0.5)*hist_.spacing(); }
     448    double operator()(void) const;
    455449
    456450  private:
     
    476470    /// @param m is the expectation value of the distribution.
    477471    ///
    478     inline Exponential(const double m=1);
     472    Exponential(const double m=1);
    479473
    480474    ///
    481475    /// @return A random number from exponential distribution.
    482476    ///
    483     inline double
    484     operator()(void) const { return gsl_ran_exponential(rng_->rng(), m_); }
     477    double operator()(void) const;
    485478
    486479    ///
     
    490483    /// @note This operator ignores parameters given in constructor.
    491484    ///
    492     inline double operator()(const double m) const
    493     { return gsl_ran_exponential(rng_->rng(), m); }
     485    double operator()(const double m) const;
    494486
    495487  private:
     
    524516    /// @return A random Gaussian number
    525517    ///
    526     inline double
    527     operator()(void) const { return gsl_ran_gaussian(rng_->rng(), s_)+m_; }
     518    double operator()(void) const;
    528519
    529520    ///
     
    533524    /// @note this operator ignores parameters given in Constructor
    534525    ///
    535     inline double
    536     operator()(const double s) const { return gsl_ran_gaussian(rng_->rng(), s); }
     526    double operator()(const double s) const;
    537527
    538528    ///
     
    542532    /// @note this operator ignores parameters given in Constructor
    543533    ///
    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;
    546535
    547536  private:
  • trunk/yat/regression/Linear.cc

    r713 r718  
    4141  {
    4242  }
    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  }
    4463
    4564  double Linear::chisq(void) const
     
    4766    return chisq_;
    4867  }
    49 
    5068
    5169  void Linear::fit(const utility::vector& x, const utility::vector& y)
     
    7391  }
    7492
     93  double Linear::r2(void) const
     94  {
     95    return r2_;
     96  }
     97
    7598  double Linear::standard_error(const double x) const
    7699  {
  • trunk/yat/regression/Linear.h

    r713 r718  
    6262       @return the parameter \f$ \alpha \f$
    6363    */
    64     inline double alpha(void) const { return alpha_; }
     64    double alpha(void) const;
    6565
    6666    /**
     
    7070       @return standard deviation of parameter \f$ \alpha \f$
    7171    */
    72     inline double alpha_err(void) const { return sqrt(alpha_var_); }
     72    double alpha_err(void) const;
    7373
    7474    /**
     
    7878       @return the parameter \f$ \beta \f$
    7979    */
    80     inline double beta(void) const { return beta_; }
     80    double beta(void) const;
    8181
    8282    /**
     
    8686       @return standard deviation of parameter \f$ \beta \f$
    8787    */
    88     inline double beta_err(void) const { return sqrt(beta_var_); }
    89    
    90    
     88    double beta_err(void) const;
     89
    9190  /**
    9291       @brief Mean Squared Error
     
    109108    double predict(const double x) const;
    110109
     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
    111116    /**
    112117       The error of the model is estimated as \f$ \sqrt{
     
    117122    double standard_error(const double x) const;
    118123
    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_; }
    124124
    125125  private:
  • trunk/yat/regression/LinearWeighted.cc

    r703 r718  
    4242  }
    4343
     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
    4464  void LinearWeighted::fit(const utility::vector& x,
    4565                           const utility::vector& y,
     
    6484  }
    6585
     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
    66131}}} // of namespaces regression, yat, and theplu
  • trunk/yat/regression/LinearWeighted.h

    r703 r718  
    5858    /// @return the parameter \f$ \alpha \f$
    5959    ///
    60     inline double alpha(void) const { return alpha_; }
     60    double alpha(void) const;
    6161
    6262    ///
    6363    /// @return standard deviation of parameter \f$ \alpha \f$
    6464    ///
    65     inline double alpha_err(void) const { return sqrt(alpha_var_); }
     65    double alpha_err(void) const;
    6666
    6767    ///
    6868    /// @return the parameter \f$ \beta \f$
    6969    ///
    70     inline double beta(void) const { return beta_; }
     70    double beta(void) const;
    7171
    7272    ///
    7373    /// @return standard deviation of parameter \f$ \beta \f$
    7474    ///
    75     inline double beta_err(void) const { return sqrt(beta_var_); }
     75    double beta_err(void) const;
    7676   
    7777    /**
     
    9090    /// @brief Mean Squared Error
    9191    ///
    92     inline double mse(void) const { return mse_; }
     92    double mse(void) const;
    9393
    9494    ///
     
    102102    /// in @a x with weight @a w
    103103    ///
    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;
    106110
    107111    /**
     
    109113       Var(\beta)*(x-m)} \f$.
    110114    */
    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;
    118116
    119117  private:
     
    123121    LinearWeighted(const LinearWeighted&);
    124122
    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;
    130128   
    131129    double alpha_;
  • trunk/yat/regression/Local.cc

    r703 r718  
    4242  Local::~Local(void)
    4343  {
     44  }
     45
     46  void Local::add(const double x, const double y)
     47  {
     48    data_.push_back(std::make_pair(x,y));
    4449  }
    4550
     
    114119  }
    115120
     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
    116136  std::ostream& operator<<(std::ostream& os, const Local& r)
    117137  {
  • trunk/yat/regression/Local.h

    r703 r718  
    6464    /// adding a data point
    6565    ///
    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);
    6867
    69     ///
    70     /// Function returning predicted values
    71     ///
    72     inline const utility::vector& y_predicted(void) const
    73     { return y_predicted_; }
    74 
    75     ///
    76     /// Function returning error of predictions
    77     ///
    78     inline const utility::vector& y_err(void) const { return y_err_; }
    79  
    8068    ///
    8169    /// @param nof_points Number of points used in each fit
     
    8775    /// @return x-values where fitting was performed.
    8876    ///
    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;
    9088
    9189  private:
  • trunk/yat/regression/MultiDimensional.cc

    r713 r718  
    6868
    6969
     70  double MultiDimensional::predict(const utility::vector& x) const
     71  {
     72    return fit_parameters_ * x;
     73  }
     74
     75
    7076  double MultiDimensional::prediction_error(const utility::vector& x) const
    7177  {
  • trunk/yat/regression/MultiDimensional.h

    r713 r718  
    7070    /// @return value in @a x according to fitted model
    7171    ///
    72     inline double predict(const utility::vector& x) const
    73     { return fit_parameters_ * x; }
     72    double predict(const utility::vector& x) const;
    7473
    7574    ///
  • trunk/yat/regression/MultiDimensionalWeighted.cc

    r703 r718  
    6060  }
    6161
     62  double MultiDimensionalWeighted::predict(const utility::vector& x) const
     63  {
     64    return fit_parameters_ * x;
     65  }
     66
    6267  double MultiDimensionalWeighted::prediction_error(const utility::vector& x,
    6368                                                    const double w) const
  • trunk/yat/regression/MultiDimensionalWeighted.h

    r703 r718  
    6060    /// @return value in @a x according to fitted model
    6161    ///
    62     inline double predict(const utility::vector& x) const
    63     { return fit_parameters_ * x; }
     62    double predict(const utility::vector& x) const;
    6463
    6564    ///
  • trunk/yat/regression/NaiveWeighted.cc

    r703 r718  
    5252  }
    5353
     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
    5469}}} // of namespaces regression, yat, and theplu
  • trunk/yat/regression/NaiveWeighted.h

    r703 r718  
    7171    /// weighted average.
    7272    ///
    73     inline double predict(const double x) const
    74     { return ap_.y_averager().mean(); }
     73    double predict(const double x) const;
    7574
    7675    ///
     
    7978    /// @see AveragerWeighted
    8079    ///
    81     inline double mse(void) const { return ap_.y_averager().std(); }
     80    double mse(void) const;
    8281
    8382    ///
    8483    /// @return estimation of error of model value in @a x
    8584    ///
    86     inline double standard_error(const double x) const
    87     { return ap_.y_averager().standard_error(); }
     85    double standard_error(const double x) const;
    8886
    8987  private:
  • trunk/yat/regression/OneDimensional.cc

    r713 r718  
    6262  }
    6363
     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
    6475}}} // of namespaces regression, yat, and theplu
  • trunk/yat/regression/OneDimensional.h

    r713 r718  
    113113       fraction of the variance explained by the regression model.
    114114    */
    115     inline double r_squared(void) const { return chisq()/variance(); }
     115    double r_squared(void) const;
    116116
    117117    /**
     
    127127    /// Variance of y
    128128    ///
    129     inline double variance(void) const { return ap_.y_averager().variance(); }
     129    double variance(void) const;
    130130
    131131    ///
  • trunk/yat/regression/PolynomialWeighted.cc

    r703 r718  
    5454  }
    5555
     56  double PolynomialWeighted::mse(void) const
     57  {
     58    return mse_;
     59  }
     60
    5661  double PolynomialWeighted::predict(const double x) const
    5762  {
  • trunk/yat/regression/PolynomialWeighted.h

    r703 r718  
    6868
    6969    ///
    70     /// @todo
    7170    /// @brief Mean Squared Error
    7271    ///
    73     inline double mse(void) const { return mse_; }
     72    double mse(void) const;
    7473
    7574    ///
  • trunk/yat/statistics/Averager.cc

    r703 r718  
    5050  }
    5151
     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
    5267  void Averager::rescale(double a)
    5368  {
     
    6075    n_=0;
    6176    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;
    62122  }
    63123
  • trunk/yat/statistics/Averager.h

    r704 r718  
    7272    ///
    7373    template <typename T>
    74     void  add_values(const T& v, u_long n=1);
     74    void add_values(const T& v, u_long n=1);
    7575
    7676    /**
     
    8282       @return standard deviation divided by mean.
    8383    */
    84     inline double cv(void) const { return x_ ? std()/mean() : 0; }
     84    double cv(void) const;
    8585
    8686    ///
    8787    /// @return Mean of presented data, \f$ \frac{1}{n}\sum x_i \f$
    8888    ///
    89     inline double mean(void) const { return n_ ? x_/n_ : 0; }
     89    double mean(void) const;
    9090
    9191    ///
    9292    /// @return Number of data points
    9393    ///
    94     inline u_long n(void) const { return n_; }
     94    u_long n(void) const;
    9595
    9696    ///
     
    106106    /// \f$ \sqrt{variance()/n} \f$
    107107    ///
    108     inline double standard_error(void) const { return sqrt(variance()/n_); }
     108    double standard_error(void) const;
    109109
    110110    ///
     
    114114    /// @return The standard deviation, root of the variance().
    115115    ///
    116     inline double std(void) const { return sqrt(variance()); }
     116    double std(void) const;
    117117
    118118    ///
     
    122122    /// @return Standard deviation around \a m, root of the variance(m).
    123123    ///
    124     inline double std(double m) const { return sqrt(variance(m)); }
     124    double std(double m) const;
    125125
    126126    ///
    127127    /// @return The sum of x
    128128    ///
    129     inline double sum_x(void) const { return x_; }
     129    double sum_x(void)  const;
    130130
    131131    ///
    132132    /// @return The sum of squares
    133133    ///
    134     inline double sum_xx(void) const { return xx_; }
     134    double sum_xx(void) const;
    135135
    136136    ///
    137137    /// @return \f$ \sum_i (x_i-m)^2 \f$
    138138    ///
    139     inline double sum_xx_centered(void) const { return xx_-x_*x_/n_; }
     139    double sum_xx_centered(void)  const;
    140140
    141141    ///
     
    147147    /// @return Variance when the mean is known to be \a m.
    148148    ///
    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;
    151150
    152151    ///
     
    158157    /// @return Estimation of variance
    159158    ///
    160     inline double variance(void) const
    161     { return n_>1 ? sum_xx_centered()/n_ : 0; }
     159    double variance(void) const;
    162160
    163161    ///
     
    169167    /// @return unbiased estimation of variance
    170168    ///
    171     inline double variance_unbiased(void) const
    172     { return (n_>1) ? sum_xx_centered()/(n_-1) : 0; }
     169    double variance_unbiased(void) const;
    173170
    174171    ///
  • trunk/yat/statistics/AveragerPair.cc

    r703 r718  
    4747  }
    4848
     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
    4982  void AveragerPair::reset(void)
    5083  {
     
    5891  }
    5992
     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
    60113  const AveragerPair& AveragerPair::operator+=(const AveragerPair& a)
    61114  {
  • trunk/yat/statistics/AveragerPair.h

    r705 r718  
    8585    /// @return Concordence correlation coefficient.
    8686    ///
    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
    9389    ///
    9490    /// \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sqrt{\sum_i
     
    9793    /// @return Pearson correlation coefficient.
    9894    ///
    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;
    10296 
    10397    ///
     
    108102    /// @return The covariance.
    109103    ///
    110     inline double covariance(void) const
    111       { return (n()>1) ? (xy_ - x_.sum_x()*y_.mean()) / n(): 0; }
     104    double covariance(void) const;
    112105 
    113106    ///
    114107    /// @return The mean of xy.
    115108    ///
    116     inline double mean_xy(void) const { return xy_/n(); }
     109    double mean_xy(void) const;
    117110
    118111    ///
     
    120113    /// \frac{1}{N} \sum (x-y)^2 \f$
    121114    ///
    122     inline double msd() const
    123     {return ( x_averager().sum_xx()+y_averager().sum_xx()-2*sum_xy() )/n();}
     115    double msd(void) const;
    124116
    125117    ///
    126118    /// @return The number of pair of data points.
    127119    ///
    128     inline unsigned long n(void) const { return x_.n(); }
     120    unsigned long n(void) const;
    129121
    130122    ///
     
    136128    /// @return The sum of xy.
    137129    ///
    138     inline double sum_xy(void) const { return xy_; }
     130    double sum_xy(void) const;
    139131
    140132    ///
    141133    /// @return \f$ \sum_i (x_i-m_x)(y_i-m_y) \f$
    142134    ///
    143     inline double sum_xy_centered(void) const {return xy_-x_.sum_x()*y_.mean();}
     135    double sum_xy_centered(void) const;
    144136
    145137    ///
    146138    /// @return A const refencer to the averager object for x.
    147139    ///
    148     inline const Averager& x_averager(void) const { return x_; }
     140    const Averager& x_averager(void) const;
    149141
    150142    ///
    151143    /// @return A const reference to the averager object for y
    152144    ///
    153     inline const Averager& y_averager(void) const { return y_; }
     145    const Averager& y_averager(void) const;
    154146
    155147    ///
  • trunk/yat/statistics/AveragerPairWeighted.cc

    r703 r718  
    6363
    6464  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,
    6572                                 const classifier::DataLookupWeighted1D& y)
    6673  {
     
    7178
    7279
     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
    7392  void AveragerPairWeighted::reset(void)
    7493  {
     
    7695  }
    7796
     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
    78126}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/AveragerPairWeighted.h

    r703 r718  
    8181    /// @a y will be treated as having all weights equal to unity
    8282    ///
    83     inline void 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);
    8585
    8686    ///
     
    112112    /// calculated as \f$ m_x = \frac {\sum w_xw_yx}{\sum w} \f$
    113113    ///
    114     inline double correlation(void) const
    115     { return covariance() / ( x_.std()*y_.std() ); }
     114    double correlation(void) const;
    116115 
    117116    ///
     
    119118    /// is calculated as \f$ m_x = \frac {\sum w_xw_yx}{\sum w} \f$
    120119    ///
    121     inline double covariance(void) const { return sum_xy_centered()/sum_w(); }
     120    double covariance(void) const;
    122121
    123122    ///
     
    129128    /// @return \f$ \sum w_xw_y \f$
    130129    ///
    131     inline double sum_w(void) const { return w_; }
     130    double sum_w(void) const;
    132131
    133132    ///
    134133    /// @return \f$ \sum w_xw_yxy \f$
    135134    ///
    136     inline double sum_xy(void) const { return wxy_; }
     135    double sum_xy(void) const;
    137136
    138137    ///
     
    140139    /// \f$ m_x = \frac {\sum w_xw_yx}{\sum w} \f$
    141140    ///
    142     inline double sum_xy_centered(void) const
    143     { return sum_xy() - x_.sum_wx()*y_.mean(); }
     141    double sum_xy_centered(void) const;
    144142
    145143    ///
     
    148146    /// @return AveragerWeighted for x
    149147    ///
    150     inline const AveragerWeighted& x_averager(void) const { return x_; }
     148    const AveragerWeighted& x_averager(void) const;
    151149
    152150    ///
     
    155153    /// @return AveragerWeighted for y
    156154    ///
    157     inline const AveragerWeighted& y_averager(void) const { return y_; }
     155    const AveragerWeighted& y_averager(void) const;
    158156
    159157  private:
  • trunk/yat/statistics/AveragerWeighted.cc

    r703 r718  
    2323
    2424#include "AveragerWeighted.h"
     25#include "Averager.h"
    2526
    2627namespace theplu {
     
    4849  }
    4950
     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
    5061  void AveragerWeighted::rescale(double a)
    5162  {
     
    6071  }
    6172
     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
    62138  const AveragerWeighted& AveragerWeighted::operator+=(const AveragerWeighted& a)
    63139  {
  • trunk/yat/statistics/AveragerWeighted.h

    r703 r718  
    9595    /// @return \f$ \frac{\sum w_ix_i}{\sum w_i} \f$
    9696    ///
    97     inline double mean(void) const { return sum_w() ? sum_wx()/sum_w() : 0; }
     97    double mean(void) const;
    9898
    9999    ///
     
    108108    /// @return \f$ \frac{\left(\sum w_i\right)^2}{\sum w_i^2} \f$
    109109    ///
    110     inline double n(void) const { return sum_w()*sum_w()/sum_ww(); }
     110    double n(void) const;
    111111
    112112    ///
     
    128128    /// @return The standard deviation, root of the variance().
    129129    ///
    130     inline double std(void) const { return sqrt(variance()); }
     130    double std(void) const;
    131131
    132132    ///
     
    141141    /// where \f$ m \f$ is the mean()
    142142    ///
    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;
    146144
    147145    ///
     
    150148    /// @return \f$ \sum w_i \f$
    151149    ///
    152     inline double sum_w(void) const
    153     { return w_.sum_x(); }
     150    double sum_w(void) const;
    154151
    155152    ///
    156153    /// @return \f$ \sum w_i^2 \f$
    157154    ///
    158     inline double sum_ww(void)  const
    159     { return w_.sum_xx(); }
     155    double sum_ww(void) const;
    160156
    161157    ///
     
    164160    /// @return weighted sum of x
    165161    ///
    166     inline double sum_wx(void)  const
    167     { return wx_.sum_x(); }
     162    double sum_wx(void) const;
    168163
    169164    ///
    170165    /// @return \f$ \sum_i w_i (x_i-m)^2\f$
    171166    ///
    172     inline double sum_xx_centered(void) const
    173     { return sum_wxx() - mean()*mean()*sum_w(); }
     167    double sum_xx_centered(void) const;
    174168
    175169    /**
     
    179173       @return Variance when the mean is known to be \a m.
    180174    */
    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;
    183176
    184177    /**
     
    191184       @return The variance.
    192185    */
    193     inline double variance(void) const
    194     { return sum_xx_centered()/sum_w(); }
     186    double variance(void) const;
    195187
    196188
    197189  private:
    198190    ///
     191    ///  @return \f$ \sum w_i^2x_i \f$
     192    ///
     193    double sum_wwx(void) const;
     194
     195    ///
    199196    ///  @return \f$ \sum w_i^2x_i^2 \f$
    200197    ///
    201     inline double sum_wwxx(void)  const
    202     { return wx_.sum_xx(); }
     198    double sum_wwxx(void) const;
    203199   
    204200    ///
    205     ///  @return \f$ \sum w_i^2x_i \f$
    206     ///
    207     inline double sum_wwx(void) const
    208     { return wwx_; }
    209 
    210     ///
    211201    ///  @return \f$ \sum w_i x_i^2 \f$
    212202    ///
    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;
    214207
    215208    ///
     
    222215    double wwx_;
    223216    double wxx_;
    224    
    225     inline Averager wx(void) const { return wx_; }
    226     inline Averager w(void) const { return w_; }
    227217  };
    228218
  • trunk/yat/statistics/Fisher.cc

    r683 r718  
    5959    d =((c_+d_)*(b_+d_)) / N;
    6060  }
     61
     62
     63  u_int& Fisher::minimum_size(void)
     64  {
     65    return minimum_size_;
     66  }
     67
    6168
    6269  double Fisher::oddsratio(const double a,
     
    133140
    134141
    135     double Fisher::score(const classifier::Target& target,
    136                         const utility::vector& value)
     142  double Fisher::score(const classifier::Target& target,
     143                      const utility::vector& value)
    137144  {
    138145    weighted_=false;
     
    186193  }
    187194 
    188     double Fisher::score(const classifier::Target& target,
    189                         const utility::vector& value,
    190                         const utility::vector& weight)
     195  double Fisher::score(const classifier::Target& target,
     196                      const utility::vector& value,
     197                      const utility::vector& weight)
    191198  {
    192199    weighted_=true;
     
    224231  }
    225232
     233
     234  double& Fisher::value_cutoff(void)
     235  {
     236    return value_cutoff_;
     237  }
     238
    226239}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/Fisher.h

    r683 r718  
    8686
    8787    ///
    88     /// Cutoff sets the limit whether a value should go into the left
    89     /// or the right row. @see score
    90     ///
    91     /// @return reference to cutoff for row
    92     ///
    93     inline double& value_cutoff(void) { return value_cutoff_; }
    94 
    95     ///
    9688    /// Calculates the expected values under the null hypothesis.
    9789    /// a' = (a+c)(a+b)/(a+b+c+d)
     
    10597    /// @return reference to minimum_size
    10698    ///
    107     inline u_int& minimum_size(void){ return minimum_size_; } 
     99    u_int& minimum_size(void);
    108100
    109101    ///
     
    166158                 const u_int c, const u_int d);
    167159
    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
    169168  private:
    170169    double oddsratio(const double a, const double b,
  • trunk/yat/statistics/Histogram.cc

    r680 r718  
    3232
    3333
    34 Histogram::Histogram(void)
    35   : xmax_(0), xmin_(0), sum_all_(), sum_histogram_()
    36 {
    37 }
     34  Histogram::Histogram(void)
     35    : xmax_(0), xmin_(0), sum_all_(), sum_histogram_()
     36  {
     37  }
    3838
    3939
    40 
    41 Histogram::Histogram(const Histogram& b)
    42 {
    43   *this=b;
    44 }
     40  Histogram::Histogram(const Histogram& b)
     41  {
     42    *this=b;
     43  }
    4544
    4645
    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  }
    5452
    5553
    56 
    57 Histogram::~Histogram(void)
    58 {
    59 }
     54  Histogram::~Histogram(void)
     55  {
     56  }
    6057
    6158
     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;
    6266
    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  }
    7571
    7672
    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  }
    8977
    9078
    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  }
    9883
    9984
    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  }
    11290
    11391
     92  size_t Histogram::nof_bins(void) const
     93  {
     94    return histogram_.size();
     95  }
    11496
    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";
    12697
    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  }
    133108
    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  }
    136183
    137184}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/Histogram.h

    r683 r718  
    8686    /// @return A const reference to an AveragerWeighted object.
    8787    ///
    88     inline const statistics::AveragerWeighted& averager_all(void) const
    89       { return sum_all_; }
     88    const statistics::AveragerWeighted& averager_all(void) const;
    9089
    9190    ///
     
    9897    /// @return A const reference to an AveragerWeighted object.
    9998    ///
    100     inline const statistics::AveragerWeighted& averager_histogram(void) const
    101       { return sum_histogram_; }
     99    const statistics::AveragerWeighted& averager_histogram(void) const;
    102100
    103101    ///
    104102    /// @return The number of bins in the histogram
    105103    ///
    106     inline size_t nof_bins(void) const { return histogram_.size(); }
     104    size_t nof_bins(void) const;
    107105
    108106    ///
     
    140138    /// histogram.
    141139    ///
    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;
    144141
    145142    ///
     
    152149    /// @return The width of the bins in the histogram.
    153150    ///
    154     inline double spacing(void) const { return (xmax_-xmin_)/nof_bins(); }
     151    double spacing(void) const;
    155152
    156153    ///
     
    159156    /// @note The upper boundary value is outside the histogram.
    160157    ///
    161     inline double xmax(void) const { return xmax_; }
     158    double xmax(void) const;
    162159
    163160    ///
     
    166163    /// @note The lower boundary value is inside the histogram.
    167164    ///
    168     inline double xmin(void) const { return xmin_; }
     165    double xmin(void) const;
    169166
    170167    ///
    171168    /// @return The count of bin \a k in the histogram.
    172169    ///
    173     inline double operator[](size_t k) const { return histogram_[k]; }
     170    double operator[](size_t k) const;
    174171
    175172    ///
     
    180177  private:
    181178    // 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);
    185180
    186181    std::vector<double> histogram_;
  • trunk/yat/statistics/ROC.cc

    r703 r718  
    7777    }
    7878    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_;
    7994  }
    8095
  • trunk/yat/statistics/ROC.h

    r703 r718  
    5959    virtual ~ROC(void);
    6060         
     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   
    6194    /// Function taking \a value, \a target (+1 or -1) and vector
    6295    /// defining what samples to use. The score is equivalent to
     
    83116    double score(const classifier::Target& target,
    84117                 const classifier::DataLookupWeighted1D& value);
    85        
    86118
    87119    /**
     
    100132                 const utility::vector& value,
    101133                 const utility::vector& weight);
    102        
    103 
    104     ///
    105     ///Calculates the p-value, i.e. the probability of observing an
    106     ///area equally or larger if the null hypothesis is true. If P is
    107     ///near zero, this casts doubt on this hypothesis. The null
    108     ///hypothesis is that the values from the 2 classes are generated
    109     ///from 2 identical distributions. The alternative is that the
    110     ///median of the first distribution is shifted from the median of
    111     ///the second distribution by a non-zero amount. If the smallest
    112     ///group size is larger than minimum_size (default = 10), then P
    113     ///is calculated using a normal approximation.  @return the
    114     ///one-sided p-value( if absolute true is used this is equivalent
    115     ///to the two-sided p-value.)
    116     ///
    117     double p_value(void) const;
    118    
    119     ///
    120     /// minimum_size is the threshold for when a normal
    121     /// approximation is used for the p-value calculation.
    122     ///
    123     /// @return reference to minimum_size
    124     ///
    125     inline u_int& minimum_size(void){ return minimum_size_; } 
    126134
    127135    ///
     
    132140    ///
    133141    bool target(const size_t i) const;
    134 
    135     ///
    136     /// @return number of samples
    137     ///
    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_; }
    144142
    145143  private:
  • trunk/yat/statistics/Score.cc

    r703 r718  
    4646  }
    4747
     48  void Score::absolute(bool absolute)
     49  {
     50    absolute_=absolute;
     51  }
     52
    4853  double Score::score(const classifier::Target& target,
    4954                      const classifier::DataLookup1D& value,
     
    5762  }
    5863
     64  bool Score::weighted(void) const
     65  {
     66    return weighted_;
     67  }
     68
    5969}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/Score.h

    r703 r718  
    6464    /// @brief Function changing mode of Score
    6565    ///
    66     inline void absolute(bool absolute) {absolute_=absolute;}
     66    void absolute(bool absolute);
    6767
    6868    ///
     
    126126  protected:
    127127    /// return true if method is weighted
    128     inline bool weighted(void) const { return weighted_; }
     128    bool weighted(void) const;
    129129
    130130    /// true if method is absolute, which means if score is below
  • trunk/yat/statistics/utility.h

    r703 r718  
    104104  ///
    105105  template <class T>
    106   inline double median(const std::vector<T>& v, const bool sorted=false)
     106  double median(const std::vector<T>& v, const bool sorted=false)
    107107  { return percentile(v, 50.0, sorted); }
    108108
  • trunk/yat/utility/CommandLine.cc

    r687 r718  
    22
    33/*
    4   Copyright (C) 2006 Peter Johansson
     4  Copyright (C) 2006 Peter Johansson, Jari Hakkinen
    55
    66  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    9898      add('\0', name, arg, description);
    9999  }
    100  
     100
    101101
    102102  void CommandLine::add_parameter(char name,
     
    107107  }
    108108 
     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
    109141
    110142  void CommandLine::parse(int argc,const char* argv[])
     
    147179    }
    148180  }
    149  
     181
     182
     183  void CommandLine::set_general_description(const std::string& description)
     184  {
     185    general_description_=description;
     186  }
     187
    150188
    151189  bool CommandLine::update(const std::string& key,
  • trunk/yat/utility/CommandLine.h

    r703 r718  
    55
    66/*
    7   Copyright (C) 2006 Peter Johansson
     7  Copyright (C) 2006 Peter Johansson, Jari Hakkinen
    88
    99  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    136136    /// @param description string used in help display
    137137    ///
    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());
    143141
    144142    ///
     
    153151    /// @return maximal number of arguments allowed.
    154152    ///
    155     inline u_int& max_argument(void) { return max_argument_; }
     153    u_int& max_argument(void);
    156154
    157155    ///
     
    161159    /// @return minimal number of arguments allowed.
    162160    ///
    163     inline u_int& min_argument(void) { return min_argument_; }
     161    u_int& min_argument(void);
    164162
    165163    ///
     
    184182    /// giving a general explanation what program is doing.
    185183    ///
    186     inline void set_general_description(const std::string& description)
    187     { general_description_=description; }
     184    void set_general_description(const std::string& description);
    188185
    189186    ///
     
    222219    void usage(void) const;
    223220
    224     private:
     221  private:
    225222    Option* add(char short_name,
    226223                const std::string& long_name,
    227224                Option::argument_type arg,
    228225                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);
    236228    void print_try_help(void) const;
    237229    std::string split(std::string&, char) const;
    238230    bool update(const std::string& key, const std::string& value);
    239 
    240231
    241232    typedef std::map<std::string, Option*> key2option;
  • trunk/yat/utility/Exception.h

    r687 r718  
    4242    /// Default constructor
    4343    ///
    44     IO_error(void) throw() : std::runtime_error("IO_error:") {}
     44    inline IO_error(void) throw() : std::runtime_error("IO_error:") {}
    4545
    4646    ///
    4747    /// Constructor for exception with message
    4848    ///
    49     IO_error(std::string message) throw()
     49    inline IO_error(std::string message) throw()
    5050      : std::runtime_error("IO_error: " + message) {}
    5151  };
  • trunk/yat/utility/NNI.cc

    r687 r718  
    7575
    7676
     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
    7788
    7889  // Contributing nearest neighbours are added up to the user set
     
    92103  }
    93104
    94 
    95105}}} // of namespace utility, yat, and theplu
  • trunk/yat/utility/NNI.h

    r687 r718  
    103103    /// @return A const reference to the modified data.
    104104    ///
    105     const utility::matrix& imputed_data(void) const { return imputed_data_; }
     105    const utility::matrix& imputed_data(void) const;
    106106
    107107    ///
    108108    /// @return indices of rows in data matrix not imputed
    109109    ///
    110     inline std::vector<size_t> not_imputed(void) const { return not_imputed_; }
     110    const std::vector<size_t>& not_imputed(void) const;
    111111
    112112  protected:
Note: See TracChangeset for help on using the changeset viewer.