2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.stat.descriptive.moment;
19
import java.io.Serializable;
23
* Computes a statistic related to the Third Central Moment. Specifically,
24
* what is computed is the sum of cubed deviations from the sample mean.
26
* The following recursive updating formula is used:</p>
29
* <li> dev = (current obs - previous mean) </li>
30
* <li> m2 = previous value of {@link SecondMoment} </li>
31
* <li> n = number of observations (including current obs) </li>
35
* new value = old value - 3 * (dev/n) * m2 + (n-1) * (n -2) * (dev^3/n^2)</p>
37
* Returns <code>Double.NaN</code> if no data values have been added and
38
* returns <code>0</code> if there is just one value in the data set.</p>
40
* <strong>Note that this implementation is not synchronized.</strong> If
41
* multiple threads access an instance of this class concurrently, and at least
42
* one of the threads invokes the <code>increment()</code> or
43
* <code>clear()</code> method, it must be synchronized externally.</p>
45
* @version $Revision: 762116 $ $Date: 2009-04-05 12:48:53 -0400 (Sun, 05 Apr 2009) $
47
public class ThirdMoment extends SecondMoment implements Serializable {
49
/** Serializable version identifier */
50
private static final long serialVersionUID = -7818711964045118679L;
52
/** third moment of values that have been added */
56
* Square of deviation of most recently added value from previous first
57
* moment, normalized by previous sample size. Retained to prevent
58
* repeated computation in higher order moments. nDevSq = nDev * nDev.
60
protected double nDevSq;
63
* Create a FourthMoment instance
65
public ThirdMoment() {
72
* Copy constructor, creates a new {@code ThirdMoment} identical
73
* to the {@code original}
75
* @param original the {@code ThirdMoment} instance to copy
77
public ThirdMoment(ThirdMoment original) {
85
public void increment(final double d) {
94
m3 = m3 - 3.0 * nDev * prevM2 + (n0 - 1) * (n0 - 2) * nDevSq * dev;
101
public double getResult() {
109
public void clear() {
119
public ThirdMoment copy() {
120
ThirdMoment result = new ThirdMoment();
126
* Copies source to dest.
127
* <p>Neither source nor dest can be null.</p>
129
* @param source ThirdMoment to copy
130
* @param dest ThirdMoment to copy to
131
* @throws NullPointerException if either source or dest is null
133
public static void copy(ThirdMoment source, ThirdMoment dest) {
134
SecondMoment.copy(source, dest);
136
dest.nDevSq = source.nDevSq;