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

Last change on this file since 747 was 747, checked in by Peter, 15 years ago

replaced includes in header files with forward declarations when possible. Added some includes in cc files.

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