annotate libs/commons-math-2.1/docs/apidocs/src-html/org/apache/commons/math/stat/descriptive/moment/Kurtosis.html @ 13:cbf34dd4d7e6

commons-math-2.1 added
author dwinter
date Tue, 04 Jan 2011 10:02:07 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
1 <HTML>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
2 <BODY BGCOLOR="white">
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
3 <PRE>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
4 <FONT color="green">001</FONT> /*<a name="line.1"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
5 <FONT color="green">002</FONT> * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.2"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
6 <FONT color="green">003</FONT> * contributor license agreements. See the NOTICE file distributed with<a name="line.3"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
7 <FONT color="green">004</FONT> * this work for additional information regarding copyright ownership.<a name="line.4"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
8 <FONT color="green">005</FONT> * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.5"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
9 <FONT color="green">006</FONT> * (the "License"); you may not use this file except in compliance with<a name="line.6"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
10 <FONT color="green">007</FONT> * the License. You may obtain a copy of the License at<a name="line.7"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
11 <FONT color="green">008</FONT> *<a name="line.8"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
12 <FONT color="green">009</FONT> * http://www.apache.org/licenses/LICENSE-2.0<a name="line.9"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
13 <FONT color="green">010</FONT> *<a name="line.10"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
14 <FONT color="green">011</FONT> * Unless required by applicable law or agreed to in writing, software<a name="line.11"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
15 <FONT color="green">012</FONT> * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.12"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
16 <FONT color="green">013</FONT> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.13"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
17 <FONT color="green">014</FONT> * See the License for the specific language governing permissions and<a name="line.14"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
18 <FONT color="green">015</FONT> * limitations under the License.<a name="line.15"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
19 <FONT color="green">016</FONT> */<a name="line.16"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
20 <FONT color="green">017</FONT> package org.apache.commons.math.stat.descriptive.moment;<a name="line.17"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
21 <FONT color="green">018</FONT> <a name="line.18"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
22 <FONT color="green">019</FONT> import java.io.Serializable;<a name="line.19"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
23 <FONT color="green">020</FONT> <a name="line.20"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
24 <FONT color="green">021</FONT> import org.apache.commons.math.MathRuntimeException;<a name="line.21"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
25 <FONT color="green">022</FONT> import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;<a name="line.22"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
26 <FONT color="green">023</FONT> <a name="line.23"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
27 <FONT color="green">024</FONT> <a name="line.24"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
28 <FONT color="green">025</FONT> /**<a name="line.25"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
29 <FONT color="green">026</FONT> * Computes the Kurtosis of the available values.<a name="line.26"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
30 <FONT color="green">027</FONT> * &lt;p&gt;<a name="line.27"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
31 <FONT color="green">028</FONT> * We use the following (unbiased) formula to define kurtosis:&lt;/p&gt;<a name="line.28"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
32 <FONT color="green">029</FONT> * &lt;p&gt;<a name="line.29"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
33 <FONT color="green">030</FONT> * kurtosis = { [n(n+1) / (n -1)(n - 2)(n-3)] sum[(x_i - mean)^4] / std^4 } - [3(n-1)^2 / (n-2)(n-3)]<a name="line.30"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
34 <FONT color="green">031</FONT> * &lt;/p&gt;&lt;p&gt;<a name="line.31"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
35 <FONT color="green">032</FONT> * where n is the number of values, mean is the {@link Mean} and std is the<a name="line.32"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
36 <FONT color="green">033</FONT> * {@link StandardDeviation}&lt;/p&gt;<a name="line.33"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
37 <FONT color="green">034</FONT> * &lt;p&gt;<a name="line.34"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
38 <FONT color="green">035</FONT> * Note that this statistic is undefined for n &lt; 4. &lt;code&gt;Double.Nan&lt;/code&gt;<a name="line.35"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
39 <FONT color="green">036</FONT> * is returned when there is not sufficient data to compute the statistic.&lt;/p&gt;<a name="line.36"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
40 <FONT color="green">037</FONT> * &lt;p&gt;<a name="line.37"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
41 <FONT color="green">038</FONT> * &lt;strong&gt;Note that this implementation is not synchronized.&lt;/strong&gt; If<a name="line.38"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
42 <FONT color="green">039</FONT> * multiple threads access an instance of this class concurrently, and at least<a name="line.39"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
43 <FONT color="green">040</FONT> * one of the threads invokes the &lt;code&gt;increment()&lt;/code&gt; or<a name="line.40"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
44 <FONT color="green">041</FONT> * &lt;code&gt;clear()&lt;/code&gt; method, it must be synchronized externally.&lt;/p&gt;<a name="line.41"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
45 <FONT color="green">042</FONT> *<a name="line.42"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
46 <FONT color="green">043</FONT> * @version $Revision: 811833 $ $Date: 2009-09-06 12:27:50 -0400 (Sun, 06 Sep 2009) $<a name="line.43"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
47 <FONT color="green">044</FONT> */<a name="line.44"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
48 <FONT color="green">045</FONT> public class Kurtosis extends AbstractStorelessUnivariateStatistic implements Serializable {<a name="line.45"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
49 <FONT color="green">046</FONT> <a name="line.46"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
50 <FONT color="green">047</FONT> /** Serializable version identifier */<a name="line.47"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
51 <FONT color="green">048</FONT> private static final long serialVersionUID = 2784465764798260919L;<a name="line.48"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
52 <FONT color="green">049</FONT> <a name="line.49"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
53 <FONT color="green">050</FONT> /**Fourth Moment on which this statistic is based */<a name="line.50"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
54 <FONT color="green">051</FONT> protected FourthMoment moment;<a name="line.51"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
55 <FONT color="green">052</FONT> <a name="line.52"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
56 <FONT color="green">053</FONT> /**<a name="line.53"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
57 <FONT color="green">054</FONT> * Determines whether or not this statistic can be incremented or cleared.<a name="line.54"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
58 <FONT color="green">055</FONT> * &lt;p&gt;<a name="line.55"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
59 <FONT color="green">056</FONT> * Statistics based on (constructed from) external moments cannot<a name="line.56"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
60 <FONT color="green">057</FONT> * be incremented or cleared.&lt;/p&gt;<a name="line.57"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
61 <FONT color="green">058</FONT> */<a name="line.58"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
62 <FONT color="green">059</FONT> protected boolean incMoment;<a name="line.59"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
63 <FONT color="green">060</FONT> <a name="line.60"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
64 <FONT color="green">061</FONT> /**<a name="line.61"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
65 <FONT color="green">062</FONT> * Construct a Kurtosis<a name="line.62"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
66 <FONT color="green">063</FONT> */<a name="line.63"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
67 <FONT color="green">064</FONT> public Kurtosis() {<a name="line.64"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
68 <FONT color="green">065</FONT> incMoment = true;<a name="line.65"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
69 <FONT color="green">066</FONT> moment = new FourthMoment();<a name="line.66"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
70 <FONT color="green">067</FONT> }<a name="line.67"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
71 <FONT color="green">068</FONT> <a name="line.68"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
72 <FONT color="green">069</FONT> /**<a name="line.69"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
73 <FONT color="green">070</FONT> * Construct a Kurtosis from an external moment<a name="line.70"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
74 <FONT color="green">071</FONT> *<a name="line.71"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
75 <FONT color="green">072</FONT> * @param m4 external Moment<a name="line.72"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
76 <FONT color="green">073</FONT> */<a name="line.73"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
77 <FONT color="green">074</FONT> public Kurtosis(final FourthMoment m4) {<a name="line.74"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
78 <FONT color="green">075</FONT> incMoment = false;<a name="line.75"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
79 <FONT color="green">076</FONT> this.moment = m4;<a name="line.76"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
80 <FONT color="green">077</FONT> }<a name="line.77"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
81 <FONT color="green">078</FONT> <a name="line.78"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
82 <FONT color="green">079</FONT> /**<a name="line.79"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
83 <FONT color="green">080</FONT> * Copy constructor, creates a new {@code Kurtosis} identical<a name="line.80"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
84 <FONT color="green">081</FONT> * to the {@code original}<a name="line.81"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
85 <FONT color="green">082</FONT> *<a name="line.82"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
86 <FONT color="green">083</FONT> * @param original the {@code Kurtosis} instance to copy<a name="line.83"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
87 <FONT color="green">084</FONT> */<a name="line.84"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
88 <FONT color="green">085</FONT> public Kurtosis(Kurtosis original) {<a name="line.85"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
89 <FONT color="green">086</FONT> copy(original, this);<a name="line.86"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
90 <FONT color="green">087</FONT> }<a name="line.87"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
91 <FONT color="green">088</FONT> <a name="line.88"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
92 <FONT color="green">089</FONT> /**<a name="line.89"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
93 <FONT color="green">090</FONT> * {@inheritDoc}<a name="line.90"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
94 <FONT color="green">091</FONT> */<a name="line.91"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
95 <FONT color="green">092</FONT> @Override<a name="line.92"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
96 <FONT color="green">093</FONT> public void increment(final double d) {<a name="line.93"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
97 <FONT color="green">094</FONT> if (incMoment) {<a name="line.94"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
98 <FONT color="green">095</FONT> moment.increment(d);<a name="line.95"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
99 <FONT color="green">096</FONT> } else {<a name="line.96"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
100 <FONT color="green">097</FONT> throw MathRuntimeException.createIllegalStateException(<a name="line.97"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
101 <FONT color="green">098</FONT> "statistics constructed from external moments cannot be incremented");<a name="line.98"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
102 <FONT color="green">099</FONT> }<a name="line.99"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
103 <FONT color="green">100</FONT> }<a name="line.100"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
104 <FONT color="green">101</FONT> <a name="line.101"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
105 <FONT color="green">102</FONT> /**<a name="line.102"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
106 <FONT color="green">103</FONT> * {@inheritDoc}<a name="line.103"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
107 <FONT color="green">104</FONT> */<a name="line.104"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
108 <FONT color="green">105</FONT> @Override<a name="line.105"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
109 <FONT color="green">106</FONT> public double getResult() {<a name="line.106"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
110 <FONT color="green">107</FONT> double kurtosis = Double.NaN;<a name="line.107"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
111 <FONT color="green">108</FONT> if (moment.getN() &gt; 3) {<a name="line.108"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
112 <FONT color="green">109</FONT> double variance = moment.m2 / (moment.n - 1);<a name="line.109"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
113 <FONT color="green">110</FONT> if (moment.n &lt;= 3 || variance &lt; 10E-20) {<a name="line.110"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
114 <FONT color="green">111</FONT> kurtosis = 0.0;<a name="line.111"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
115 <FONT color="green">112</FONT> } else {<a name="line.112"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
116 <FONT color="green">113</FONT> double n = moment.n;<a name="line.113"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
117 <FONT color="green">114</FONT> kurtosis =<a name="line.114"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
118 <FONT color="green">115</FONT> (n * (n + 1) * moment.m4 -<a name="line.115"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
119 <FONT color="green">116</FONT> 3 * moment.m2 * moment.m2 * (n - 1)) /<a name="line.116"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
120 <FONT color="green">117</FONT> ((n - 1) * (n -2) * (n -3) * variance * variance);<a name="line.117"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
121 <FONT color="green">118</FONT> }<a name="line.118"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
122 <FONT color="green">119</FONT> }<a name="line.119"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
123 <FONT color="green">120</FONT> return kurtosis;<a name="line.120"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
124 <FONT color="green">121</FONT> }<a name="line.121"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
125 <FONT color="green">122</FONT> <a name="line.122"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
126 <FONT color="green">123</FONT> /**<a name="line.123"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
127 <FONT color="green">124</FONT> * {@inheritDoc}<a name="line.124"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
128 <FONT color="green">125</FONT> */<a name="line.125"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
129 <FONT color="green">126</FONT> @Override<a name="line.126"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
130 <FONT color="green">127</FONT> public void clear() {<a name="line.127"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
131 <FONT color="green">128</FONT> if (incMoment) {<a name="line.128"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
132 <FONT color="green">129</FONT> moment.clear();<a name="line.129"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
133 <FONT color="green">130</FONT> } else {<a name="line.130"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
134 <FONT color="green">131</FONT> throw MathRuntimeException.createIllegalStateException(<a name="line.131"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
135 <FONT color="green">132</FONT> "statistics constructed from external moments cannot be cleared");<a name="line.132"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
136 <FONT color="green">133</FONT> }<a name="line.133"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
137 <FONT color="green">134</FONT> }<a name="line.134"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
138 <FONT color="green">135</FONT> <a name="line.135"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
139 <FONT color="green">136</FONT> /**<a name="line.136"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
140 <FONT color="green">137</FONT> * {@inheritDoc}<a name="line.137"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
141 <FONT color="green">138</FONT> */<a name="line.138"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
142 <FONT color="green">139</FONT> public long getN() {<a name="line.139"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
143 <FONT color="green">140</FONT> return moment.getN();<a name="line.140"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
144 <FONT color="green">141</FONT> }<a name="line.141"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
145 <FONT color="green">142</FONT> <a name="line.142"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
146 <FONT color="green">143</FONT> /* UnvariateStatistic Approach */<a name="line.143"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
147 <FONT color="green">144</FONT> <a name="line.144"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
148 <FONT color="green">145</FONT> /**<a name="line.145"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
149 <FONT color="green">146</FONT> * Returns the kurtosis of the entries in the specified portion of the<a name="line.146"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
150 <FONT color="green">147</FONT> * input array.<a name="line.147"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
151 <FONT color="green">148</FONT> * &lt;p&gt;<a name="line.148"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
152 <FONT color="green">149</FONT> * See {@link Kurtosis} for details on the computing algorithm.&lt;/p&gt;<a name="line.149"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
153 <FONT color="green">150</FONT> * &lt;p&gt;<a name="line.150"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
154 <FONT color="green">151</FONT> * Throws &lt;code&gt;IllegalArgumentException&lt;/code&gt; if the array is null.&lt;/p&gt;<a name="line.151"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
155 <FONT color="green">152</FONT> *<a name="line.152"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
156 <FONT color="green">153</FONT> * @param values the input array<a name="line.153"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
157 <FONT color="green">154</FONT> * @param begin index of the first array element to include<a name="line.154"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
158 <FONT color="green">155</FONT> * @param length the number of elements to include<a name="line.155"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
159 <FONT color="green">156</FONT> * @return the kurtosis of the values or Double.NaN if length is less than<a name="line.156"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
160 <FONT color="green">157</FONT> * 4<a name="line.157"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
161 <FONT color="green">158</FONT> * @throws IllegalArgumentException if the input array is null or the array<a name="line.158"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
162 <FONT color="green">159</FONT> * index parameters are not valid<a name="line.159"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
163 <FONT color="green">160</FONT> */<a name="line.160"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
164 <FONT color="green">161</FONT> @Override<a name="line.161"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
165 <FONT color="green">162</FONT> public double evaluate(final double[] values,final int begin, final int length) {<a name="line.162"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
166 <FONT color="green">163</FONT> // Initialize the kurtosis<a name="line.163"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
167 <FONT color="green">164</FONT> double kurt = Double.NaN;<a name="line.164"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
168 <FONT color="green">165</FONT> <a name="line.165"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
169 <FONT color="green">166</FONT> if (test(values, begin, length) &amp;&amp; length &gt; 3) {<a name="line.166"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
170 <FONT color="green">167</FONT> <a name="line.167"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
171 <FONT color="green">168</FONT> // Compute the mean and standard deviation<a name="line.168"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
172 <FONT color="green">169</FONT> Variance variance = new Variance();<a name="line.169"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
173 <FONT color="green">170</FONT> variance.incrementAll(values, begin, length);<a name="line.170"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
174 <FONT color="green">171</FONT> double mean = variance.moment.m1;<a name="line.171"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
175 <FONT color="green">172</FONT> double stdDev = Math.sqrt(variance.getResult());<a name="line.172"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
176 <FONT color="green">173</FONT> <a name="line.173"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
177 <FONT color="green">174</FONT> // Sum the ^4 of the distance from the mean divided by the<a name="line.174"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
178 <FONT color="green">175</FONT> // standard deviation<a name="line.175"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
179 <FONT color="green">176</FONT> double accum3 = 0.0;<a name="line.176"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
180 <FONT color="green">177</FONT> for (int i = begin; i &lt; begin + length; i++) {<a name="line.177"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
181 <FONT color="green">178</FONT> accum3 += Math.pow(values[i] - mean, 4.0);<a name="line.178"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
182 <FONT color="green">179</FONT> }<a name="line.179"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
183 <FONT color="green">180</FONT> accum3 /= Math.pow(stdDev, 4.0d);<a name="line.180"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
184 <FONT color="green">181</FONT> <a name="line.181"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
185 <FONT color="green">182</FONT> // Get N<a name="line.182"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
186 <FONT color="green">183</FONT> double n0 = length;<a name="line.183"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
187 <FONT color="green">184</FONT> <a name="line.184"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
188 <FONT color="green">185</FONT> double coefficientOne =<a name="line.185"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
189 <FONT color="green">186</FONT> (n0 * (n0 + 1)) / ((n0 - 1) * (n0 - 2) * (n0 - 3));<a name="line.186"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
190 <FONT color="green">187</FONT> double termTwo =<a name="line.187"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
191 <FONT color="green">188</FONT> (3 * Math.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3));<a name="line.188"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
192 <FONT color="green">189</FONT> <a name="line.189"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
193 <FONT color="green">190</FONT> // Calculate kurtosis<a name="line.190"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
194 <FONT color="green">191</FONT> kurt = (coefficientOne * accum3) - termTwo;<a name="line.191"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
195 <FONT color="green">192</FONT> }<a name="line.192"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
196 <FONT color="green">193</FONT> return kurt;<a name="line.193"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
197 <FONT color="green">194</FONT> }<a name="line.194"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
198 <FONT color="green">195</FONT> <a name="line.195"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
199 <FONT color="green">196</FONT> /**<a name="line.196"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
200 <FONT color="green">197</FONT> * {@inheritDoc}<a name="line.197"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
201 <FONT color="green">198</FONT> */<a name="line.198"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
202 <FONT color="green">199</FONT> @Override<a name="line.199"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
203 <FONT color="green">200</FONT> public Kurtosis copy() {<a name="line.200"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
204 <FONT color="green">201</FONT> Kurtosis result = new Kurtosis();<a name="line.201"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
205 <FONT color="green">202</FONT> copy(this, result);<a name="line.202"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
206 <FONT color="green">203</FONT> return result;<a name="line.203"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
207 <FONT color="green">204</FONT> }<a name="line.204"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
208 <FONT color="green">205</FONT> <a name="line.205"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
209 <FONT color="green">206</FONT> /**<a name="line.206"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
210 <FONT color="green">207</FONT> * Copies source to dest.<a name="line.207"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
211 <FONT color="green">208</FONT> * &lt;p&gt;Neither source nor dest can be null.&lt;/p&gt;<a name="line.208"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
212 <FONT color="green">209</FONT> *<a name="line.209"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
213 <FONT color="green">210</FONT> * @param source Kurtosis to copy<a name="line.210"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
214 <FONT color="green">211</FONT> * @param dest Kurtosis to copy to<a name="line.211"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
215 <FONT color="green">212</FONT> * @throws NullPointerException if either source or dest is null<a name="line.212"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
216 <FONT color="green">213</FONT> */<a name="line.213"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
217 <FONT color="green">214</FONT> public static void copy(Kurtosis source, Kurtosis dest) {<a name="line.214"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
218 <FONT color="green">215</FONT> dest.moment = source.moment.copy();<a name="line.215"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
219 <FONT color="green">216</FONT> dest.incMoment = source.incMoment;<a name="line.216"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
220 <FONT color="green">217</FONT> }<a name="line.217"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
221 <FONT color="green">218</FONT> <a name="line.218"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
222 <FONT color="green">219</FONT> }<a name="line.219"></a>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
223
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
224
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
225
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
226
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
227
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
228
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
229
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
230
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
231
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
232
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
233
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
234
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
235
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
236
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
237
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
238
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
239
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
240
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
241
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
242
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
243
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
244
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
245
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
246
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
247
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
248
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
249
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
250
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
251
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
252
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
253
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
254
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
255
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
256
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
257
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
258
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
259
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
260
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
261
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
262
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
263
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
264
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
265
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
266
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
267
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
268
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
269
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
270
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
271
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
272
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
273
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
274
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
275
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
276
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
277
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
278
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
279
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
280
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
281
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
282
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
283 </PRE>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
284 </BODY>
cbf34dd4d7e6 commons-math-2.1 added
dwinter
parents:
diff changeset
285 </HTML>