Ignore:
Timestamp:
Sep 5, 2006, 4:13:12 AM (16 years ago)
Author:
Peter
Message:

fixes #112 and refs #123 added overloaded function score taking Target and DataLookupWeighted1D, which is needed for InputRanker?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/statistics/tScore.cc

    r616 r623  
    11// $Id$
    22
    3 // System includes
     3#include "c++_tools/statistics/tScore.h"
     4#include "c++_tools/statistics/Averager.h"
     5#include "c++_tools/statistics/AveragerWeighted.h"
     6#include "c++_tools/classifier/DataLookupWeighted1D.h"
     7#include "c++_tools/classifier/Target.h"
     8
    49#include <cassert>
    510#include <cmath>
    611
    7 // Thep C++ Tools
    8 #include <c++_tools/statistics/tScore.h>
    9 #include <c++_tools/statistics/Averager.h>
    10 #include <c++_tools/statistics/AveragerWeighted.h>
    11 #include <c++_tools/classifier/Target.h>
    1212
    1313namespace theplu {
     
    4141    return t_;
    4242  }
     43
     44
     45  double tScore::score(const classifier::Target& target,
     46                       const classifier::DataLookupWeighted1D& value)
     47  {
     48    weighted_=true;
     49
     50    statistics::AveragerWeighted positive;
     51    statistics::AveragerWeighted negative;
     52    for(size_t i=0; i<target.size(); i++){
     53      if (target.binary(i))
     54        positive.add(value.data(i),value.weight(i));
     55      else
     56        negative.add(value.data(i),value.weight(i));
     57    }
     58    double diff = positive.mean() - negative.mean();
     59    dof_=positive.n()+negative.n()-2;
     60    double s2=(positive.sum_xx_centered()+negative.sum_xx_centered())/dof_;
     61    t_=diff/sqrt(s2/positive.n()+s2/(negative.n()));
     62    if (t_<0 && absolute_)
     63      t_=-t_;
     64
     65    if(positive.sum_w()==0 || negative.sum_w()==0)
     66      t_=0;
     67    return t_;
     68  }
     69
    4370
    4471  double tScore::score(const classifier::Target& target,
Note: See TracChangeset for help on using the changeset viewer.