Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:21

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