Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:32:50

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // 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_KURTOSIS_HPP_EAN_28_10_2005
0009 #define BOOST_ACCUMULATORS_STATISTICS_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/mean.hpp>
0019 #include <boost/accumulators/statistics/moment.hpp>
0020 
0021 namespace boost { namespace accumulators
0022 {
0023 
0024 namespace impl
0025 {
0026     ///////////////////////////////////////////////////////////////////////////////
0027     // kurtosis_impl
0028     /**
0029         @brief Kurtosis estimation
0030 
0031         The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
0032         moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
0033         has zero kurtosis. The kurtosis can also be expressed by the simple moments:
0034 
0035         \f[
0036             \hat{g}_2 =
0037                 \frac
0038                 {\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}
0039                 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
0040         \f]
0041 
0042         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
0043         \f$ n \f$ samples.
0044     */
0045     template<typename Sample>
0046     struct kurtosis_impl
0047       : accumulator_base
0048     {
0049         // for boost::result_of
0050         typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
0051 
0052         kurtosis_impl(dont_care) {}
0053 
0054         template<typename Args>
0055         result_type result(Args const &args) const
0056         {
0057             return numeric::fdiv(
0058                         accumulators::moment<4>(args)
0059                         - 4. * accumulators::moment<3>(args) * mean(args)
0060                         + 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
0061                         - 3. * mean(args) * mean(args) * mean(args) * mean(args)
0062                       , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
0063                         * ( accumulators::moment<2>(args) - mean(args) * mean(args) )
0064                     ) - 3.;
0065         }
0066         
0067         // serialization is done by accumulators it depends on
0068         template<class Archive>
0069         void serialize(Archive & ar, const unsigned int file_version) {}
0070     };
0071 
0072 } // namespace impl
0073 
0074 ///////////////////////////////////////////////////////////////////////////////
0075 // tag::kurtosis
0076 //
0077 namespace tag
0078 {
0079     struct kurtosis
0080       : depends_on<mean, moment<2>, moment<3>, moment<4> >
0081     {
0082         /// INTERNAL ONLY
0083         ///
0084         typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
0085     };
0086 }
0087 
0088 ///////////////////////////////////////////////////////////////////////////////
0089 // extract::kurtosis
0090 //
0091 namespace extract
0092 {
0093     extractor<tag::kurtosis> const kurtosis = {};
0094 
0095     BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
0096 }
0097 
0098 using extract::kurtosis;
0099 
0100 // So that kurtosis can be automatically substituted with
0101 // weighted_kurtosis when the weight parameter is non-void
0102 template<>
0103 struct as_weighted_feature<tag::kurtosis>
0104 {
0105     typedef tag::weighted_kurtosis type;
0106 };
0107 
0108 template<>
0109 struct feature_of<tag::weighted_kurtosis>
0110   : feature_of<tag::kurtosis>
0111 {
0112 };
0113 
0114 }} // namespace boost::accumulators
0115 
0116 #endif