source: trunk/yat/statistics/FoldChange.cc

Last change on this file was 2919, checked in by Peter, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: FoldChange.cc 2919 2012-12-19 06:54:23Z peter $
2
3/*
4  Copyright (C) 2005 Peter Johansson
5  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2012 Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include <config.h>
25
26#include "FoldChange.h"
27#include "Score.h"
28#include "Averager.h"
29#include "AveragerWeighted.h"
30#include "yat/classifier/DataLookupWeighted1D.h"
31#include "yat/classifier/Target.h"
32#include "yat/utility/VectorBase.h"
33
34#include <cmath>
35
36namespace theplu {
37namespace yat {
38namespace statistics {
39
40  FoldChange::FoldChange(bool absolute)
41    : Score(absolute)
42  {
43  }
44
45  double FoldChange::score(const classifier::Target& target, 
46                           const utility::VectorBase& value) const
47  {
48    Averager pos;
49    Averager neg;
50
51    for (size_t i=0; i<value.size(); i++) 
52      if (target.binary(i))
53        pos.add(value(i));
54      else
55        neg.add(value(i));
56         
57    if (absolute_)
58      return std::abs(pos.mean()-neg.mean());
59    return pos.mean()-neg.mean();
60  }
61
62  double FoldChange::score(const classifier::Target& target, 
63                           const classifier::DataLookupWeighted1D& value) const
64  {
65    AveragerWeighted pos;
66    AveragerWeighted neg;
67
68    for (size_t i=0; i<value.size(); i++) 
69      if (target.binary(i))
70        pos.add(value.data(i),value.weight(i));
71      else
72        neg.add(value.data(i),value.weight(i));
73         
74    if (absolute_)
75      return std::abs(pos.mean()-neg.mean());
76    return pos.mean()-neg.mean();
77  }
78
79  double FoldChange::score(const classifier::Target& target, 
80                           const utility::VectorBase& value,
81                           const utility::VectorBase& weight) const
82  {
83    AveragerWeighted pos;
84    AveragerWeighted neg;
85
86    for (size_t i=0; i<value.size(); i++) 
87      if (target.binary(i))
88        pos.add(value(i),weight(i));
89      else
90        neg.add(value(i),weight(i));
91         
92    if (absolute_)
93      return std::abs(pos.mean()-neg.mean());
94    return pos.mean()-neg.mean();
95  }
96
97}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.