annotate DEPENDENCIES/generic/include/boost/accumulators/statistics/weighted_kurtosis.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 // weighted_kurtosis.hpp
Chris@16 3 //
Chris@16 4 // Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
Chris@16 5 // Software License, Version 1.0. (See accompanying file
Chris@16 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 #ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
Chris@16 9 #define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
Chris@16 10
Chris@16 11 #include <limits>
Chris@16 12 #include <boost/mpl/placeholders.hpp>
Chris@16 13 #include <boost/accumulators/framework/accumulator_base.hpp>
Chris@16 14 #include <boost/accumulators/framework/extractor.hpp>
Chris@16 15 #include <boost/accumulators/framework/parameters/sample.hpp>
Chris@16 16 #include <boost/accumulators/numeric/functional.hpp>
Chris@16 17 #include <boost/accumulators/framework/depends_on.hpp>
Chris@16 18 #include <boost/accumulators/statistics_fwd.hpp>
Chris@16 19 #include <boost/accumulators/statistics/weighted_moment.hpp>
Chris@16 20 #include <boost/accumulators/statistics/weighted_mean.hpp>
Chris@16 21
Chris@16 22 namespace boost { namespace accumulators
Chris@16 23 {
Chris@16 24
Chris@16 25 namespace impl
Chris@16 26 {
Chris@16 27 ///////////////////////////////////////////////////////////////////////////////
Chris@16 28 // weighted_kurtosis_impl
Chris@16 29 /**
Chris@16 30 @brief Kurtosis estimation for weighted samples
Chris@16 31
Chris@16 32 The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
Chris@16 33 moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
Chris@16 34 has zero kurtosis. The kurtosis can also be expressed by the simple moments:
Chris@16 35
Chris@16 36 \f[
Chris@16 37 \hat{g}_2 =
Chris@16 38 \frac
Chris@16 39 {\widehat{m}_n^{(4)}-4\widehat{m}_n^{(3)}\hat{\mu}_n+6\widehat{m}_n^{(2)}\hat{\mu}_n^2-3\hat{\mu}_n^4}
Chris@16 40 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
Chris@16 41 \f]
Chris@16 42
Chris@16 43 where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
Chris@16 44 \f$ n \f$ samples.
Chris@16 45
Chris@16 46 The kurtosis estimator for weighted samples is formally identical to the estimator for unweighted samples, except that
Chris@16 47 the weighted counterparts of all measures it depends on are to be taken.
Chris@16 48 */
Chris@16 49 template<typename Sample, typename Weight>
Chris@16 50 struct weighted_kurtosis_impl
Chris@16 51 : accumulator_base
Chris@16 52 {
Chris@16 53 typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample;
Chris@16 54 // for boost::result_of
Chris@16 55 typedef typename numeric::functional::fdiv<weighted_sample, weighted_sample>::result_type result_type;
Chris@16 56
Chris@16 57 weighted_kurtosis_impl(dont_care)
Chris@16 58 {
Chris@16 59 }
Chris@16 60
Chris@16 61 template<typename Args>
Chris@16 62 result_type result(Args const &args) const
Chris@16 63 {
Chris@16 64 return numeric::fdiv(
Chris@16 65 accumulators::weighted_moment<4>(args)
Chris@16 66 - 4. * accumulators::weighted_moment<3>(args) * weighted_mean(args)
Chris@16 67 + 6. * accumulators::weighted_moment<2>(args) * weighted_mean(args) * weighted_mean(args)
Chris@16 68 - 3. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
Chris@16 69 , ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
Chris@16 70 * ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
Chris@16 71 ) - 3.;
Chris@16 72 }
Chris@16 73 };
Chris@16 74
Chris@16 75 } // namespace impl
Chris@16 76
Chris@16 77 ///////////////////////////////////////////////////////////////////////////////
Chris@16 78 // tag::weighted_kurtosis
Chris@16 79 //
Chris@16 80 namespace tag
Chris@16 81 {
Chris@16 82 struct weighted_kurtosis
Chris@16 83 : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3>, weighted_moment<4> >
Chris@16 84 {
Chris@16 85 /// INTERNAL ONLY
Chris@16 86 ///
Chris@16 87 typedef accumulators::impl::weighted_kurtosis_impl<mpl::_1, mpl::_2> impl;
Chris@16 88 };
Chris@16 89 }
Chris@16 90
Chris@16 91 ///////////////////////////////////////////////////////////////////////////////
Chris@16 92 // extract::weighted_kurtosis
Chris@16 93 //
Chris@16 94 namespace extract
Chris@16 95 {
Chris@16 96 extractor<tag::weighted_kurtosis> const weighted_kurtosis = {};
Chris@16 97
Chris@16 98 BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_kurtosis)
Chris@16 99 }
Chris@16 100
Chris@16 101 using extract::weighted_kurtosis;
Chris@16 102
Chris@16 103 }} // namespace boost::accumulators
Chris@16 104
Chris@16 105 #endif