PageRenderTime 48ms CodeModel.GetById 30ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/accumulators/statistics/skewness.hpp

http://hadesmem.googlecode.com/
C++ Header | 114 lines | 63 code | 16 blank | 35 comment | 0 complexity | df8b936e98462c05b207b1001b33db60 MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////
  2// skewness.hpp
  3//
  4//  Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
  5//  Software License, Version 1.0. (See accompanying file
  6//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7
  8#ifndef BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
  9#define BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
 10
 11#include <limits>
 12#include <boost/mpl/placeholders.hpp>
 13#include <boost/accumulators/framework/accumulator_base.hpp>
 14#include <boost/accumulators/framework/extractor.hpp>
 15#include <boost/accumulators/framework/parameters/sample.hpp>
 16#include <boost/accumulators/numeric/functional.hpp>
 17#include <boost/accumulators/framework/depends_on.hpp>
 18#include <boost/accumulators/statistics_fwd.hpp>
 19#include <boost/accumulators/statistics/moment.hpp>
 20#include <boost/accumulators/statistics/mean.hpp>
 21
 22
 23namespace boost { namespace accumulators
 24{
 25
 26namespace impl
 27{
 28    ///////////////////////////////////////////////////////////////////////////////
 29    // skewness_impl
 30    /**
 31        @brief Skewness estimation
 32
 33        The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the \f$ 3/2 \f$-th power
 34        of the 2nd central moment (the variance) of the sampless 3. The skewness can also be expressed by the simple moments:
 35
 36        \f[
 37            \hat{g}_1 =
 38                \frac
 39                {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3}
 40                {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}}
 41        \f]
 42
 43        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
 44        \f$ n \f$ samples.
 45    */
 46    template<typename Sample>
 47    struct skewness_impl
 48      : accumulator_base
 49    {
 50        // for boost::result_of
 51        typedef typename numeric::functional::average<Sample, Sample>::result_type result_type;
 52
 53        skewness_impl(dont_care)
 54        {
 55        }
 56
 57        template<typename Args>
 58        result_type result(Args const &args) const
 59        {
 60            return numeric::average(
 61                        accumulators::moment<3>(args)
 62                        - 3. * accumulators::moment<2>(args) * mean(args)
 63                        + 2. * mean(args) * mean(args) * mean(args)
 64                      , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
 65                        * std::sqrt( accumulators::moment<2>(args) - mean(args) * mean(args) )
 66                   );
 67        }
 68    };
 69
 70} // namespace impl
 71
 72///////////////////////////////////////////////////////////////////////////////
 73// tag::skewness
 74//
 75namespace tag
 76{
 77    struct skewness
 78      : depends_on<mean, moment<2>, moment<3> >
 79    {
 80        /// INTERNAL ONLY
 81        ///
 82        typedef accumulators::impl::skewness_impl<mpl::_1> impl;
 83    };
 84}
 85
 86///////////////////////////////////////////////////////////////////////////////
 87// extract::skewness
 88//
 89namespace extract
 90{
 91    extractor<tag::skewness> const skewness = {};
 92
 93    BOOST_ACCUMULATORS_IGNORE_GLOBAL(skewness)
 94}
 95
 96using extract::skewness;
 97
 98// So that skewness can be automatically substituted with
 99// weighted_skewness when the weight parameter is non-void
100template<>
101struct as_weighted_feature<tag::skewness>
102{
103    typedef tag::weighted_skewness type;
104};
105
106template<>
107struct feature_of<tag::weighted_skewness>
108  : feature_of<tag::skewness>
109{
110};
111
112}} // namespace boost::accumulators
113
114#endif