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

Last change on this file since 899 was 899, checked in by Peter, 14 years ago

changed euclidean to fulfill design criteria, removes sum_squared_deviation from AveragerPairWeighted?, also changed vector::sort to use stl rather than gsl. refs #248 and fixes #253

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