annotate DEPENDENCIES/generic/include/boost/accumulators/statistics/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 // 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_KURTOSIS_HPP_EAN_28_10_2005
Chris@16 9 #define BOOST_ACCUMULATORS_STATISTICS_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/mean.hpp>
Chris@16 19 #include <boost/accumulators/statistics/moment.hpp>
Chris@16 20
Chris@16 21 namespace boost { namespace accumulators
Chris@16 22 {
Chris@16 23
Chris@16 24 namespace impl
Chris@16 25 {
Chris@16 26 ///////////////////////////////////////////////////////////////////////////////
Chris@16 27 // kurtosis_impl
Chris@16 28 /**
Chris@16 29 @brief Kurtosis estimation
Chris@16 30
Chris@16 31 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 32 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 33 has zero kurtosis. The kurtosis can also be expressed by the simple moments:
Chris@16 34
Chris@16 35 \f[
Chris@16 36 \hat{g}_2 =
Chris@16 37 \frac
Chris@16 38 {\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 39 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
Chris@16 40 \f]
Chris@16 41
Chris@16 42 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 43 \f$ n \f$ samples.
Chris@16 44 */
Chris@16 45 template<typename Sample>
Chris@16 46 struct kurtosis_impl
Chris@16 47 : accumulator_base
Chris@16 48 {
Chris@16 49 // for boost::result_of
Chris@16 50 typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
Chris@16 51
Chris@16 52 kurtosis_impl(dont_care) {}
Chris@16 53
Chris@16 54 template<typename Args>
Chris@16 55 result_type result(Args const &args) const
Chris@16 56 {
Chris@16 57 return numeric::fdiv(
Chris@16 58 accumulators::moment<4>(args)
Chris@16 59 - 4. * accumulators::moment<3>(args) * mean(args)
Chris@16 60 + 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
Chris@16 61 - 3. * mean(args) * mean(args) * mean(args) * mean(args)
Chris@16 62 , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
Chris@16 63 * ( accumulators::moment<2>(args) - mean(args) * mean(args) )
Chris@16 64 ) - 3.;
Chris@16 65 }
Chris@16 66 };
Chris@16 67
Chris@16 68 } // namespace impl
Chris@16 69
Chris@16 70 ///////////////////////////////////////////////////////////////////////////////
Chris@16 71 // tag::kurtosis
Chris@16 72 //
Chris@16 73 namespace tag
Chris@16 74 {
Chris@16 75 struct kurtosis
Chris@16 76 : depends_on<mean, moment<2>, moment<3>, moment<4> >
Chris@16 77 {
Chris@16 78 /// INTERNAL ONLY
Chris@16 79 ///
Chris@16 80 typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
Chris@16 81 };
Chris@16 82 }
Chris@16 83
Chris@16 84 ///////////////////////////////////////////////////////////////////////////////
Chris@16 85 // extract::kurtosis
Chris@16 86 //
Chris@16 87 namespace extract
Chris@16 88 {
Chris@16 89 extractor<tag::kurtosis> const kurtosis = {};
Chris@16 90
Chris@16 91 BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
Chris@16 92 }
Chris@16 93
Chris@16 94 using extract::kurtosis;
Chris@16 95
Chris@16 96 // So that kurtosis can be automatically substituted with
Chris@16 97 // weighted_kurtosis when the weight parameter is non-void
Chris@16 98 template<>
Chris@16 99 struct as_weighted_feature<tag::kurtosis>
Chris@16 100 {
Chris@16 101 typedef tag::weighted_kurtosis type;
Chris@16 102 };
Chris@16 103
Chris@16 104 template<>
Chris@16 105 struct feature_of<tag::weighted_kurtosis>
Chris@16 106 : feature_of<tag::kurtosis>
Chris@16 107 {
Chris@16 108 };
Chris@16 109
Chris@16 110 }} // namespace boost::accumulators
Chris@16 111
Chris@16 112 #endif