Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / accumulators / statistics / kurtosis.hpp @ 2486

History | View | Annotate | Download (3.6 kB)

1 2486 sjacqu01
///////////////////////////////////////////////////////////////////////////////
2 2486 sjacqu01
// kurtosis.hpp
3 2486 sjacqu01
//
4 2486 sjacqu01
//  Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
5 2486 sjacqu01
//  Software License, Version 1.0. (See accompanying file
6 2486 sjacqu01
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 2486 sjacqu01
8 2486 sjacqu01
#ifndef BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
9 2486 sjacqu01
#define BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
10 2486 sjacqu01
11 2486 sjacqu01
#include <limits>
12 2486 sjacqu01
#include <boost/mpl/placeholders.hpp>
13 2486 sjacqu01
#include <boost/accumulators/framework/accumulator_base.hpp>
14 2486 sjacqu01
#include <boost/accumulators/framework/extractor.hpp>
15 2486 sjacqu01
#include <boost/accumulators/framework/parameters/sample.hpp>
16 2486 sjacqu01
#include <boost/accumulators/numeric/functional.hpp>
17 2486 sjacqu01
#include <boost/accumulators/framework/depends_on.hpp>
18 2486 sjacqu01
#include <boost/accumulators/statistics/mean.hpp>
19 2486 sjacqu01
#include <boost/accumulators/statistics/moment.hpp>
20 2486 sjacqu01
21 2486 sjacqu01
namespace boost { namespace accumulators
22 2486 sjacqu01
{
23 2486 sjacqu01
24 2486 sjacqu01
namespace impl
25 2486 sjacqu01
{
26 2486 sjacqu01
    ///////////////////////////////////////////////////////////////////////////////
27 2486 sjacqu01
    // kurtosis_impl
28 2486 sjacqu01
    /**
29 2486 sjacqu01
        @brief Kurtosis estimation
30 2486 sjacqu01

31 2486 sjacqu01
        The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
32 2486 sjacqu01
        moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
33 2486 sjacqu01
        has zero kurtosis. The kurtosis can also be expressed by the simple moments:
34 2486 sjacqu01

35 2486 sjacqu01
        \f[
36 2486 sjacqu01
            \hat{g}_2 =
37 2486 sjacqu01
                \frac
38 2486 sjacqu01
                {\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}
39 2486 sjacqu01
                {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
40 2486 sjacqu01
        \f]
41 2486 sjacqu01

42 2486 sjacqu01
        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
43 2486 sjacqu01
        \f$ n \f$ samples.
44 2486 sjacqu01
    */
45 2486 sjacqu01
    template<typename Sample>
46 2486 sjacqu01
    struct kurtosis_impl
47 2486 sjacqu01
      : accumulator_base
48 2486 sjacqu01
    {
49 2486 sjacqu01
        // for boost::result_of
50 2486 sjacqu01
        typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
51 2486 sjacqu01
52 2486 sjacqu01
        kurtosis_impl(dont_care) {}
53 2486 sjacqu01
54 2486 sjacqu01
        template<typename Args>
55 2486 sjacqu01
        result_type result(Args const &args) const
56 2486 sjacqu01
        {
57 2486 sjacqu01
            return numeric::fdiv(
58 2486 sjacqu01
                        accumulators::moment<4>(args)
59 2486 sjacqu01
                        - 4. * accumulators::moment<3>(args) * mean(args)
60 2486 sjacqu01
                        + 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
61 2486 sjacqu01
                        - 3. * mean(args) * mean(args) * mean(args) * mean(args)
62 2486 sjacqu01
                      , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
63 2486 sjacqu01
                        * ( accumulators::moment<2>(args) - mean(args) * mean(args) )
64 2486 sjacqu01
                    ) - 3.;
65 2486 sjacqu01
        }
66 2486 sjacqu01
    };
67 2486 sjacqu01
68 2486 sjacqu01
} // namespace impl
69 2486 sjacqu01
70 2486 sjacqu01
///////////////////////////////////////////////////////////////////////////////
71 2486 sjacqu01
// tag::kurtosis
72 2486 sjacqu01
//
73 2486 sjacqu01
namespace tag
74 2486 sjacqu01
{
75 2486 sjacqu01
    struct kurtosis
76 2486 sjacqu01
      : depends_on<mean, moment<2>, moment<3>, moment<4> >
77 2486 sjacqu01
    {
78 2486 sjacqu01
        /// INTERNAL ONLY
79 2486 sjacqu01
        ///
80 2486 sjacqu01
        typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
81 2486 sjacqu01
    };
82 2486 sjacqu01
}
83 2486 sjacqu01
84 2486 sjacqu01
///////////////////////////////////////////////////////////////////////////////
85 2486 sjacqu01
// extract::kurtosis
86 2486 sjacqu01
//
87 2486 sjacqu01
namespace extract
88 2486 sjacqu01
{
89 2486 sjacqu01
    extractor<tag::kurtosis> const kurtosis = {};
90 2486 sjacqu01
91 2486 sjacqu01
    BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
92 2486 sjacqu01
}
93 2486 sjacqu01
94 2486 sjacqu01
using extract::kurtosis;
95 2486 sjacqu01
96 2486 sjacqu01
// So that kurtosis can be automatically substituted with
97 2486 sjacqu01
// weighted_kurtosis when the weight parameter is non-void
98 2486 sjacqu01
template<>
99 2486 sjacqu01
struct as_weighted_feature<tag::kurtosis>
100 2486 sjacqu01
{
101 2486 sjacqu01
    typedef tag::weighted_kurtosis type;
102 2486 sjacqu01
};
103 2486 sjacqu01
104 2486 sjacqu01
template<>
105 2486 sjacqu01
struct feature_of<tag::weighted_kurtosis>
106 2486 sjacqu01
  : feature_of<tag::kurtosis>
107 2486 sjacqu01
{
108 2486 sjacqu01
};
109 2486 sjacqu01
110 2486 sjacqu01
}} // namespace boost::accumulators
111 2486 sjacqu01
112 2486 sjacqu01
#endif