Changeset 727 for trunk/yat/regression


Ignore:
Timestamp:
Jan 4, 2007, 4:06:14 PM (15 years ago)
Author:
Peter
Message:

fixes #177

Location:
trunk/yat/regression
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/regression/Linear.cc

    r726 r727  
    9797  }
    9898
    99   double Linear::standard_error(const double x) const
     99  double Linear::standard_error2(const double x) const
    100100  {
    101     return sqrt( alpha_var_+beta_var_*(x-ap_.x_averager().mean())*
    102                  (x-ap_.x_averager().mean()) );
     101    return alpha_var_+beta_var_*(x-ap_.x_averager().mean())*
     102      (x-ap_.x_averager().mean());
    103103  }
    104104
  • trunk/yat/regression/Linear.h

    r726 r727  
    113113
    114114    /**
    115        The error of the model is estimated as \f$ \sqrt{
    116        \textrm{alpha\_err}^2+\textrm{beta\_err}^2*(x-m_x)*(x-m_x)}\f$
     115       The error of the model is estimated as \f$
     116       \textrm{alpha\_err}^2+\textrm{beta\_err}^2*(x-m_x)*(x-m_x)\f$
    117117   
    118118       @return estimated error of model in @a x
    119119    */
    120     double standard_error(const double x) const;
     120    double standard_error2(const double x) const;
    121121
    122122
  • trunk/yat/regression/MultiDimensional.cc

    r726 r727  
    8080
    8181
    82   double MultiDimensional::prediction_error(const utility::vector& x) const
     82  double MultiDimensional::prediction_error2(const utility::vector& x) const
     83  {
     84    return standard_error2(x)+chisquare_;
     85  }
     86
     87
     88  double MultiDimensional::standard_error2(const utility::vector& x) const
    8389  {
    8490    double s2 = 0;
     
    8894        s2 += 2*covariance_(i,j)*x(i)*x(j);
    8995    }
    90     return sqrt(s2+chisquare_);
    91   }
    92 
    93 
    94   double MultiDimensional::standard_error(const utility::vector& x) const
    95   {
    96     double s2 = 0;
    97     for (size_t i=0; i<x.size(); ++i){
    98       s2 += covariance_(i,i)*x(i)*x(i);
    99       for (size_t j=i+1; j<x.size(); ++j)
    100         s2 += 2*covariance_(i,j)*x(i)*x(j);
    101     }
    102     return sqrt(s2);
     96    return s2;
    10397  }
    10498
  • trunk/yat/regression/MultiDimensional.h

    r726 r727  
    7878
    7979    ///
    80     /// @return expected prediction error for a new data point in @a x
     80    /// @return expected squared prediction error for a new data point
     81    /// in @a x
    8182    ///
    82     double prediction_error(const utility::vector& x) const;
     83    double prediction_error2(const utility::vector& x) const;
    8384
    8485    ///
    85     /// @return error of model value in @a x
     86    /// @return squared error of model value in @a x
    8687    ///
    87     double standard_error(const utility::vector& x) const;
     88    double standard_error2(const utility::vector& x) const;
    8889
    8990  private:
  • trunk/yat/regression/Naive.cc

    r726 r727  
    6666 
    6767
    68   double Naive::standard_error(const double x) const
     68  double Naive::standard_error2(const double x) const
    6969  {
    70     return ap_.y_averager().standard_error();
     70    return chisq()/ap_.n()/(ap_.n()-1);
    7171  }
    7272
  • trunk/yat/regression/Naive.h

    r726 r727  
    7979    /// @see statistics::Averager
    8080    ///
    81     double standard_error(const double x) const;
     81    double standard_error2(const double x) const;
    8282
    8383  private:
  • trunk/yat/regression/OneDimensional.cc

    r718 r727  
    3737
    3838
    39   double OneDimensional::prediction_error(const double x) const
     39  double OneDimensional::prediction_error2(const double x) const
    4040  {
    41     return sqrt(chisq()+pow(standard_error(x),2));
     41    return chisq()+standard_error2(x);
    4242  }
    4343
     
    5656    for ( double x=min; x<=max; x+=dx) {
    5757      double y = predict(x);
    58       double y_err = prediction_error(x);
     58      double y_err = sqrt(prediction_error2(x));
    5959      os << x << "\t" << y << "\t" << y_err << "\n";
    6060    }
  • trunk/yat/regression/OneDimensional.h

    r726 r727  
    6464   
    6565    /**
    66        This function computes the best-fit given a model (see
    67        specific class for details) by minimizing \f$
    68        \sum{(\hat{y_i}-y_i)^2} \f$, where \f$ \hat{y} \f$ is the fitted value.
     66       This function computes the best-fit given a model (see specific
     67       class for details) by minimizing \f$ \sum{(\hat{y_i}-y_i)^2}
     68       \f$, where \f$ \hat{y} \f$ is the fitted value.
    6969    */
    7070    virtual void fit(const utility::vector& x, const utility::vector& y)=0;
     
    7676   
    7777    /**
    78        The prediction error is defined as the square root of the
    79        expected squared deviation a new data point will have from
    80        value the model provides. The expected squared deviation is
    81        defined as \f$ E(Y|x - \hat{y}(x))^2 \f$ and is typically
     78       The prediction error is defined as the expected squared
     79       deviation a new data point will have from value the model
     80       provides: \f$ E(Y|x - \hat{y}(x))^2 \f$ and is typically
    8281       divided into two terms \f$ E(Y|x - E(Y|x))^2 \f$ and \f$
    8382       E(E(Y|x) - \hat{y}(x))^2 \f$, which is the conditional variance
    8483       given \f$ x \f$ and the squared standard error (see
    85        standard_error()) of the model estimation in \f$ x \f$,
     84       standard_error2()) of the model estimation in \f$ x \f$,
    8685       respectively.
    8786       
    88        @return expected prediction error for a new data point in @a x
     87       @return expected squared prediction error for a new data point
     88       in @a x
    8989    */
    90     double prediction_error(const double x) const;
     90    double prediction_error2(const double x) const;
    9191
    9292    ///
     
    114114
    115115    /**
    116        The standard error is defined as \f$ \sqrt{E(Y|x -
    117        \hat{y}(x))^2 }\f$
     116       The standard error is defined as \f$ E(Y|x - \hat{y}(x))^2 \f$
    118117
    119        @return expected error of model value in @a x
     118       @return expected squared error of model value in @a x
    120119    */
    121     virtual double standard_error(const double x) const=0;
     120    virtual double standard_error2(const double x) const=0;
    122121
    123122  protected:
  • trunk/yat/regression/Polynomial.cc

    r726 r727  
    7878
    7979
    80   double Polynomial::standard_error(const double x) const
     80  double Polynomial::standard_error2(const double x) const
    8181  {
    8282    utility::vector vec(power_+1,1);
    8383    for (size_t i=1; i<=power_; ++i)
    8484      vec(i) = vec(i-1)*x;
    85     return md_.standard_error(vec);
     85    return md_.standard_error2(vec);
    8686  }
    8787
  • trunk/yat/regression/Polynomial.h

    r726 r727  
    8686
    8787    ///
    88     /// @return error of model value in @a x
     88    /// @return squared error of model value in @a x
    8989    ///
    90     double standard_error(const double x) const;
     90    double standard_error2(const double x) const;
    9191
    9292  private:
Note: See TracChangeset for help on using the changeset viewer.