source: trunk/lib/statistics/FoldChange.cc @ 514

Last change on this file since 514 was 514, checked in by Peter, 17 years ago

generalised binary functionality in Target

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1// $Id: FoldChange.cc 514 2006-02-20 09:45:34Z peter $
2
3#include <c++_tools/statistics/FoldChange.h>
4#include <c++_tools/statistics/Score.h>
5#include <c++_tools/statistics/Averager.h>
6#include <c++_tools/statistics/AveragerWeighted.h>
7#include <c++_tools/classifier/Target.h>
8
9namespace theplu {
10namespace statistics {
11
12
13  FoldChange::FoldChange(bool absolute)
14    : Score(absolute)
15  {
16  }
17
18
19
20  FoldChange::FoldChange(const FoldChange& other)
21    : Score(other)
22  {
23  }
24
25
26
27  FoldChange& FoldChange::operator=(const FoldChange& other)
28  {
29    Score::operator=(other);
30    return *this;
31  }
32
33  double FoldChange::score(const classifier::Target& target, 
34                           const gslapi::vector& value) 
35  {
36    weighted_=false;
37    Averager pos;
38    Averager neg;
39
40    for (size_t i=0; i<value.size(); i++) 
41      if (target.binary(i))
42        pos.add(value(i));
43      else
44        neg.add(value(i));
45         
46    if (absolute_)
47      return fabs(pos.mean()-neg.mean());
48    return pos.mean()-neg.mean();
49  }
50
51  double FoldChange::score(const classifier::Target& target, 
52                           const gslapi::vector& value,
53                           const gslapi::vector& weight) 
54  {
55    weighted_=true;
56    AveragerWeighted pos;
57    AveragerWeighted neg;
58
59    for (size_t i=0; i<value.size(); i++) 
60      if (target.binary(i))
61        pos.add(value(i),weight(i));
62      else
63        neg.add(value(i),weight(i));
64         
65    if (absolute_)
66      return fabs(pos.mean()-neg.mean());
67    return pos.mean()-neg.mean();
68  }
69
70} // of namespace statistics
71} // of namespace theplu
Note: See TracBrowser for help on using the repository browser.