Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // 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_SKEWNESS_HPP_EAN_28_10_2005 Chris@16: #define BOOST_ACCUMULATORS_STATISTICS_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: Chris@16: namespace boost { namespace accumulators Chris@16: { Chris@16: Chris@16: namespace impl Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // skewness_impl Chris@16: /** Chris@16: @brief Skewness estimation 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 3. 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: template Chris@16: struct skewness_impl Chris@16: : accumulator_base Chris@16: { Chris@16: // for boost::result_of Chris@16: typedef typename numeric::functional::fdiv::result_type result_type; Chris@16: Chris@16: skewness_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::moment<3>(args) Chris@16: - 3. * accumulators::moment<2>(args) * mean(args) Chris@16: + 2. * mean(args) * mean(args) * mean(args) Chris@16: , ( accumulators::moment<2>(args) - mean(args) * mean(args) ) Chris@16: * std::sqrt( accumulators::moment<2>(args) - mean(args) * mean(args) ) Chris@16: ); Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace impl Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // tag::skewness Chris@16: // Chris@16: namespace tag Chris@16: { Chris@16: struct skewness Chris@16: : depends_on, moment<3> > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::skewness_impl impl; Chris@16: }; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // extract::skewness Chris@16: // Chris@16: namespace extract Chris@16: { Chris@16: extractor const skewness = {}; Chris@16: Chris@16: BOOST_ACCUMULATORS_IGNORE_GLOBAL(skewness) Chris@16: } Chris@16: Chris@16: using extract::skewness; Chris@16: Chris@16: // So that skewness can be automatically substituted with Chris@16: // weighted_skewness when the weight parameter is non-void Chris@16: template<> Chris@16: struct as_weighted_feature Chris@16: { Chris@16: typedef tag::weighted_skewness type; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct feature_of Chris@16: : feature_of Chris@16: { Chris@16: }; Chris@16: Chris@16: }} // namespace boost::accumulators Chris@16: Chris@16: #endif