source: trunk/yat/statistics/SNRScore.cc @ 1381

Last change on this file since 1381 was 1275, checked in by Jari Häkkinen, 14 years ago

Updating copyright statements.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: SNRScore.cc 1275 2008-04-11 06:10:12Z jari $
2
3/*
4  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
5  Copyright (C) 2008 Peter Johansson
6
7  This file is part of the yat library, http://trac.thep.lu.se/yat
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version.
13
14  The yat library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "SNRScore.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/VectorBase.h"
31
32#include <cassert>
33
34namespace theplu {
35namespace yat {
36namespace statistics { 
37
38  SNRScore::SNRScore(bool b) 
39    : Score(b)
40  {
41  }
42
43  SNRScore::~SNRScore(void)
44  {
45  }
46
47  double SNRScore::score(const classifier::Target& target, 
48                         const utility::VectorBase& value) const
49  {
50    statistics::Averager positive;
51    statistics::Averager negative;
52    for(size_t i=0; i<target.size(); i++){
53      if (target.binary(i))
54        positive.add(value(i));
55      else
56        negative.add(value(i));
57    }
58    double diff = positive.mean() - negative.mean();
59    double denom=positive.std()+negative.std();
60    double snr=diff/denom;
61    if(positive.n()==0 || negative.n()==0) 
62      snr=0;
63    if (snr<0 && absolute_)
64      snr=-snr;   
65    return snr;
66  }
67
68  double SNRScore::score(const classifier::Target& target, 
69                         const classifier::DataLookupWeighted1D& value) const
70  {
71    statistics::AveragerWeighted positive;
72    statistics::AveragerWeighted negative;
73    for(size_t i=0; i<target.size(); i++){
74      if (target.binary(i))
75        positive.add(value.data(i),value.weight(i));
76      else
77        negative.add(value.data(i),value.weight(i));
78    }
79    double diff = positive.mean() - negative.mean();
80    double denom=positive.std()+negative.std();
81    assert(denom);
82    double snr=diff/denom;
83    if(positive.sum_w()==0 || negative.sum_w()==0) 
84      snr=0;
85    if (snr<0 && absolute_)
86      snr=-snr;   
87    return snr;
88  }
89
90
91
92  double SNRScore::score(const classifier::Target& target, 
93                    const utility::VectorBase& value,
94                    const utility::VectorBase& weight) const
95  {
96    statistics::AveragerWeighted positive;
97    statistics::AveragerWeighted negative;
98    for(size_t i=0; i<target.size(); i++){
99      if (target.binary(i))
100        positive.add(value(i),weight(i));
101      else
102        negative.add(value(i),weight(i));
103    }
104    double diff = positive.mean() - negative.mean();
105    double denom=positive.std()+negative.std();
106    assert(denom);
107    double snr=diff/denom;
108    if(positive.sum_w()==0 || negative.sum_w()==0) 
109      snr=0;
110    if (snr<0 && absolute_)
111      snr=-snr;   
112    return snr;
113  }
114
115}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.