yat/statistics/Averager.cc

Code
Comments
Other
Rev Date Author Line
87 27 May 04 peter 1 // $Id$
87 27 May 04 peter 2
675 10 Oct 06 jari 3 /*
2119 12 Dec 09 peter 4   Copyright (C) 2004 Jari Häkkinen, Peter Johansson
1746 23 Jan 09 peter 5   Copyright (C) 2005 Peter Johansson
2119 12 Dec 09 peter 6   Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
4359 23 Aug 23 peter 7   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
2798 27 Jul 12 peter 9   Copyright (C) 2011, 2012 Peter Johansson
137 19 Aug 04 peter 10
1437 25 Aug 08 peter 11   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 12
675 10 Oct 06 jari 13   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 14   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 15   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 16   License, or (at your option) any later version.
675 10 Oct 06 jari 17
675 10 Oct 06 jari 18   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 19   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 21   General Public License for more details.
675 10 Oct 06 jari 22
675 10 Oct 06 jari 23   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 24   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 25 */
675 10 Oct 06 jari 26
2881 18 Nov 12 peter 27 #include <config.h>
2881 18 Nov 12 peter 28
680 11 Oct 06 jari 29 #include "Averager.h"
675 10 Oct 06 jari 30
916 30 Sep 07 peter 31 #include <cassert>
2560 24 Sep 11 peter 32 #include <cmath>
1122 22 Feb 08 peter 33 #include <limits>
916 30 Sep 07 peter 34
87 27 May 04 peter 35 namespace theplu {
680 11 Oct 06 jari 36 namespace yat {
680 11 Oct 06 jari 37 namespace statistics {
680 11 Oct 06 jari 38
620 04 Sep 06 markus 39   Averager::Averager(void)
620 04 Sep 06 markus 40   {
620 04 Sep 06 markus 41   }
87 27 May 04 peter 42
2558 24 Sep 11 peter 43
1295 12 May 08 jari 44   Averager::Averager(double x, double xx, long n)
620 04 Sep 06 markus 45   {
2809 06 Aug 12 peter 46     n_ = n;
2809 06 Aug 12 peter 47     mean_ = x/n;
2809 06 Aug 12 peter 48     cm2_ = xx-x*x/n;
620 04 Sep 06 markus 49   }
680 11 Oct 06 jari 50
2558 24 Sep 11 peter 51
620 04 Sep 06 markus 52   Averager::Averager(const Averager& a)
2809 06 Aug 12 peter 53     : averager_base2<Averager>(a)
620 04 Sep 06 markus 54   {
620 04 Sep 06 markus 55   }
680 11 Oct 06 jari 56
2558 24 Sep 11 peter 57
2809 06 Aug 12 peter 58   void Averager::add_impl(double d, long n)
703 18 Dec 06 jari 59   {
2809 06 Aug 12 peter 60     if (n==1)
2809 06 Aug 12 peter 61       add2(d - this->mean_);
2809 06 Aug 12 peter 62     else
2809 06 Aug 12 peter 63       add2(d, 0, n);
1297 13 May 08 jari 64     assert(n_>-1);
703 18 Dec 06 jari 65   }
703 18 Dec 06 jari 66
718 26 Dec 06 jari 67
703 18 Dec 06 jari 68   const Averager& Averager::operator=(const Averager& a)
703 18 Dec 06 jari 69   {
2558 24 Sep 11 peter 70     if (this != &a) { // avoid self-assignment
2558 24 Sep 11 peter 71       n_  = a.n_;
2558 24 Sep 11 peter 72       mean_  = a.mean_;
2809 06 Aug 12 peter 73       cm2_ = a.cm2_;
2558 24 Sep 11 peter 74     }
703 18 Dec 06 jari 75     return *this;
703 18 Dec 06 jari 76   }
703 18 Dec 06 jari 77
2809 06 Aug 12 peter 78
2809 06 Aug 12 peter 79   void Averager::rescale_impl(double x)
87 27 May 04 peter 80   {
2809 06 Aug 12 peter 81     this->rescale2(x);
87 27 May 04 peter 82   }
87 27 May 04 peter 83
2809 06 Aug 12 peter 84
680 11 Oct 06 jari 85 }}} // of namespace statistics, yat, and theplu