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

Last change on this file since 865 was 865, checked in by Peter, 14 years ago

changing URL to http://trac.thep.lu.se/trac/yat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: FoldChange.cc 865 2007-09-10 19:41:04Z peter $
2
3/*
4  Copyright (C) 2005 Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2007 Peter Johansson
7
8  This file is part of the yat library, http://trac.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
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/vector.h"
33
34namespace theplu {
35namespace yat {
36namespace statistics {
37
38  FoldChange::FoldChange(bool absolute)
39    : Score(absolute)
40  {
41  }
42
43  double FoldChange::score(const classifier::Target& target, 
44                           const utility::vector& value) const
45  {
46    Averager pos;
47    Averager neg;
48
49    for (size_t i=0; i<value.size(); i++) 
50      if (target.binary(i))
51        pos.add(value(i));
52      else
53        neg.add(value(i));
54         
55    if (absolute_)
56      return fabs(pos.mean()-neg.mean());
57    return pos.mean()-neg.mean();
58  }
59
60  double FoldChange::score(const classifier::Target& target, 
61                           const classifier::DataLookupWeighted1D& value) const
62  {
63    AveragerWeighted pos;
64    AveragerWeighted neg;
65
66    for (size_t i=0; i<value.size(); i++) 
67      if (target.binary(i))
68        pos.add(value.data(i),value.weight(i));
69      else
70        neg.add(value.data(i),value.weight(i));
71         
72    if (absolute_)
73      return fabs(pos.mean()-neg.mean());
74    return pos.mean()-neg.mean();
75  }
76
77  double FoldChange::score(const classifier::Target& target, 
78                           const utility::vector& value,
79                           const utility::vector& weight) const
80  {
81    AveragerWeighted pos;
82    AveragerWeighted neg;
83
84    for (size_t i=0; i<value.size(); i++) 
85      if (target.binary(i))
86        pos.add(value(i),weight(i));
87      else
88        neg.add(value(i),weight(i));
89         
90    if (absolute_)
91      return fabs(pos.mean()-neg.mean());
92    return pos.mean()-neg.mean();
93  }
94
95}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.