Changeset 428


Ignore:
Timestamp:
Dec 8, 2005, 5:20:36 PM (17 years ago)
Author:
Peter
Message:

improved doc in Score

Location:
trunk/lib/statistics
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/statistics/Linear.cc

    r385 r428  
    3434  }
    3535
    36   void Linear::fit(const gslapi::vector& x,
    37                    const gslapi::vector& y,
    38                    const gslapi::vector& w)
    39   {
    40     double m_x = w*x /w.sum();
    41     double m_y = w*y /w.sum();
    42    
    43     double sxy = 0;
    44     for (size_t i=0; i<x.size(); i++)
    45       sxy += w(i)*(x(i)-m_x)*(y(i)-m_y);
    46 
    47     double sxx = 0;
    48     for (size_t i=0; i<x.size(); i++)
    49       sxx += w(i)*(x(i)-m_x)*(x(i)-m_x);
    50 
    51     double syy = 0;
    52     for (size_t i=0; i<y.size(); i++)
    53       syy += w(i)*(y(i)-m_y)*(y(i)-m_y);
    54 
    55     // estimating the noise level. see attached document for motivation
    56     // of the expression.
    57     s2_= (syy-sxy*sxy/sxx)/(w.sum()-2*(w*w)/w.sum()) ;
    58    
    59     alpha_ = m_y;
    60     beta_ = sxy/sxx;
    61     alpha_var_ = s2_/w.sum();
    62     beta_var_ = s2_/sxx; 
    63     m_x_=m_x;
     36  void Linear::predict(const double x, double& y, double& y_err)
     37  {
     38    y = alpha_ + beta_ * (x-m_x_);
     39    y_err = sqrt( alpha_var_+beta_var_*(x-m_x_)*(x-m_x_)+s2_/w );
     40    x_=x;
     41    y_=y;
     42    y_err_=y_err;
    6443  }
    6544
  • trunk/lib/statistics/Linear.h

    r420 r428  
    6464   
    6565    ///
    66     /// This function computes the best-fit linear regression
    67     /// coefficients \f$ (\alpha, \beta)\f$ of the model \f$ y =
    68     /// \alpha + \beta (x-m_x) \f$ from vectors \a x and \a y, by
    69     /// minimizing \f$ \sum{w_i(y_i - \alpha - \beta (x-m_x))^2} \f$,
    70     /// where \f$ m_x \f$ is the weighted average. By construction \f$
    71     /// \alpha \f$ and \f$ \beta \f$ are independent.
     66    /// Function predicting value using the linear model. \a y_err is
     67    /// the expected deviation from the line for a new data point.
    7268    ///
    73     void fit(const gslapi::vector& x, const gslapi::vector& y,
    74              const gslapi::vector& w);
    75    
    76     ///
    77     /// Function predicting value using the linear model. \a y_err is
    78     /// the expected deviation from the line for a new data point. If
    79     /// weights are used a weight can be specified for the new point.
    80     ///
    81     inline void predict(const double x, double& y, double& y_err,
    82                         const double w=1.0)
    83     {
    84       y = alpha_ + beta_ * (x-m_x_);
    85       y_err = sqrt( alpha_var_+beta_var_*(x-m_x_)*(x-m_x_)+s2_/w );
    86       x_=x;
    87       y_=y;
    88       y_err_=y_err;
    89     }
     69    void predict(const double x, double& y, double& y_err)
    9070
    9171    ///
  • trunk/lib/statistics/OneDimensional.h

    r389 r428  
    6868    /// x for predicted point
    6969    ///
    70     double x_;
     70    //double x_;
    7171    ///
    7272    /// y for predicted point
    7373    ///
    74     double y_;
     74    //double y_;
    7575    ///
    7676    /// estimated error of predicted point (in y).
    7777    ///
    78     double y_err_;
     78    //double y_err_;
    7979  };
    8080
  • trunk/lib/statistics/Score.h

    r410 r428  
    99namespace statistics {
    1010
    11   ///
     11  ///
    1212  /// Abstract Base Class defining the interface for the score classes.
    13   ///
    14   class Score
    15   {
    16    
    17   public:
    18     ///
    19     ///   Constructor
    20     ///   
    21     Score(bool absolute=true) ;
     13  ///
     14  class Score
     15  {
     16
     17  public:
     18    ///
     19    ///   Constructor
     20    ///   
     21    Score(bool absolute=true) ;
    2222   
    2323    ///
    24     ///   Destructor
    25     ///
    26     virtual ~Score(void) {};
     24    ///   Destructor
     25    ///
     26    virtual ~Score(void) {};
    2727   
    28     ///
     28    ///
    2929    ///  Function changing mode of Score
    3030    ///
     
    3939    /// @return statistica.
    4040    ///
    41     /// @param target is +1 or -1
     41    /// @param target vector of targets (most often +1 -1)
    4242    /// @param value vector of the values
    4343    /// @train_set defining which values to use (number of values used
Note: See TracChangeset for help on using the changeset viewer.