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

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

References #83. Changing project name to yat. Compilation will fail in this revision.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: FoldChange.cc 675 2006-10-10 12:08:45Z 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 "yat/statistics/FoldChange.h"
25#include "yat/statistics/Score.h"
26#include "yat/statistics/Averager.h"
27#include "yat/statistics/AveragerWeighted.h"
28#include "yat/classifier/DataLookupWeighted1D.h"
29#include "yat/classifier/Target.h"
30
31namespace theplu {
32namespace statistics {
33
34
35  FoldChange::FoldChange(bool absolute)
36    : Score(absolute)
37  {
38  }
39
40
41
42  FoldChange::FoldChange(const FoldChange& other)
43    : Score(other)
44  {
45  }
46
47
48
49  FoldChange& FoldChange::operator=(const FoldChange& other)
50  {
51    Score::operator=(other);
52    return *this;
53  }
54
55  double FoldChange::score(const classifier::Target& target, 
56                           const utility::vector& value) 
57  {
58    weighted_=false;
59    Averager pos;
60    Averager neg;
61
62    for (size_t i=0; i<value.size(); i++) 
63      if (target.binary(i))
64        pos.add(value(i));
65      else
66        neg.add(value(i));
67         
68    if (absolute_)
69      return fabs(pos.mean()-neg.mean());
70    return pos.mean()-neg.mean();
71  }
72
73  double FoldChange::score(const classifier::Target& target, 
74                           const classifier::DataLookupWeighted1D& value) 
75  {
76    weighted_=true;
77    AveragerWeighted pos;
78    AveragerWeighted neg;
79
80    for (size_t i=0; i<value.size(); i++) 
81      if (target.binary(i))
82        pos.add(value.data(i),value.weight(i));
83      else
84        neg.add(value.data(i),value.weight(i));
85         
86    if (absolute_)
87      return fabs(pos.mean()-neg.mean());
88    return pos.mean()-neg.mean();
89  }
90
91
92  double FoldChange::score(const classifier::Target& target, 
93                           const utility::vector& value,
94                           const utility::vector& weight) 
95  {
96    weighted_=true;
97    AveragerWeighted pos;
98    AveragerWeighted neg;
99
100    for (size_t i=0; i<value.size(); i++) 
101      if (target.binary(i))
102        pos.add(value(i),weight(i));
103      else
104        neg.add(value(i),weight(i));
105         
106    if (absolute_)
107      return fabs(pos.mean()-neg.mean());
108    return pos.mean()-neg.mean();
109  }
110
111} // of namespace statistics
112} // of namespace theplu
Note: See TracBrowser for help on using the repository browser.