Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:21

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // weighted_kurtosis.hpp
0003 //
0004 //  Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
0009 #define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
0010 
0011 #include <limits>
0012 #include <boost/mpl/placeholders.hpp>
0013 #include <boost/accumulators/framework/accumulator_base.hpp>
0014 #include <boost/accumulators/framework/extractor.hpp>
0015 #include <boost/accumulators/framework/parameters/sample.hpp>
0016 #include <boost/accumulators/numeric/functional.hpp>
0017 #include <boost/accumulators/framework/depends_on.hpp>
0018 #include <boost/accumulators/statistics_fwd.hpp>
0019 #include <boost/accumulators/statistics/weighted_moment.hpp>
0020 #include <boost/accumulators/statistics/weighted_mean.hpp>
0021 
0022 namespace boost { namespace accumulators
0023 {
0024 
0025 namespace impl
0026 {
0027     ///////////////////////////////////////////////////////////////////////////////
0028     // weighted_kurtosis_impl
0029     /**
0030         @brief Kurtosis estimation for weighted samples
0031 
0032         The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
0033         moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
0034         has zero kurtosis. The kurtosis can also be expressed by the simple moments:
0035 
0036         \f[
0037             \hat{g}_2 =
0038                 \frac
0039                 {\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}
0040                 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
0041         \f]
0042 
0043         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
0044         \f$ n \f$ samples.
0045 
0046         The kurtosis estimator for weighted samples is formally identical to the estimator for unweighted samples, except that
0047         the weighted counterparts of all measures it depends on are to be taken.
0048     */
0049     template<typename Sample, typename Weight>
0050     struct weighted_kurtosis_impl
0051       : accumulator_base
0052     {
0053         typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample;
0054         // for boost::result_of
0055         typedef typename numeric::functional::fdiv<weighted_sample, weighted_sample>::result_type result_type;
0056 
0057         weighted_kurtosis_impl(dont_care)
0058         {
0059         }
0060 
0061         template<typename Args>
0062         result_type result(Args const &args) const
0063         {
0064             return numeric::fdiv(
0065                         accumulators::weighted_moment<4>(args)
0066                         - 4. * accumulators::weighted_moment<3>(args) * weighted_mean(args)
0067                         + 6. * accumulators::weighted_moment<2>(args) * weighted_mean(args) * weighted_mean(args)
0068                         - 3. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
0069                       , ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
0070                         * ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
0071                    ) - 3.;
0072         }
0073     };
0074 
0075 } // namespace impl
0076 
0077 ///////////////////////////////////////////////////////////////////////////////
0078 // tag::weighted_kurtosis
0079 //
0080 namespace tag
0081 {
0082     struct weighted_kurtosis
0083       : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3>, weighted_moment<4> >
0084     {
0085         /// INTERNAL ONLY
0086         ///
0087         typedef accumulators::impl::weighted_kurtosis_impl<mpl::_1, mpl::_2> impl;
0088     };
0089 }
0090 
0091 ///////////////////////////////////////////////////////////////////////////////
0092 // extract::weighted_kurtosis
0093 //
0094 namespace extract
0095 {
0096     extractor<tag::weighted_kurtosis> const weighted_kurtosis = {};
0097 
0098     BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_kurtosis)
0099 }
0100 
0101 using extract::weighted_kurtosis;
0102 
0103 }} // namespace boost::accumulators
0104 
0105 #endif