Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // weighted_skewness.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_SKEWNESS_HPP_EAN_28_10_2005 Chris@16: #define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SKEWNESS_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_skewness_impl Chris@16: /** Chris@16: @brief Skewness estimation for weighted samples Chris@16: Chris@16: 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: of the 2nd central moment (the variance) of the samples. The skewness can also be expressed by the simple moments: Chris@16: Chris@16: \f[ Chris@16: \hat{g}_1 = Chris@16: \frac Chris@16: {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3} Chris@16: {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}} 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 skewness 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_skewness_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_skewness_impl(dont_care) {} 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<3>(args) Chris@16: - 3. * accumulators::weighted_moment<2>(args) * weighted_mean(args) Chris@16: + 2. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) Chris@16: , ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) ) Chris@16: * std::sqrt( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) ) Chris@16: ); Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace impl Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // tag::weighted_skewness Chris@16: // Chris@16: namespace tag Chris@16: { Chris@16: struct weighted_skewness Chris@16: : depends_on, weighted_moment<3> > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::weighted_skewness_impl impl; Chris@16: }; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // extract::weighted_skewness Chris@16: // Chris@16: namespace extract Chris@16: { Chris@16: extractor const weighted_skewness = {}; Chris@16: Chris@16: BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_skewness) Chris@16: } Chris@16: Chris@16: using extract::weighted_skewness; Chris@16: Chris@16: }} // namespace boost::accumulators Chris@16: Chris@16: #endif