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

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

Addresses #153. Introduced yat namespace. Removed alignment namespace. 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 680 2006-10-11 17:49:03Z 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
36  FoldChange::FoldChange(bool absolute)
37    : Score(absolute)
38  {
39  }
40
41
42
43  FoldChange::FoldChange(const FoldChange& other)
44    : Score(other)
45  {
46  }
47
48
49
50  FoldChange& FoldChange::operator=(const FoldChange& other)
51  {
52    Score::operator=(other);
53    return *this;
54  }
55
56  double FoldChange::score(const classifier::Target& target, 
57                           const utility::vector& value) 
58  {
59    weighted_=false;
60    Averager pos;
61    Averager neg;
62
63    for (size_t i=0; i<value.size(); i++) 
64      if (target.binary(i))
65        pos.add(value(i));
66      else
67        neg.add(value(i));
68         
69    if (absolute_)
70      return fabs(pos.mean()-neg.mean());
71    return pos.mean()-neg.mean();
72  }
73
74  double FoldChange::score(const classifier::Target& target, 
75                           const classifier::DataLookupWeighted1D& value) 
76  {
77    weighted_=true;
78    AveragerWeighted pos;
79    AveragerWeighted neg;
80
81    for (size_t i=0; i<value.size(); i++) 
82      if (target.binary(i))
83        pos.add(value.data(i),value.weight(i));
84      else
85        neg.add(value.data(i),value.weight(i));
86         
87    if (absolute_)
88      return fabs(pos.mean()-neg.mean());
89    return pos.mean()-neg.mean();
90  }
91
92
93  double FoldChange::score(const classifier::Target& target, 
94                           const utility::vector& value,
95                           const utility::vector& weight) 
96  {
97    weighted_=true;
98    AveragerWeighted pos;
99    AveragerWeighted neg;
100
101    for (size_t i=0; i<value.size(); i++) 
102      if (target.binary(i))
103        pos.add(value(i),weight(i));
104      else
105        neg.add(value(i),weight(i));
106         
107    if (absolute_)
108      return fabs(pos.mean()-neg.mean());
109    return pos.mean()-neg.mean();
110  }
111
112}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.