Ignore:
Timestamp:
Mar 5, 2007, 7:58:30 PM (15 years ago)
Author:
Peter
Message:

Refs #101

File:
1 edited

Legend:

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

    r747 r779  
    2525#include "Averager.h"
    2626#include "AveragerWeighted.h"
     27#include "yat/classifier/DataLookup1D.h"
    2728#include "yat/classifier/DataLookupWeighted1D.h"
    2829#include "yat/classifier/Target.h"
     
    3738
    3839  tScore::tScore(bool b)
    39     : Score(b),  t_(0)
     40    : Score(b)
    4041  {
    4142  }
    4243
     44
    4345  double tScore::score(const classifier::Target& target,
    44                        const utility::vector& value)
     46                       const utility::vector& value) const
    4547  {
    46     weighted_=false;
     48    return score(target, value, NULL);
     49  }
     50
     51
     52  double tScore::score(const classifier::Target& target,
     53                       const utility::vector& value,
     54                       double* dof) const
     55  {
    4756    statistics::Averager positive;
    4857    statistics::Averager negative;
     
    5362        negative.add(value(i));
    5463    }
    55     double diff = positive.mean() - negative.mean();
    56     dof_=positive.n()+negative.n()-2;
    57     double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_;
    58 
    59     t_=diff/sqrt(s2/positive.n()+s2/negative.n());
    60     if (t_<0 && absolute_)
    61       t_=-t_;
    62      
    63     return t_;
     64    return score(positive, negative, dof);
    6465  }
    6566
    6667
    6768  double tScore::score(const classifier::Target& target,
    68                        const classifier::DataLookupWeighted1D& value)
     69                       const classifier::DataLookupWeighted1D& value) const
    6970  {
    70     weighted_=true;
     71    return score(target, value, NULL);
     72  }
    7173
     74
     75  double tScore::score(const classifier::Target& target,
     76                       const classifier::DataLookupWeighted1D& value,
     77                       double* dof) const
     78  {
    7279    statistics::AveragerWeighted positive;
    7380    statistics::AveragerWeighted negative;
     
    7885        negative.add(value.data(i),value.weight(i));
    7986    }
    80     double diff = positive.mean() - negative.mean();
    81     dof_=positive.n()+negative.n()-2;
    82     double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_;
    83     t_=diff/sqrt(s2/positive.n()+s2/(negative.n()));
    84     if (t_<0 && absolute_)
    85       t_=-t_;
    86 
    87     if(positive.sum_w()==0 || negative.sum_w()==0)
    88       t_=0;
    89     return t_;
     87    return score(positive, negative, dof);
    9088  }
    9189
     
    9391  double tScore::score(const classifier::Target& target,
    9492                       const utility::vector& value,
    95                        const utility::vector& weight)
     93                       const utility::vector& weight) const
    9694  {
    97     weighted_=true;
     95    return score(target, value, weight, NULL);
     96  }
    9897
     98
     99  double tScore::score(const classifier::Target& target,
     100                       const utility::vector& value,
     101                       const utility::vector& weight,
     102                       double* dof) const
     103  {
    99104    statistics::AveragerWeighted positive;
    100105    statistics::AveragerWeighted negative;
     
    105110        negative.add(value(i),weight(i));
    106111    }
    107     double diff = positive.mean() - negative.mean();
    108     dof_=positive.n()+negative.n()-2;
    109     double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_;
    110     t_=diff/sqrt(s2/positive.n()+s2/(negative.n()));
    111     if (t_<0 && absolute_)
    112       t_=-t_;
    113 
    114     if(positive.sum_w()==0 || negative.sum_w()==0)
    115       t_=0;
    116     return t_;
    117   }
    118 
    119   double tScore::p_value(void) const
    120   {
    121     double p = gsl_cdf_tdist_Q(t_, dof_);
    122     return (dof_ > 0 && !weighted_) ? p : 1;
     112    return score(positive, negative, dof);
    123113  }
    124114
Note: See TracChangeset for help on using the changeset viewer.