Changeset 703 for trunk/yat/statistics


Ignore:
Timestamp:
Dec 18, 2006, 1:47:44 AM (17 years ago)
Author:
Jari Häkkinen
Message:

Addresses #65 and #170.

Location:
trunk/yat/statistics
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/statistics/Averager.cc

    r680 r703  
    4343  }
    4444
     45  void Averager::add(double d, u_long n)
     46  {
     47    n_  += n;
     48    x_  += n*d;
     49    xx_ += n*d*d;
     50  }
     51
     52  void Averager::rescale(double a)
     53  {
     54    x_  *= a;
     55    xx_ *= a*a;
     56  }
     57
     58  void Averager::reset(void)
     59  {
     60    n_=0;
     61    x_=xx_=0.0;
     62  }
     63
     64  const Averager& Averager::operator=(const Averager& a)
     65  {
     66    n_  = a.n_;
     67    x_  = a.x_;
     68    xx_ = a.xx_;
     69    return *this;
     70  }
     71
    4572  const Averager& Averager::operator+=(const Averager& a)
    4673  {
  • trunk/yat/statistics/Averager.h

    r680 r703  
    6262    /// Adding \a n (default=1) number of data point(s) with value \a d.
    6363    ///
    64     inline void add(double d, u_long n=1) { n_+=n; x_+=n*d; xx_+=n*d*d;}
     64    void add(double d, u_long n=1);
    6565
    6666    ///
     
    9595
    9696    ///
    97     /// Rescales the object, \f$ \forall x_i \rightarrow a*x_i \f$,
     97    /// @brief Rescales the object
     98    ///
     99    /// \f$ \forall x_i \rightarrow a*x_i \f$,
    98100    /// \f$ \forall x_i^2 \rightarrow a^2*x_i^2 \f$
    99101    ///
    100     inline void rescale(double a) { x_*=a; xx_*=a*a; }
     102    inline void rescale(double a);
    101103
    102104    ///
     
    107109
    108110    ///
    109     /// The standard deviation is defined as the square root of the
    110     /// variance.
     111    /// @brief The standard deviation is defined as the square root of
     112    /// the variance.
    111113    ///
    112114    /// @return The standard deviation, root of the variance().
     
    115117
    116118    ///
    117     /// The standard deviation is defined as the square root of the
    118     /// variance.
     119    /// @brief The standard deviation is defined as the square root of
     120    /// the variance.
    119121    ///
    120122    /// @return Standard deviation around \a m, root of the variance(m).
     
    138140
    139141    ///
     142    /// @brief The variance with know mean
     143    ///
     144    /// The variance is calculated as
    140145    /// \f$ \frac{1}{n}\sum (x_i-m)^2 \f$.
    141146    ///
     
    146151
    147152    ///
     153    /// @brief The estimated variance
     154    ///
    148155    /// The variance is calculated as \f$ \frac{1}{N}\sum_i
    149156    /// (x_i-m)^2 \f$, where \f$ m \f$ is the mean.
    150157    ///
    151     /// @return estimation of variance
     158    /// @return Estimation of variance
    152159    ///
    153160    inline double variance(void) const
     
    166173
    167174    ///
    168     /// Resets everything to zero
    169     ///
    170     inline void reset(void) { n_=0; x_=xx_=0.0;}
    171 
    172     ///
    173     /// The assignment operator
    174     ///
    175     inline const Averager& operator=(const Averager& a)
    176       { n_=a.n_; x_=a.x_; xx_=a.xx_; return *this; }
     175    /// @brief Reset everything to zero
     176    ///
     177    void reset(void);
     178
     179    ///
     180    /// @brief The assignment operator
     181    ///
     182    const Averager& operator=(const Averager&);
    177183
    178184    ///
  • trunk/yat/statistics/AveragerPair.cc

    r683 r703  
    3131namespace yat {
    3232namespace statistics {
    33  
     33
     34  AveragerPair::AveragerPair(void)
     35    : x_(Averager()), y_(Averager()), xy_(0.0)
     36  {
     37  }
     38
     39  AveragerPair::AveragerPair(const AveragerPair& a)
     40    : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy())
     41  {
     42  }
     43
     44  void AveragerPair::add(const double x, const double y, const unsigned long n)
     45  {
     46    x_.add(x,n); y_.add(y,n); xy_ += n*x*y;
     47  }
     48
     49  void AveragerPair::reset(void)
     50  {
     51    x_.reset(); y_.reset(); xy_=0.0;
     52  }
     53
     54  const AveragerPair& AveragerPair::operator=(const AveragerPair& a)
     55  {
     56    x_=a.x_; y_=a.y_; xy_=a.xy_;
     57    return *this;
     58  }
     59
    3460  const AveragerPair& AveragerPair::operator+=(const AveragerPair& a)
    3561  {
  • trunk/yat/statistics/AveragerPair.h

    r680 r703  
    4545
    4646    ///
    47     /// Default constructor
     47    /// @brief The default constructor
    4848    ///
    49     inline AveragerPair(void) : x_(Averager()), y_(Averager()), xy_(0.0) {}
    50    
     49    AveragerPair(void);
     50
    5151    ///
    5252    /// Constructor taking sum of \a x , \a xx , \a y , \a yy , xy and
     
    5858
    5959    ///
    60     /// Copy constructor
     60    /// The copy constructor
    6161    ///
    62     inline AveragerPair(const AveragerPair& a)
    63       : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy()) {}
    64    
     62    AveragerPair(const AveragerPair&);
     63
    6564    ///
    6665    /// Adding \a n pairs of data points with value \a x and \a y.
    6766    ///
    68     inline void add(const double x, const double y, const unsigned long n=1)
    69       { x_.add(x,n); y_.add(y,n), xy_ += n*x*y; }
     67    void add(const double x, const double y, const unsigned long n=1);
    7068
    7169    ///
     
    131129
    132130    ///
    133     /// Resets everything to zero
     131    /// @brief Reset everything to zero
    134132    ///
    135     inline void reset(void) { x_.reset(); y_.reset(); xy_=0.0; }
     133    void reset(void);
    136134
    137135    ///
     
    156154
    157155    ///
    158     /// The assigment operator
     156    /// @brief The assigment operator
    159157    ///
    160     inline const AveragerPair& operator=(const AveragerPair& a)
    161       { x_=a.x_; y_=a.y_; xy_=a.xy_; return *this; }
     158    const AveragerPair& operator=(const AveragerPair& a);
    162159
    163160    ///
  • trunk/yat/statistics/AveragerPairWeighted.cc

    r701 r703  
    3131namespace yat {
    3232namespace statistics {
    33  
     33
     34
     35  AveragerPairWeighted::AveragerPairWeighted(void)
     36    : wxy_(0), w_(0)
     37  {
     38  }
     39
    3440
    3541  void  AveragerPairWeighted::add(const double x, const double y,
     
    6470  }
    6571
     72
     73  void AveragerPairWeighted::reset(void)
     74  {
     75    x_.reset(); y_.reset(); wxy_=0; w_=0;
     76  }
     77
    6678}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/AveragerPairWeighted.h

    r683 r703  
    5555  public:
    5656
    57     AveragerPairWeighted()
    58       : wxy_(0), w_(0)
    59     {
    60     }
     57    ///
     58    /// @brief The default constructor
     59    ///
     60    AveragerPairWeighted(void);
    6161
    6262    ///
     
    122122
    123123    ///
    124     /// reset everything to zero
     124    /// @brief Reset everything to zero
    125125    ///
    126     inline void reset(void) { x_.reset(); y_.reset(); wxy_=0; w_=0; }
     126    void reset(void);
    127127
    128128    ///
  • trunk/yat/statistics/AveragerWeighted.cc

    r683 r703  
    2828namespace statistics {
    2929
    30   AveragerWeighted AveragerWeighted::operator+=(const AveragerWeighted& a)
     30  AveragerWeighted::AveragerWeighted(void)
     31    : w_(Averager()), wx_(Averager()), wwx_(0), wxx_(0)
     32  {
     33  }
     34
     35  AveragerWeighted::AveragerWeighted(const AveragerWeighted& a)
     36    : w_(Averager(a.sum_w(),a.sum_ww(),1)),
     37      wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)),
     38      wwx_(a.sum_wwx()),
     39      wxx_(a.sum_wxx())
     40  {
     41  }
     42
     43  void AveragerWeighted::add(const double d, const double w)
     44  {
     45    if (!w)
     46      return;
     47    w_.add(w); wx_.add(w*d); wwx_+=w*w*d; wxx_+=w*d*d;
     48  }
     49
     50  void AveragerWeighted::rescale(double a)
     51  {
     52    wx_.rescale(a);
     53    wwx_*=a;
     54    wxx_*=a*a;
     55  }
     56
     57  void AveragerWeighted::reset(void)
     58  {
     59    wx_.reset(); w_.reset(); wwx_=0; wxx_=0;
     60  }
     61
     62  const AveragerWeighted& AveragerWeighted::operator+=(const AveragerWeighted& a)
    3163  {
    3264    wx_+=a.wx(); w_+=a.w(); wwx_+=a.sum_wwx(); wxx_+=a.sum_wxx();
  • trunk/yat/statistics/AveragerWeighted.h

    r699 r703  
    6565
    6666    ///
    67     /// Default constructor
     67    /// @brief The default constructor
    6868    ///
    69     inline AveragerWeighted(void)
    70       : w_(Averager()), wx_(Averager()), wwx_(0), wxx_(0) {}
    71 
    72     ///
    73     /// Copy constructor
    74     ///
    75     inline AveragerWeighted(const AveragerWeighted& a)
    76       : w_(Averager(a.sum_w(),a.sum_ww(),1)),
    77         wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)), wwx_(a.sum_wwx()),
    78         wxx_(a.sum_wxx()) {}
    79 
    80     ///
    81     /// adding a data point d, with weight w (default is 1)
    82     ///
    83     inline void add(const double d,const double w=1)
    84     { if(w==0) return; w_.add(w); wx_.add(w*d); wwx_+=w*w*d; wxx_+=w*d*d; }
     69    AveragerWeighted(void);
     70
     71    ///
     72    /// @brief The copy constructor
     73    ///
     74    AveragerWeighted(const AveragerWeighted&);
     75
     76    ///
     77    /// Adding a data point \a d, with weight \a w (default is 1)
     78    ///
     79    void  add(const double d,const double w=1);
    8580
    8681    ///
     
    9691
    9792    ///
    98     /// Calculating the weighted mean
     93    /// @brief Calculate the weighted mean
    9994    ///
    10095    /// @return \f$ \frac{\sum w_ix_i}{\sum w_i} \f$
    10196    ///
    102     inline double mean(void) const { return sum_w() ?
    103                                        sum_wx()/sum_w() : 0; }
     97    inline double mean(void) const { return sum_w() ? sum_wx()/sum_w() : 0; }
    10498
    10599    ///
     
    117111
    118112    ///
    119     /// rescale object, i.e. each data point is rescaled
    120     /// \f$ x = a * x \f$
    121     ///
    122     inline void rescale(double a) { wx_.rescale(a); wwx_*=a; wxx_*=a*a; }
    123 
    124     ///
    125     /// resets everything to zero
    126     ///
    127     inline void reset(void) { wx_.reset(); w_.reset(); wwx_=0; wxx_=0; }
    128 
    129     ///
    130     /// The standard deviation is defined as the square root of the
    131     /// variance().
     113    /// @brief Rescale object.
     114    ///
     115    /// Each data point is rescaled as \f$ x = a * x \f$
     116    ///
     117    void rescale(double a);
     118
     119    ///
     120    /// @brief Reset everything to zero.
     121    ///
     122    void reset(void);
     123
     124    ///
     125    /// @brief The standard deviation is defined as the square root of
     126    /// the variance().
    132127    ///
    133128    /// @return The standard deviation, root of the variance().
     
    136131
    137132    ///
    138     /// Calculates standard deviation of the mean(). Variance from the
     133    /// @brief Calculates standard deviation of the mean().
     134    ///
     135    /// Variance from the
    139136    /// weights are here neglected. This is true when the weight is
    140137    /// known before the measurement. In case this is not a good
     
    219216    /// operator to add a AveragerWeighted
    220217    ///
    221     AveragerWeighted operator+=(const AveragerWeighted&);
     218    const AveragerWeighted& operator+=(const AveragerWeighted&);
    222219   
    223220    Averager w_;
     
    226223    double wxx_;
    227224   
    228     inline Averager wx(void) const {return wx_;}
    229     inline Averager w(void) const {return w_;}
    230 
    231 
     225    inline Averager wx(void) const { return wx_; }
     226    inline Averager w(void) const { return w_; }
    232227  };
    233228
  • trunk/yat/statistics/Distance.cc

    r683 r703  
    3131namespace statistics{
    3232
    33   double Distance::operator()(const classifier::DataLookup1D& x,
     33  Distance::Distance(void)
     34  {
     35  }
     36
     37  Distance::~Distance(void)
     38  {
     39  }
     40
     41  double Distance::operator()(const classifier::DataLookup1D& x,
    3442                              const classifier::DataLookup1D& y) const
    3543  {
  • trunk/yat/statistics/Distance.h

    r683 r703  
    4444  public:
    4545
    46     Distance()
    47     {
    48     }
     46    ///
     47    /// @brief The default constructor
     48    ///
     49    Distance(void);
    4950
    50     virtual ~Distance()
    51     {
    52     }
     51    ///
     52    /// @brief The destructor
     53    ///
     54    virtual ~Distance(void);
    5355
    5456    ///
  • trunk/yat/statistics/Pearson.cc

    r683 r703  
    3838  Pearson::Pearson(bool b)
    3939    : Score(b), r_(0), nof_samples_(0)
     40  {
     41  }
     42
     43  Pearson::~Pearson(void)
    4044  {
    4145  }
  • trunk/yat/statistics/Pearson.h

    r683 r703  
    4343  class Pearson : public Score
    4444  {
    45  
    4645  public:
    4746    ///
    48     /// Default Constructor.
     47    /// @brief The default constructor.
    4948    ///
    5049    Pearson(bool absolute=true);
    5150
    5251    ///
    53     /// Destructor
     52    /// @brief The destructor.
    5453    ///
    55     virtual ~Pearson(void) {};
     54    virtual ~Pearson(void);
    5655         
    5756   
  • trunk/yat/statistics/PearsonDistance.cc

    r683 r703  
    3131namespace statistics{
    3232
     33  PearsonDistance::PearsonDistance(void)
     34    : Distance()
     35  {
     36  }
     37
     38  PearsonDistance::~PearsonDistance(void)
     39  {
     40  }
     41
    3342  double PearsonDistance::operator()(const utility::vector& x,
    3443                                     const utility::vector& y) const
  • trunk/yat/statistics/PearsonDistance.h

    r683 r703  
    4747  public:
    4848
    49     PearsonDistance()
    50       : Distance()
    51     {
    52     }
     49    PearsonDistance(void);
    5350
    54     virtual ~PearsonDistance()
    55     {
    56     }   
    57    
     51    virtual ~PearsonDistance(void);
     52
    5853    // Use all operator() from Distance except the ones that are
    5954    // overloaded in this class.
     
    6863                              const utility::vector& wx,
    6964                              const utility::vector& wy) const;
    70 
    71   private:
    7265  };
    7366
  • trunk/yat/statistics/ROC.cc

    r683 r703  
    3939  ROC::ROC(bool b)
    4040    : Score(b), area_(0.5), minimum_size_(10), nof_pos_(0) 
     41  {
     42  }
     43
     44  ROC::~ROC(void)
    4145  {
    4246  }
  • trunk/yat/statistics/ROC.h

    r683 r703  
    5050  public:
    5151    ///
    52     /// Default constructor
     52    /// @brief Default constructor
    5353    ///
    5454    ROC(bool absolute=true);
    5555         
    5656    ///
    57     /// Destructor
     57    /// @brief The destructor
    5858    ///
    59     virtual ~ROC(void) {};
     59    virtual ~ROC(void);
    6060         
    6161    /// Function taking \a value, \a target (+1 or -1) and vector
  • trunk/yat/statistics/SNR.h

    r683 r703  
    5454  public:
    5555    ///
    56     /// Default Constructor.
     56    /// @brief Default Constructor.
    5757    ///
    5858    SNR(bool absolute=true);
  • trunk/yat/statistics/Score.cc

    r683 r703  
    3333  }
    3434
     35  Score::~Score(void)
     36  {
     37  }
     38
     39  double Score::score(const classifier::Target& target,
     40                      const classifier::DataLookup1D& value)
     41  {
     42    assert(target.size()==value.size());
     43    utility::vector a;
     44    classifier::convert(value,a);
     45    return score(target,a);
     46  }
     47
     48  double Score::score(const classifier::Target& target,
     49                      const classifier::DataLookup1D& value,
     50                      const classifier::DataLookup1D& weight)
     51  {
     52    utility::vector a;
     53    classifier::convert(value,a);
     54    utility::vector b;
     55    classifier::convert(weight,a);
     56    return score(target,a,b);
     57  }
     58
    3559}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/Score.h

    r683 r703  
    5252  public:
    5353    ///
    54     ///   Constructor
     54    /// @brief Constructor
    5555    ///   
    5656    Score(bool absolute=true) ;
    5757   
    5858    ///
    59     ///   Destructor
     59    /// @brief Destructor
    6060    ///
    61     virtual ~Score(void) {};
     61    virtual ~Score(void);
    6262   
    6363    ///
    64     /// Function changing mode of Score
     64    /// @brief Function changing mode of Score
    6565    ///
    6666    inline void absolute(bool absolute) {absolute_=absolute;}
     
    8787    /// @param value vector of the values
    8888    ///
    89     inline double
    90     score(const classifier::Target& target,
    91           const classifier::DataLookup1D& value)
    92     {
    93       assert(target.size()==value.size());
    94       utility::vector a;
    95       classifier::convert(value,a);
    96       return score(target,a);
    97     }
     89    double score(const classifier::Target& target,
     90                 const classifier::DataLookup1D& value);
    9891 
    9992    ///
     
    127120    /// is wanted.
    128121    ///
    129     inline double
    130     score(const classifier::Target& target,
    131           const classifier::DataLookup1D& value,
    132           const classifier::DataLookup1D& weight)
    133     {
    134       utility::vector a;
    135       classifier::convert(value,a);
    136       utility::vector b;
    137       classifier::convert(weight,a);
    138       return score(target,a,b);
    139     }
     122    double score(const classifier::Target& target,
     123                 const classifier::DataLookup1D& value,
     124                 const classifier::DataLookup1D& weight);
    140125
    141126  protected:
  • trunk/yat/statistics/tScore.h

    r683 r703  
    4848  public:
    4949    ///
    50     /// Default Constructor.
     50    /// 2brief Default Constructor.
    5151    ///
    5252    tScore(bool absolute=true);
  • trunk/yat/statistics/utility.cc

    r683 r703  
    3737      p+= gsl_ran_hypergeometric_pdf(i, n1, n2, t);
    3838    return p;
     39  }
     40
     41  double kurtosis(const utility::vector& v)
     42  {
     43    const gsl_vector* gvp=v.gsl_vector_p();
     44    return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size);
    3945  }
    4046
     
    8288  }
    8389
     90  double skewness(const utility::vector& v)
     91  {
     92    const gsl_vector* gvp=v.gsl_vector_p();
     93    return gsl_stats_skew(gvp->data,gvp->stride,gvp->size);
     94  }
     95
    8496}}} // of namespace statistics, yat, and theplu
  • trunk/yat/statistics/utility.h

    r683 r703  
    4040  //forward declarations
    4141  template <class T>
    42   inline double median(const std::vector<T>& v, const bool sorted=false);
     42  double median(const std::vector<T>& v, const bool sorted=false);
    4343
    4444  template <class T>
     
    6161
    6262  ///
    63   /// Computes the kurtosis of the data in a vector. The kurtosis
    64   /// measures how sharply peaked a distribution is, relative to its
    65   /// width. The kurtosis is normalized to zero for a gaussian
    66   /// distribution.
     63  /// @brief Computes the kurtosis of the data in a vector.
    6764  ///
    68   inline double kurtosis(const utility::vector& v)
    69   {
    70     const gsl_vector* gvp=v.gsl_vector_p();
    71     return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size);
    72   }
     65  /// The kurtosis measures how sharply peaked a distribution is,
     66  /// relative to its width. The kurtosis is normalized to zero for a
     67  /// gaussian distribution.
     68  ///
     69  double kurtosis(const utility::vector&);
    7370
    7471
     
    173170
    174171  ///
    175   /// Computes the skewness of the data in a vector. The skewness
    176   /// measures the asymmetry of the tails of a distribution.
     172  /// @brief Computes the skewness of the data in a vector.
    177173  ///
    178   inline double skewness(const utility::vector& v)
    179   {
    180     const gsl_vector* gvp=v.gsl_vector_p();
    181     return gsl_stats_skew(gvp->data,gvp->stride,gvp->size);
    182   }
     174  /// The skewness measures the asymmetry of the tails of a
     175  /// distribution.
     176  ///
     177  double skewness(const utility::vector&);
    183178 
    184179}}} // of namespace statistics, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.