source: branches/peters_vector/lib/statistics/FoldChange.cc @ 469

Last change on this file since 469 was 469, checked in by Peter, 16 years ago

non compiling checking before revision after design meeting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1// $Id: FoldChange.cc 469 2005-12-19 14:58:29Z 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 classifier::VectorAbstract& value) 
35  {
36    weighted_=false;
37    Averager pos;
38    Averager neg;
39
40    for (size_t i=0; i<value.size(); i++) 
41      if (class_one(target(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 classifier::VectorAbstract& value,
53                           const classifier::VectorAbstract& weight) 
54  {
55    weighted_=true;
56    AveragerWeighted pos;
57    AveragerWeighted neg;
58
59    for (size_t i=0; i<value.size(); i++) 
60      if (class_one(target(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.