1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/*
2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more
3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements.  See the NOTICE file distributed with
4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership.
5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0
6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with
7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License.  You may obtain a copy of the License at
8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *      http://www.apache.org/licenses/LICENSE-2.0
10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software
12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS,
13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and
15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License.
16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.stat.descriptive;
18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.io.Serializable;
20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.MathRuntimeException;
22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.exception.util.LocalizedFormats;
23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.GeometricMean;
24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.Mean;
25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.SecondMoment;
26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.moment.Variance;
27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.rank.Max;
28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.rank.Min;
29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.summary.Sum;
30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.util.MathUtils;
33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.util.FastMath;
34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/**
36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>
37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes summary statistics for a stream of data values added using the
38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #addValue(double) addValue} method. The data values are not stored in
39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * memory, so this class can be used to compute statistics for very large data
40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * streams.
41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p>
42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>
43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The {@link StorelessUnivariateStatistic} instances used to maintain summary
44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * state and compute statistics are configurable via setters. For example, the
45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * default implementation for the variance can be overridden by calling
46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #setVarianceImpl(StorelessUnivariateStatistic)}. Actual parameters to
47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * these methods must implement the {@link StorelessUnivariateStatistic}
48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * interface and configuration must be completed before <code>addValue</code>
49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * is called. No configuration is necessary to use the default, commons-math
50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * provided implementations.
51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p>
52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>
53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Note: This class is not thread-safe. Use
54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link SynchronizedSummaryStatistics} if concurrent access from multiple
55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * threads is required.
56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p>
57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 1042376 $ $Date: 2010-12-05 16:54:55 +0100 (dim. 05 déc. 2010) $
58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic class SummaryStatistics implements StatisticalSummary, Serializable {
60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Serialization UID */
62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private static final long serialVersionUID = -2021321786743555871L;
63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** count of values that have been added */
65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected long n = 0;
66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** SecondMoment is used to compute the mean and variance */
68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected SecondMoment secondMoment = new SecondMoment();
69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** sum of values that have been added */
71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected Sum sum = new Sum();
72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** sum of the square of each value that has been added */
74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected SumOfSquares sumsq = new SumOfSquares();
75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** min of values that have been added */
77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected Min min = new Min();
78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** max of values that have been added */
80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected Max max = new Max();
81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** sumLog of values that have been added */
83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected SumOfLogs sumLog = new SumOfLogs();
84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** geoMean of values that have been added */
86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected GeometricMean geoMean = new GeometricMean(sumLog);
87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** mean of values that have been added */
89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected Mean mean = new Mean();
90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** variance of values that have been added */
92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    protected Variance variance = new Variance();
93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Sum statistic implementation - can be reset by setter. */
95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic sumImpl = sum;
96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Sum of squares statistic implementation - can be reset by setter. */
98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic sumsqImpl = sumsq;
99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Minimum statistic implementation - can be reset by setter. */
101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic minImpl = min;
102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Maximum statistic implementation - can be reset by setter. */
104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic maxImpl = max;
105dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
106dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Sum of log statistic implementation - can be reset by setter. */
107dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic sumLogImpl = sumLog;
108dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
109dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Geometric mean statistic implementation - can be reset by setter. */
110dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic geoMeanImpl = geoMean;
111dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
112dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Mean statistic implementation - can be reset by setter. */
113dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic meanImpl = mean;
114dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
115dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Variance statistic implementation - can be reset by setter. */
116dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private StorelessUnivariateStatistic varianceImpl = variance;
117dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
118dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
119dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Construct a SummaryStatistics instance
120dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
121dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public SummaryStatistics() {
122dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
123dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
124dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
125dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * A copy constructor. Creates a deep-copy of the {@code original}.
126dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
127dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param original the {@code SummaryStatistics} instance to copy
128dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
129dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public SummaryStatistics(SummaryStatistics original) {
130dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        copy(original, this);
131dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
132dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
133dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
134dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Return a {@link StatisticalSummaryValues} instance reporting current
135dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * statistics.
136dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return Current values of statistics
137dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
138dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StatisticalSummary getSummary() {
139dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return new StatisticalSummaryValues(getMean(), getVariance(), getN(),
140dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                getMax(), getMin(), getSum());
141dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
142dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
143dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
144dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Add a value to the data
145dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param value the value to add
146dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
147dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void addValue(double value) {
148dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        sumImpl.increment(value);
149dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        sumsqImpl.increment(value);
150dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        minImpl.increment(value);
151dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        maxImpl.increment(value);
152dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        sumLogImpl.increment(value);
153dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        secondMoment.increment(value);
154dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // If mean, variance or geomean have been overridden,
155dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // need to increment these
156dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (!(meanImpl instanceof Mean)) {
157dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            meanImpl.increment(value);
158dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
159dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (!(varianceImpl instanceof Variance)) {
160dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            varianceImpl.increment(value);
161dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
162dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (!(geoMeanImpl instanceof GeometricMean)) {
163dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            geoMeanImpl.increment(value);
164dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
165dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        n++;
166dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
167dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
168dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
169dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the number of available values
170dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The number of available values
171dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
172dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public long getN() {
173dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return n;
174dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
175dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
176dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
177dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the sum of the values that have been added
178dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The sum or <code>Double.NaN</code> if no values have been added
179dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
180dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSum() {
181dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumImpl.getResult();
182dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
183dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
184dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
185dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the sum of the squares of the values that have been added.
186dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
187dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
188dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
189dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return The sum of squares
190dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
191dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSumsq() {
192dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumsqImpl.getResult();
193dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
194dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
195dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
196dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the mean of the values that have been added.
197dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
198dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
199dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
200dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the mean
201dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
202dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getMean() {
203dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (mean == meanImpl) {
204dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            return new Mean(secondMoment).getResult();
205dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
206dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            return meanImpl.getResult();
207dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
208dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
209dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
210dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
211dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the standard deviation of the values that have been added.
212dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
213dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
214dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
215dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the standard deviation
216dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
217dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getStandardDeviation() {
218dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        double stdDev = Double.NaN;
219dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (getN() > 0) {
220dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            if (getN() > 1) {
221dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                stdDev = FastMath.sqrt(getVariance());
222dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            } else {
223dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                stdDev = 0.0;
224dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            }
225dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
226dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return stdDev;
227dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
228dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
229dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
230dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the variance of the values that have been added.
231dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
232dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
233dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
234dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the variance
235dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
236dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getVariance() {
237dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (varianceImpl == variance) {
238dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            return new Variance(secondMoment).getResult();
239dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
240dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            return varianceImpl.getResult();
241dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
242dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
243dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
244dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
245dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the maximum of the values that have been added.
246dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
247dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
248dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
249dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the maximum
250dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
251dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getMax() {
252dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return maxImpl.getResult();
253dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
254dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
255dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
256dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the minimum of the values that have been added.
257dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
258dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
259dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
260dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the minimum
261dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
262dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getMin() {
263dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return minImpl.getResult();
264dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
265dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
266dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
267dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the geometric mean of the values that have been added.
268dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
269dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
270dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
271dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the geometric mean
272dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
273dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getGeometricMean() {
274dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return geoMeanImpl.getResult();
275dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
276dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
277dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
278dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the sum of the logs of the values that have been added.
279dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
280dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Double.NaN is returned if no values have been added.
281dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
282dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the sum of logs
283dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
284dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
285dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSumOfLogs() {
286dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumLogImpl.getResult();
287dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
288dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
289dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
290dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns a statistic related to the Second Central Moment.  Specifically,
291dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * what is returned is the sum of squared deviations from the sample mean
292dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * among the values that have been added.
293dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
294dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns <code>Double.NaN</code> if no data values have been added and
295dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * returns <code>0</code> if there is just one value in the data set.</p>
296dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
297dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return second central moment statistic
298dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 2.0
299dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
300dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double getSecondMoment() {
301dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return secondMoment.getResult();
302dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
303dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
304dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
305dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Generates a text report displaying summary statistics from values that
306dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * have been added.
307dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return String with line feeds displaying statistics
308dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
309dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
310dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    @Override
311dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public String toString() {
312dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        StringBuilder outBuffer = new StringBuilder();
313dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        String endl = "\n";
314dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("SummaryStatistics:").append(endl);
315dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("n: ").append(getN()).append(endl);
316dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("min: ").append(getMin()).append(endl);
317dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("max: ").append(getMax()).append(endl);
318dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("mean: ").append(getMean()).append(endl);
319dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("geometric mean: ").append(getGeometricMean())
320dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            .append(endl);
321dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("variance: ").append(getVariance()).append(endl);
322dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("sum of squares: ").append(getSumsq()).append(endl);
323dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("standard deviation: ").append(getStandardDeviation())
324dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            .append(endl);
325dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        outBuffer.append("sum of logs: ").append(getSumOfLogs()).append(endl);
326dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return outBuffer.toString();
327dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
328dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
329dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
330dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Resets all statistics and storage
331dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
332dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void clear() {
333dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.n = 0;
334dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        minImpl.clear();
335dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        maxImpl.clear();
336dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        sumImpl.clear();
337dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        sumLogImpl.clear();
338dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        sumsqImpl.clear();
339dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        geoMeanImpl.clear();
340dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        secondMoment.clear();
341dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (meanImpl != mean) {
342dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            meanImpl.clear();
343dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
344dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (varianceImpl != variance) {
345dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            varianceImpl.clear();
346dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
347dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
348dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
349dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
350dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns true iff <code>object</code> is a
351dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <code>SummaryStatistics</code> instance and all statistics have the
352dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * same values as this.
353dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param object the object to test equality against.
354dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return true if object equals this
355dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
356dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    @Override
357dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public boolean equals(Object object) {
358dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (object == this) {
359dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            return true;
360dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
361dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (object instanceof SummaryStatistics == false) {
362dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            return false;
363dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
364dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        SummaryStatistics stat = (SummaryStatistics)object;
365dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return MathUtils.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) &&
366dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getMax(),           getMax())           &&
367dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getMean(),          getMean())          &&
368dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getMin(),           getMin())           &&
369dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getN(),             getN())             &&
370dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getSum(),           getSum())           &&
371dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getSumsq(),         getSumsq())         &&
372dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond               MathUtils.equalsIncludingNaN(stat.getVariance(),      getVariance());
373dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
374dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
375dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
376dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns hash code based on values of statistics
377dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return hash code
378dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
379dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    @Override
380dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public int hashCode() {
381dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        int result = 31 + MathUtils.hash(getGeometricMean());
382dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getGeometricMean());
383dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getMax());
384dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getMean());
385dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getMin());
386dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getN());
387dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getSum());
388dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getSumsq());
389dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        result = result * 31 + MathUtils.hash(getVariance());
390dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return result;
391dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
392dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
393dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    // Getters and setters for statistics implementations
394dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
395dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured Sum implementation
396dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the sum
397dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
398dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
399dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getSumImpl() {
400dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumImpl;
401dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
402dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
403dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
404dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
405dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the Sum.
406dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
407dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
408dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
409dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
410dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
411dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
412dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param sumImpl the StorelessUnivariateStatistic instance to use for
413dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the Sum
414dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
415dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
416dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
417dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
418dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setSumImpl(StorelessUnivariateStatistic sumImpl) {
419dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
420dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.sumImpl = sumImpl;
421dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
422dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
423dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
424dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured sum of squares implementation
425dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the sum of squares
426dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
427dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
428dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getSumsqImpl() {
429dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumsqImpl;
430dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
431dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
432dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
433dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
434dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the sum of squares.
435dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
436dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
437dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
438dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
439dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
440dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
441dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param sumsqImpl the StorelessUnivariateStatistic instance to use for
442dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the sum of squares
443dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
444dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
445dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
446dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
447dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl) {
448dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
449dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.sumsqImpl = sumsqImpl;
450dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
451dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
452dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
453dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured minimum implementation
454dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the minimum
455dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
456dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
457dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getMinImpl() {
458dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return minImpl;
459dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
460dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
461dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
462dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
463dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the minimum.
464dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
465dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
466dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
467dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
468dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
469dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
470dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param minImpl the StorelessUnivariateStatistic instance to use for
471dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the minimum
472dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
473dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
474dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
475dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
476dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setMinImpl(StorelessUnivariateStatistic minImpl) {
477dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
478dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.minImpl = minImpl;
479dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
480dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
481dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
482dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured maximum implementation
483dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the maximum
484dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
485dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
486dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getMaxImpl() {
487dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return maxImpl;
488dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
489dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
490dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
491dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
492dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the maximum.
493dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
494dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
495dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
496dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
497dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
498dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
499dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param maxImpl the StorelessUnivariateStatistic instance to use for
500dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the maximum
501dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
502dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
503dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
504dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
505dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setMaxImpl(StorelessUnivariateStatistic maxImpl) {
506dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
507dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.maxImpl = maxImpl;
508dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
509dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
510dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
511dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured sum of logs implementation
512dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the log sum
513dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
514dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
515dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getSumLogImpl() {
516dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return sumLogImpl;
517dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
518dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
519dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
520dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
521dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the sum of logs.
522dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
523dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
524dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
525dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
526dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
527dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
528dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param sumLogImpl the StorelessUnivariateStatistic instance to use for
529dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the log sum
530dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
531dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
532dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
533dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
534dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl) {
535dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
536dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.sumLogImpl = sumLogImpl;
537dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        geoMean.setSumLogImpl(sumLogImpl);
538dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
539dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
540dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
541dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured geometric mean implementation
542dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the geometric mean
543dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
544dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
545dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getGeoMeanImpl() {
546dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return geoMeanImpl;
547dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
548dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
549dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
550dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
551dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the geometric mean.
552dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
553dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
554dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
555dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
556dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
557dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
558dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param geoMeanImpl the StorelessUnivariateStatistic instance to use for
559dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the geometric mean
560dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
561dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
562dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
563dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
564dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl) {
565dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
566dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.geoMeanImpl = geoMeanImpl;
567dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
568dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
569dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
570dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured mean implementation
571dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the mean
572dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
573dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
574dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getMeanImpl() {
575dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return meanImpl;
576dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
577dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
578dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
579dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
580dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the mean.
581dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
582dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
583dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
584dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
585dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
586dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
587dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param meanImpl the StorelessUnivariateStatistic instance to use for
588dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the mean
589dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
590dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
591dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
592dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
593dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setMeanImpl(StorelessUnivariateStatistic meanImpl) {
594dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
595dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.meanImpl = meanImpl;
596dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
597dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
598dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
599dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the currently configured variance implementation
600dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the StorelessUnivariateStatistic implementing the variance
601dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
602dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
603dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public StorelessUnivariateStatistic getVarianceImpl() {
604dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return varianceImpl;
605dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
606dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
607dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
608dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
609dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the implementation for the variance.
610dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
611dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
612dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This method must be activated before any data has been added - i.e.,
613dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * before {@link #addValue(double) addValue} has been used to add data;
614dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * otherwise an IllegalStateException will be thrown.
615dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
616dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param varianceImpl the StorelessUnivariateStatistic instance to use for
617dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *        computing the variance
618dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws IllegalStateException if data has already been added (i.e if n >
619dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         0)
620dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @since 1.2
621dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
622dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl) {
623dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        checkEmpty();
624dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.varianceImpl = varianceImpl;
625dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
626dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
627dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
628dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Throws IllegalStateException if n > 0.
629dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
630dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private void checkEmpty() {
631dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (n > 0) {
632dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            throw MathRuntimeException.createIllegalStateException(
633dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                    LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC,
634dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                    n);
635dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
636dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
637dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
638dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
639dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns a copy of this SummaryStatistics instance with the same internal state.
640dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
641dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a copy of this
642dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
643dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public SummaryStatistics copy() {
644dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        SummaryStatistics result = new SummaryStatistics();
645dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        copy(this, result);
646dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return result;
647dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
648dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
649dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
650dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Copies source to dest.
651dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>Neither source nor dest can be null.</p>
652dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
653dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param source SummaryStatistics to copy
654dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param dest SummaryStatistics to copy to
655dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws NullPointerException if either source or dest is null
656dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
657dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static void copy(SummaryStatistics source, SummaryStatistics dest) {
658dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.maxImpl = source.maxImpl.copy();
659dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.meanImpl = source.meanImpl.copy();
660dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.minImpl = source.minImpl.copy();
661dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.sumImpl = source.sumImpl.copy();
662dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.varianceImpl = source.varianceImpl.copy();
663dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.sumLogImpl = source.sumLogImpl.copy();
664dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.sumsqImpl = source.sumsqImpl.copy();
665dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.getGeoMeanImpl() instanceof GeometricMean) {
666dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            // Keep geoMeanImpl, sumLogImpl in synch
667dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
668dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
669dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.geoMeanImpl = source.geoMeanImpl.copy();
670dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
671dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        SecondMoment.copy(source.secondMoment, dest.secondMoment);
672dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        dest.n = source.n;
673dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
674dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // Make sure that if stat == statImpl in source, same
675dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        // holds in dest; otherwise copy stat
676dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.geoMean == source.geoMeanImpl) {
677dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.geoMean = (GeometricMean) dest.geoMeanImpl;
678dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
679dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            GeometricMean.copy(source.geoMean, dest.geoMean);
680dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
681dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.max == source.maxImpl) {
682dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.max = (Max) dest.maxImpl;
683dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
684dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            Max.copy(source.max, dest.max);
685dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
686dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.mean == source.meanImpl) {
687dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.mean = (Mean) dest.meanImpl;
688dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
689dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            Mean.copy(source.mean, dest.mean);
690dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
691dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.min == source.minImpl) {
692dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.min = (Min) dest.minImpl;
693dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
694dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            Min.copy(source.min, dest.min);
695dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
696dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.sum == source.sumImpl) {
697dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.sum = (Sum) dest.sumImpl;
698dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
699dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            Sum.copy(source.sum, dest.sum);
700dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
701dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.variance == source.varianceImpl) {
702dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.variance = (Variance) dest.varianceImpl;
703dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
704dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            Variance.copy(source.variance, dest.variance);
705dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
706dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.sumLog == source.sumLogImpl) {
707dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.sumLog = (SumOfLogs) dest.sumLogImpl;
708dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
709dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            SumOfLogs.copy(source.sumLog, dest.sumLog);
710dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
711dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        if (source.sumsq == source.sumsqImpl) {
712dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            dest.sumsq = (SumOfSquares) dest.sumsqImpl;
713dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        } else {
714dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond            SumOfSquares.copy(source.sumsq, dest.sumsq);
715dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        }
716dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
717dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond}
718