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