annotate DEPENDENCIES/generic/include/boost/accumulators/statistics/weighted_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 // weighted_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_WEIGHTED_SKEWNESS_HPP_EAN_28_10_2005
Chris@16 9 #define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_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/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_skewness_impl
Chris@16 29 /**
Chris@16 30 @brief Skewness estimation for weighted samples
Chris@16 31
Chris@16 32 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 33 of the 2nd central moment (the variance) of the samples. The skewness can also be expressed by the simple moments:
Chris@16 34
Chris@16 35 \f[
Chris@16 36 \hat{g}_1 =
Chris@16 37 \frac
Chris@16 38 {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3}
Chris@16 39 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}}
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 The skewness estimator for weighted samples is formally identical to the estimator for unweighted samples, except that
Chris@16 46 the weighted counterparts of all measures it depends on are to be taken.
Chris@16 47 */
Chris@16 48 template<typename Sample, typename Weight>
Chris@16 49 struct weighted_skewness_impl
Chris@16 50 : accumulator_base
Chris@16 51 {
Chris@16 52 typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample;
Chris@16 53 // for boost::result_of
Chris@16 54 typedef typename numeric::functional::fdiv<weighted_sample, weighted_sample>::result_type result_type;
Chris@16 55
Chris@16 56 weighted_skewness_impl(dont_care) {}
Chris@16 57
Chris@16 58 template<typename Args>
Chris@16 59 result_type result(Args const &args) const
Chris@16 60 {
Chris@16 61 return numeric::fdiv(
Chris@16 62 accumulators::weighted_moment<3>(args)
Chris@16 63 - 3. * accumulators::weighted_moment<2>(args) * weighted_mean(args)
Chris@16 64 + 2. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
Chris@16 65 , ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
Chris@16 66 * std::sqrt( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
Chris@16 67 );
Chris@16 68 }
Chris@16 69 };
Chris@16 70
Chris@16 71 } // namespace impl
Chris@16 72
Chris@16 73 ///////////////////////////////////////////////////////////////////////////////
Chris@16 74 // tag::weighted_skewness
Chris@16 75 //
Chris@16 76 namespace tag
Chris@16 77 {
Chris@16 78 struct weighted_skewness
Chris@16 79 : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3> >
Chris@16 80 {
Chris@16 81 /// INTERNAL ONLY
Chris@16 82 ///
Chris@16 83 typedef accumulators::impl::weighted_skewness_impl<mpl::_1, mpl::_2> impl;
Chris@16 84 };
Chris@16 85 }
Chris@16 86
Chris@16 87 ///////////////////////////////////////////////////////////////////////////////
Chris@16 88 // extract::weighted_skewness
Chris@16 89 //
Chris@16 90 namespace extract
Chris@16 91 {
Chris@16 92 extractor<tag::weighted_skewness> const weighted_skewness = {};
Chris@16 93
Chris@16 94 BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_skewness)
Chris@16 95 }
Chris@16 96
Chris@16 97 using extract::weighted_skewness;
Chris@16 98
Chris@16 99 }} // namespace boost::accumulators
Chris@16 100
Chris@16 101 #endif