Changeset 718 for trunk/yat/regression


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

Addresses #170.

Location:
trunk/yat/regression
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • 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    ///
Note: See TracChangeset for help on using the changeset viewer.