source: trunk/yat/statistics/tScore.cc @ 1701

Last change on this file since 1701 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • 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 1487 2008-09-10 08:41:36Z jari $
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 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 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 "tScore.h"
27#include "Averager.h"
28#include "AveragerWeighted.h"
29#include "yat/classifier/DataLookup1D.h"
30#include "yat/classifier/DataLookupWeighted1D.h"
31#include "yat/classifier/Target.h"
32#include "yat/utility/VectorBase.h"
33
34#include <cassert>
35#include <cmath>
36
37namespace theplu {
38namespace yat {
39namespace statistics { 
40
41  tScore::tScore(bool b) 
42    : Score(b)
43  {
44  }
45
46
47  double tScore::score(const classifier::Target& target, 
48                       const utility::VectorBase& value) const
49  {
50    return score(target, value, NULL);
51  }
52
53
54  double tScore::score(const classifier::Target& target, 
55                       const utility::VectorBase& value,
56                       double* dof) const
57  {
58    statistics::Averager positive;
59    statistics::Averager negative;
60    for(size_t i=0; i<target.size(); i++){
61      if (target.binary(i))
62        positive.add(value(i));
63      else
64        negative.add(value(i));
65    }
66    return score(positive, negative, dof);
67  }
68
69
70  double tScore::score(const classifier::Target& target, 
71                       const classifier::DataLookupWeighted1D& value) const
72  {
73    return score(target, value, NULL);
74  }
75
76
77  double tScore::score(const classifier::Target& target, 
78                       const classifier::DataLookupWeighted1D& value,
79                       double* dof) const
80  {
81    statistics::AveragerWeighted positive;
82    statistics::AveragerWeighted negative;
83    for(size_t i=0; i<target.size(); i++){
84      if (target.binary(i))
85        positive.add(value.data(i),value.weight(i));
86      else
87        negative.add(value.data(i),value.weight(i));
88    }
89    return score(positive, negative, dof);
90  }
91
92
93  double tScore::score(const classifier::Target& target, 
94                       const utility::VectorBase& value,
95                       const utility::VectorBase& weight) const
96  {
97    return score(target, value, weight, NULL);
98  }
99
100
101  double tScore::score(const classifier::Target& target, 
102                       const utility::VectorBase& value,
103                       const utility::VectorBase& weight,
104                       double* dof) const
105  {
106    statistics::AveragerWeighted positive;
107    statistics::AveragerWeighted negative;
108    for(size_t i=0; i<target.size(); i++){
109      if (target.binary(i))
110        positive.add(value(i),weight(i));
111      else
112        negative.add(value(i),weight(i));
113    }
114    return score(positive, negative, dof);
115  }
116
117}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.