669 |
07 Oct 06 |
peter |
// $Id$ |
669 |
07 Oct 06 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
669 |
07 Oct 06 |
peter |
8 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
10 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
15 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
20 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
23 |
*/ |
675 |
10 Oct 06 |
jari |
24 |
|
2881 |
18 Nov 12 |
peter |
25 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
26 |
|
779 |
05 Mar 07 |
peter |
27 |
#include "SAMScore.h" |
680 |
11 Oct 06 |
jari |
28 |
#include "Averager.h" |
680 |
11 Oct 06 |
jari |
29 |
#include "AveragerWeighted.h" |
675 |
10 Oct 06 |
jari |
30 |
#include "yat/classifier/DataLookupWeighted1D.h" |
675 |
10 Oct 06 |
jari |
31 |
#include "yat/classifier/Target.h" |
1023 |
01 Feb 08 |
peter |
32 |
#include "yat/utility/VectorBase.h" |
675 |
10 Oct 06 |
jari |
33 |
|
669 |
07 Oct 06 |
peter |
34 |
#include <cmath> |
669 |
07 Oct 06 |
peter |
35 |
|
669 |
07 Oct 06 |
peter |
36 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
37 |
namespace yat { |
4200 |
19 Aug 22 |
peter |
38 |
namespace statistics { |
669 |
07 Oct 06 |
peter |
39 |
|
4200 |
19 Aug 22 |
peter |
40 |
SAMScore::SAMScore(const double s0, bool b) |
669 |
07 Oct 06 |
peter |
41 |
: Score(b), s0_(s0) |
669 |
07 Oct 06 |
peter |
42 |
{ |
669 |
07 Oct 06 |
peter |
43 |
} |
669 |
07 Oct 06 |
peter |
44 |
|
4200 |
19 Aug 22 |
peter |
45 |
double SAMScore::score(const classifier::Target& target, |
1023 |
01 Feb 08 |
peter |
46 |
const utility::VectorBase& value) const |
669 |
07 Oct 06 |
peter |
47 |
{ |
669 |
07 Oct 06 |
peter |
48 |
statistics::Averager positive; |
669 |
07 Oct 06 |
peter |
49 |
statistics::Averager negative; |
669 |
07 Oct 06 |
peter |
50 |
for(size_t i=0; i<target.size(); i++){ |
669 |
07 Oct 06 |
peter |
51 |
if (target.binary(i)) |
669 |
07 Oct 06 |
peter |
52 |
positive.add(value(i)); |
669 |
07 Oct 06 |
peter |
53 |
else |
669 |
07 Oct 06 |
peter |
54 |
negative.add(value(i)); |
669 |
07 Oct 06 |
peter |
55 |
} |
779 |
05 Mar 07 |
peter |
56 |
return score(positive, negative); |
669 |
07 Oct 06 |
peter |
57 |
} |
669 |
07 Oct 06 |
peter |
58 |
|
4200 |
19 Aug 22 |
peter |
59 |
double SAMScore::score(const classifier::Target& target, |
779 |
05 Mar 07 |
peter |
60 |
const classifier::DataLookupWeighted1D& value) const |
669 |
07 Oct 06 |
peter |
61 |
{ |
669 |
07 Oct 06 |
peter |
62 |
statistics::AveragerWeighted positive; |
669 |
07 Oct 06 |
peter |
63 |
statistics::AveragerWeighted negative; |
669 |
07 Oct 06 |
peter |
64 |
for(size_t i=0; i<target.size(); i++){ |
669 |
07 Oct 06 |
peter |
65 |
if (target.binary(i)) |
669 |
07 Oct 06 |
peter |
66 |
positive.add(value.data(i),value.weight(i)); |
669 |
07 Oct 06 |
peter |
67 |
else |
669 |
07 Oct 06 |
peter |
68 |
negative.add(value.data(i),value.weight(i)); |
669 |
07 Oct 06 |
peter |
69 |
} |
779 |
05 Mar 07 |
peter |
70 |
return score(positive, negative); |
669 |
07 Oct 06 |
peter |
71 |
} |
669 |
07 Oct 06 |
peter |
72 |
|
669 |
07 Oct 06 |
peter |
73 |
|
669 |
07 Oct 06 |
peter |
74 |
|
4200 |
19 Aug 22 |
peter |
75 |
double SAMScore::score(const classifier::Target& target, |
1023 |
01 Feb 08 |
peter |
76 |
const utility::VectorBase& value, |
1023 |
01 Feb 08 |
peter |
77 |
const utility::VectorBase& weight) const |
669 |
07 Oct 06 |
peter |
78 |
{ |
669 |
07 Oct 06 |
peter |
79 |
statistics::AveragerWeighted positive; |
669 |
07 Oct 06 |
peter |
80 |
statistics::AveragerWeighted negative; |
669 |
07 Oct 06 |
peter |
81 |
for(size_t i=0; i<target.size(); i++){ |
669 |
07 Oct 06 |
peter |
82 |
if (target.binary(i)) |
669 |
07 Oct 06 |
peter |
83 |
positive.add(value(i),weight(i)); |
669 |
07 Oct 06 |
peter |
84 |
else |
669 |
07 Oct 06 |
peter |
85 |
negative.add(value(i),weight(i)); |
669 |
07 Oct 06 |
peter |
86 |
} |
779 |
05 Mar 07 |
peter |
87 |
return score(positive, negative); |
669 |
07 Oct 06 |
peter |
88 |
} |
669 |
07 Oct 06 |
peter |
89 |
|
683 |
11 Oct 06 |
jari |
90 |
}}} // of namespace statistics, yat, and theplu |