yat/statistics/TukeyBiweightEstimator.cc

Code
Comments
Other
Rev Date Author Line
3917 31 May 20 peter 1 // $Id$
3917 31 May 20 peter 2
3917 31 May 20 peter 3 /*
3917 31 May 20 peter 4   Copyright (C) 2020 Peter Johansson
3917 31 May 20 peter 5
3917 31 May 20 peter 6   This file is part of the yat library, http://dev.thep.lu.se/yat
3917 31 May 20 peter 7
3917 31 May 20 peter 8   The yat library is free software; you can redistribute it and/or
3917 31 May 20 peter 9   modify it under the terms of the GNU General Public License as
3917 31 May 20 peter 10   published by the Free Software Foundation; either version 3 of the
3917 31 May 20 peter 11   License, or (at your option) any later version.
3917 31 May 20 peter 12
3917 31 May 20 peter 13   The yat library is distributed in the hope that it will be useful,
3917 31 May 20 peter 14   but WITHOUT ANY WARRANTY; without even the implied warranty of
3917 31 May 20 peter 15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3917 31 May 20 peter 16   General Public License for more details.
3917 31 May 20 peter 17
3917 31 May 20 peter 18   You should have received a copy of the GNU General Public License
3917 31 May 20 peter 19   along with yat. If not, see <http://www.gnu.org/licenses/>.
3917 31 May 20 peter 20 */
3917 31 May 20 peter 21
3926 05 Jul 20 peter 22 #include <config.h>
3926 05 Jul 20 peter 23
3917 31 May 20 peter 24 #include "TukeyBiweightEstimator.h"
3917 31 May 20 peter 25
3917 31 May 20 peter 26 #include "yat/utility/Exception.h"
3917 31 May 20 peter 27
3917 31 May 20 peter 28 #include <cstddef>
3917 31 May 20 peter 29
3917 31 May 20 peter 30 namespace theplu {
3917 31 May 20 peter 31 namespace yat {
3917 31 May 20 peter 32 namespace statistics {
3917 31 May 20 peter 33
3917 31 May 20 peter 34   TukeyBiweightEstimator::Stopper::Stopper(size_t max)
3917 31 May 20 peter 35     : epochs_(0), max_epochs_(max)
3917 31 May 20 peter 36   {}
3917 31 May 20 peter 37
3917 31 May 20 peter 38
3917 31 May 20 peter 39   bool TukeyBiweightEstimator::Stopper::stop(double x, double prev)
3917 31 May 20 peter 40   {
3917 31 May 20 peter 41     ++epochs_;
3917 31 May 20 peter 42     if (epochs_ > max_epochs_)
3917 31 May 20 peter 43       throw utility::runtime_error("TukeyBiweightIterator: too many epochs");
3917 31 May 20 peter 44     return (*this)(x, prev);
3917 31 May 20 peter 45   }
3917 31 May 20 peter 46
3917 31 May 20 peter 47
3917 31 May 20 peter 48   size_t TukeyBiweightEstimator::Stopper::epochs(void) const
3917 31 May 20 peter 49   {
3917 31 May 20 peter 50     return epochs_;
3917 31 May 20 peter 51   }
3917 31 May 20 peter 52
3917 31 May 20 peter 53
3917 31 May 20 peter 54   size_t TukeyBiweightEstimator::Stopper::max_epochs(void) const
3917 31 May 20 peter 55   {
3917 31 May 20 peter 56     return max_epochs_;
3917 31 May 20 peter 57   }
3917 31 May 20 peter 58
3917 31 May 20 peter 59
3917 31 May 20 peter 60   bool
3917 31 May 20 peter 61   TukeyBiweightEstimator::DefaultStopper::operator()(double current,
3917 31 May 20 peter 62                                                      double previous) const
3917 31 May 20 peter 63   {
3917 31 May 20 peter 64     return current == previous;
3917 31 May 20 peter 65   }
3917 31 May 20 peter 66
3917 31 May 20 peter 67 }}} // end of namespace theplu yat statistics