source: trunk/c++_tools/statistics/FoldChange.cc @ 616

Last change on this file since 616 was 616, checked in by Jari Häkkinen, 15 years ago

Removed gslapi namespace and put the code into utility namespace.
Move #ifndef _header_ idiom to top of touched header files.
Removed unneccesary #includes, and added needed #includes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1// $Id: FoldChange.cc 616 2006-08-31 08:52:02Z jari $
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 utility::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 utility::vector& value,
53                           const utility::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.