source: trunk/yat/statistics/AveragerPairWeighted.cc @ 781

Last change on this file since 781 was 781, checked in by Peter, 16 years ago

changing name to ROCScore and also added some cassert includes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1// $Id: AveragerPairWeighted.cc 781 2007-03-05 19:44:03Z peter $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "AveragerPairWeighted.h"
25#include "AveragerPair.h"
26#include "Averager.h"
27#include "yat/classifier/DataLookup1D.h"
28#include "yat/classifier/DataLookupWeighted1D.h"
29
30#include <cassert>
31
32namespace theplu {
33namespace yat {
34namespace statistics {
35
36
37  AveragerPairWeighted::AveragerPairWeighted(void)
38    : wxy_(0), w_(0)
39  {
40  }
41
42
43  void  AveragerPairWeighted::add(const double x, const double y, 
44                                  const double wx, const double wy)
45  { 
46    if(wx==0.0 || wy==0.0) {
47      return;
48    }
49    double w=wx*wy;
50    x_.add(x,w);
51    y_.add(y,w); 
52    wxy_ += w*x*y;   
53    w_ +=w;
54  }
55
56
57  void AveragerPairWeighted::add(const classifier::DataLookup1D& x, 
58                                 const classifier::DataLookupWeighted1D& y)
59  {
60    assert(x.size()==y.size());
61    for (size_t i=0; i<x.size(); ++i)
62      add(x(i), y.data(i), 1.0, y.weight(i));
63  }
64
65
66  void AveragerPairWeighted::add(const classifier::DataLookupWeighted1D& x, 
67                                 const classifier::DataLookup1D& y)
68  {
69    add(y,x);
70  }
71
72
73  void AveragerPairWeighted::add(const classifier::DataLookupWeighted1D& x, 
74                                 const classifier::DataLookupWeighted1D& y)
75  {
76    assert(x.size()==y.size());
77    for (size_t i=0; i<x.size(); ++i)
78      add(x.data(i), y.data(i), x.weight(i), y.weight(i));
79  }
80
81
82  double AveragerPairWeighted::correlation(void) const
83  {
84    return covariance() / ( x_.std()*y_.std() );
85  }
86
87
88  double AveragerPairWeighted::covariance(void) const
89  {
90    return sum_xy_centered()/sum_w();
91  }
92
93
94  double AveragerPairWeighted::msd(void) const
95  {
96    return ( x_.sum_wxx()+y_.sum_wxx()-2*wxy_)/w_;
97  }
98
99
100  void AveragerPairWeighted::reset(void)
101  {
102    x_.reset(); y_.reset(); wxy_=0; w_=0;
103  }
104
105  double AveragerPairWeighted::sum_w(void) const
106  {
107    return w_;
108  }
109
110
111  double AveragerPairWeighted::sum_xy(void) const
112  {
113    return wxy_;
114  }
115
116
117  double AveragerPairWeighted::sum_xy_centered(void) const
118  {
119    return sum_xy() - x_.sum_wx()*y_.mean();
120  }
121
122
123  const AveragerWeighted& AveragerPairWeighted::x_averager(void) const
124  {
125    return x_;
126  }
127
128
129  const AveragerWeighted& AveragerPairWeighted::y_averager(void) const
130  {
131    return y_;
132  }
133
134}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.