Ignore:
Timestamp:
Mar 19, 2007, 12:44:09 AM (15 years ago)
Author:
Peter
Message:

redesigned tTest fixes #212 and #156

File:
1 edited

Legend:

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

    r779 r822  
    2323
    2424#include "tTest.h"
     25#include "AveragerWeighted.h"
    2526#include "tScore.h"
    26 //#include "Averager.h"
    27 //#include "AveragerWeighted.h"
    28 //#include "yat/classifier/DataLookupWeighted1D.h"
    29 //#include "yat/classifier/Target.h"
    30 //#include "yat/utility/vector.h"
    3127
     28#include <algorithm>
    3229#include <cassert>
    3330#include <cmath>
     
    3734namespace statistics { 
    3835
    39   tTest::tTest(bool b)
    40     : t_(0)
     36  tTest::tTest(void)
     37    : updated_(false)
    4138  {
    4239  }
    4340
    44   double tTest::score(const classifier::Target& target,
    45                       const utility::vector& value)
     41 
     42  void tTest::add(double x, bool target, double w)
    4643  {
    47     tScore score;
    48     t_ = score.score(target, value, &dof_);
     44    if (!w)
     45      return;
     46    if (target)
     47      pos_.add(x,w);
     48    else
     49      neg_.add(x,w);
     50    updated_=false;
     51  }
     52
     53  double tTest::score(void)
     54  {
     55    if (!updated_){
     56      tScore score(false);
     57      t_ = score.score(pos_, neg_, &dof_);
     58      updated_=true;
     59    }
    4960    return t_;
    5061  }
    5162
    5263
    53   double tTest::score(const classifier::Target& target,
    54                       const classifier::DataLookupWeighted1D& value)
     64  double tTest::p_value(void) const
    5565  {
    56     tScore score;
    57     t_ = score.score(target, value, &dof_);
    58     return t_;
     66    double p=2*p_value_one_sided();
     67    return std::min(p,2-p);
    5968  }
    6069
    6170
    62   double tTest::score(const classifier::Target& target,
    63                       const utility::vector& value,
    64                       const utility::vector& weight)
     71  double tTest::p_value_one_sided(void) const
    6572  {
    66     tScore score;
    67     t_ = score.score(target, value, weight, &dof_);
    68     return t_;
    69   }
    70 
    71   double tTest::p_value(void) const
    72   {
    73     if (!dof_)
     73    double t=t_;
     74    double dof=dof_;
     75    if (!updated_){
     76      tScore score(false);
     77      t = score.score(pos_, neg_, &dof);
     78    }
     79    if (!dof)
    7480      return 1.0;
    75     return gsl_cdf_tdist_Q(t_, dof_);
     81    return gsl_cdf_tdist_Q(t, dof);
    7682  }
    7783
Note: See TracChangeset for help on using the changeset viewer.