source: trunk/yat/statistics/FoldChange.cc @ 683

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

Addresses #153. Clean up of code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1// $Id: FoldChange.cc 683 2006-10-11 22:20:36Z jari $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "FoldChange.h"
25#include "Score.h"
26#include "Averager.h"
27#include "AveragerWeighted.h"
28#include "yat/classifier/DataLookupWeighted1D.h"
29#include "yat/classifier/Target.h"
30
31namespace theplu {
32namespace yat {
33namespace statistics {
34
35  FoldChange::FoldChange(bool absolute)
36    : Score(absolute)
37  {
38  }
39
40  FoldChange::FoldChange(const FoldChange& other)
41    : Score(other)
42  {
43  }
44
45  FoldChange& FoldChange::operator=(const FoldChange& other)
46  {
47    Score::operator=(other);
48    return *this;
49  }
50
51  double FoldChange::score(const classifier::Target& target, 
52                           const utility::vector& value) 
53  {
54    weighted_=false;
55    Averager pos;
56    Averager neg;
57
58    for (size_t i=0; i<value.size(); i++) 
59      if (target.binary(i))
60        pos.add(value(i));
61      else
62        neg.add(value(i));
63         
64    if (absolute_)
65      return fabs(pos.mean()-neg.mean());
66    return pos.mean()-neg.mean();
67  }
68
69  double FoldChange::score(const classifier::Target& target, 
70                           const classifier::DataLookupWeighted1D& value) 
71  {
72    weighted_=true;
73    AveragerWeighted pos;
74    AveragerWeighted neg;
75
76    for (size_t i=0; i<value.size(); i++) 
77      if (target.binary(i))
78        pos.add(value.data(i),value.weight(i));
79      else
80        neg.add(value.data(i),value.weight(i));
81         
82    if (absolute_)
83      return fabs(pos.mean()-neg.mean());
84    return pos.mean()-neg.mean();
85  }
86
87  double FoldChange::score(const classifier::Target& target, 
88                           const utility::vector& value,
89                           const utility::vector& weight) 
90  {
91    weighted_=true;
92    AveragerWeighted pos;
93    AveragerWeighted neg;
94
95    for (size_t i=0; i<value.size(); i++) 
96      if (target.binary(i))
97        pos.add(value(i),weight(i));
98      else
99        neg.add(value(i),weight(i));
100         
101    if (absolute_)
102      return fabs(pos.mean()-neg.mean());
103    return pos.mean()-neg.mean();
104  }
105
106}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.