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