Changeset 1122


Ignore:
Timestamp:
Feb 22, 2008, 6:01:15 PM (16 years ago)
Author:
Peter
Message:

refs #335 - Changed so Averager classes are consistently returning NaN when Averager is empty or for some other reason the estimation ends up with things like zero by zero division. Previously zero was returned from some functions and Nan from some functions. I did not change anythuing in NCC.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r1119 r1122  
    3333  ensemble_test feature_selection_test fileutil_test \
    3434  index_test inputranker_test \
    35   iterator_test kernel_test kernel_lookup_test \
    36   knn_test matrix_test matrix_lookup_test \
     35  iterator_test kernel_lookup_test kernel_test \
     36  knn_test matrix_lookup_test matrix_test \
    3737  nbc_test \
    3838  ncc_test nni_test pca_test regression_test rnd_test roc_test \
  • trunk/yat/statistics/Averager.cc

    r1000 r1122  
    2626
    2727#include <cassert>
     28#include <limits>
    2829
    2930namespace theplu {
     
    5657  double Averager::cv(void) const
    5758  {
    58     return x_ ? std()/mean() : 0;
     59    return std()/mean();
    5960  }
    6061
    6162  double Averager::mean(void) const
    6263  {
    63     return n_ ? x_/n_ : 0;
     64    return x_/n_;
    6465  }
    6566
     
    113114  double Averager::variance(double m) const
    114115  {
    115     return n_ ? (xx_ - 2*m*x_ + m*m*n()) /n_ : 0;
     116    return (xx_ - 2*m*x_ + m*m*n()) /n_;
    116117  }
    117118
    118119  double Averager::variance(void) const
    119120  {
    120     return n_>1 ? sum_xx_centered()/n_ : 0;
     121    return sum_xx_centered()/n_;
    121122  }
    122123
    123124  double Averager::variance_unbiased(void) const
    124125  {
    125     return (n_>1) ? sum_xx_centered()/(n_-1) : 0;
     126    return (n_>1) ? sum_xx_centered()/(n_-1) :
     127      std::numeric_limits<double>::quiet_NaN();
    126128  }
    127129
  • trunk/yat/statistics/Averager.h

    r1000 r1122  
    143143    double variance(double m) const;
    144144
    145     ///
    146     /// @brief The estimated variance
    147     ///
    148     /// The variance is calculated as \f$ \frac{1}{N}\sum_i
    149     /// (x_i-m)^2 \f$, where \f$ m \f$ is the mean.
    150     ///
    151     /// @return Estimation of variance
    152     ///
     145    /**
     146       \brief The estimated variance
     147       
     148      The variance is calculated as \f$ \frac{1}{N}\sum_i
     149      (x_i-m)^2 \f$, where \f$ m \f$ is the mean.
     150       
     151       \return Estimation of variance
     152    */
    153153    double variance(void) const;
    154154
  • trunk/yat/statistics/AveragerPair.cc

    r1000 r1122  
    5151  double AveragerPair::ccc(void) const
    5252  {
    53     return ( (x_.variance() && y_.variance() && (x_.mean()-y_.mean()) ) ?
    54              ((2*covariance()) /
    55               ((x_.variance()+y_.variance()) +
    56                (x_.mean()-y_.mean())*(x_.mean()-y_.mean()))) : 0);
     53    return ((2*covariance()) /
     54            ((x_.variance()+y_.variance()) +
     55             (x_.mean()-y_.mean())*(x_.mean()-y_.mean())));
    5756  }
    5857
    5958  double AveragerPair::correlation(void) const
    60   { return ((x_.std()>0 && y_.std()>0) ?
    61             (covariance() / (x_.std()*y_.std()) ) : 0);
     59  { return covariance() / std::sqrt(x_.variance()*y_.variance());
    6260  }
    6361
    6462  double AveragerPair::covariance(void) const
    6563  {
    66     return (n()>1) ? (xy_ - x_.sum_x()*y_.mean()) / n(): 0;
     64    return (xy_ - x_.sum_x()*y_.mean()) / n();
    6765  }
    6866
  • trunk/yat/statistics/AveragerPair.h

    r1043 r1122  
    7373       \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sum_i
    7474       (x_i-m_x)^2+\sum_i (y_i-m_y)^2 + n(m_x-m_y)^2} \f$
    75        
    76        In case of a zero denominator - zero is returned.
    7775       
    7876       @return Concordence correlation coefficient.
  • trunk/yat/statistics/AveragerPairWeighted.cc

    r1043 r1122  
    2727#include "AveragerPair.h"
    2828#include "Averager.h"
    29 #include "yat/classifier/DataLookup1D.h"
    30 #include "yat/classifier/DataLookupWeighted1D.h"
    3129
    3230#include <cassert>
     
    6361  double AveragerPairWeighted::correlation(void) const
    6462  {
    65     return ( x_.variance()>0 && y_.variance()>0 ?
    66              covariance() / sqrt(x_.variance()*y_.variance()) : 0 );
     63    return covariance() / sqrt(x_.variance()*y_.variance());
    6764  }
    6865
  • trunk/yat/statistics/AveragerPairWeighted.h

    r1088 r1122  
    3737namespace theplu{
    3838namespace yat{
    39 namespace classifier{
    40   class DataLookup1D;
    41   class DataLookupWeighted1D;
    42 }
    4339namespace statistics{
    4440  ///
  • trunk/yat/statistics/AveragerWeighted.cc

    r1000 r1122  
    5252  double AveragerWeighted::mean(void) const
    5353  {
    54     return sum_w() ? sum_wx()/sum_w() : 0;
     54    return sum_wx()/sum_w();
    5555  }
    5656
Note: See TracChangeset for help on using the changeset viewer.