Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // weighted_kurtosis.hpp Chris@16: // Chris@16: // Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005 Chris@16: #define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace accumulators Chris@16: { Chris@16: Chris@16: namespace impl Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // weighted_kurtosis_impl Chris@16: /** Chris@16: @brief Kurtosis estimation for weighted samples Chris@16: Chris@16: 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: 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: has zero kurtosis. The kurtosis can also be expressed by the simple moments: Chris@16: Chris@16: \f[ Chris@16: \hat{g}_2 = Chris@16: \frac Chris@16: {\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: {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3, Chris@16: \f] Chris@16: Chris@16: 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: \f$ n \f$ samples. Chris@16: Chris@16: The kurtosis estimator for weighted samples is formally identical to the estimator for unweighted samples, except that Chris@16: the weighted counterparts of all measures it depends on are to be taken. Chris@16: */ Chris@16: template Chris@16: struct weighted_kurtosis_impl Chris@16: : accumulator_base Chris@16: { Chris@16: typedef typename numeric::functional::multiplies::result_type weighted_sample; Chris@16: // for boost::result_of Chris@16: typedef typename numeric::functional::fdiv::result_type result_type; Chris@16: Chris@16: weighted_kurtosis_impl(dont_care) Chris@16: { Chris@16: } Chris@16: Chris@16: template Chris@16: result_type result(Args const &args) const Chris@16: { Chris@16: return numeric::fdiv( Chris@16: accumulators::weighted_moment<4>(args) Chris@16: - 4. * accumulators::weighted_moment<3>(args) * weighted_mean(args) Chris@16: + 6. * accumulators::weighted_moment<2>(args) * weighted_mean(args) * weighted_mean(args) Chris@16: - 3. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) Chris@16: , ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) ) Chris@16: * ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) ) Chris@16: ) - 3.; Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace impl Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // tag::weighted_kurtosis Chris@16: // Chris@16: namespace tag Chris@16: { Chris@16: struct weighted_kurtosis Chris@16: : depends_on, weighted_moment<3>, weighted_moment<4> > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::weighted_kurtosis_impl impl; Chris@16: }; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // extract::weighted_kurtosis Chris@16: // Chris@16: namespace extract Chris@16: { Chris@16: extractor const weighted_kurtosis = {}; Chris@16: Chris@16: BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_kurtosis) Chris@16: } Chris@16: Chris@16: using extract::weighted_kurtosis; Chris@16: Chris@16: }} // namespace boost::accumulators Chris@16: Chris@16: #endif