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
///////////////////////////////////////////////////////////////////////////////
2
// kurtosis.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_KURTOSIS_HPP_EAN_28_10_2005
9
#define BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_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/mean.hpp>
19
#include <boost/accumulators/statistics/moment.hpp>
20

    
21
namespace boost { namespace accumulators
22
{
23

    
24
namespace impl
25
{
26
    ///////////////////////////////////////////////////////////////////////////////
27
    // kurtosis_impl
28
    /**
29
        @brief Kurtosis estimation
30

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

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

42
        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
        \f$ n \f$ samples.
44
    */
45
    template<typename Sample>
46
    struct kurtosis_impl
47
      : accumulator_base
48
    {
49
        // for boost::result_of
50
        typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
51

    
52
        kurtosis_impl(dont_care) {}
53

    
54
        template<typename Args>
55
        result_type result(Args const &args) const
56
        {
57
            return numeric::fdiv(
58
                        accumulators::moment<4>(args)
59
                        - 4. * accumulators::moment<3>(args) * mean(args)
60
                        + 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
61
                        - 3. * mean(args) * mean(args) * mean(args) * mean(args)
62
                      , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
63
                        * ( accumulators::moment<2>(args) - mean(args) * mean(args) )
64
                    ) - 3.;
65
        }
66
    };
67

    
68
} // namespace impl
69

    
70
///////////////////////////////////////////////////////////////////////////////
71
// tag::kurtosis
72
//
73
namespace tag
74
{
75
    struct kurtosis
76
      : depends_on<mean, moment<2>, moment<3>, moment<4> >
77
    {
78
        /// INTERNAL ONLY
79
        ///
80
        typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
81
    };
82
}
83

    
84
///////////////////////////////////////////////////////////////////////////////
85
// extract::kurtosis
86
//
87
namespace extract
88
{
89
    extractor<tag::kurtosis> const kurtosis = {};
90

    
91
    BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
92
}
93

    
94
using extract::kurtosis;
95

    
96
// So that kurtosis can be automatically substituted with
97
// weighted_kurtosis when the weight parameter is non-void
98
template<>
99
struct as_weighted_feature<tag::kurtosis>
100
{
101
    typedef tag::weighted_kurtosis type;
102
};
103

    
104
template<>
105
struct feature_of<tag::weighted_kurtosis>
106
  : feature_of<tag::kurtosis>
107
{
108
};
109

    
110
}} // namespace boost::accumulators
111

    
112
#endif