/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.stat.descriptive; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.NotPositiveException; import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; /** * Abstract base class for all implementations of the * {@link UnivariateStatistic} interface. *
* Provides a default implementation of evaluate(double[]),
* delegating to evaluate(double[], int, int)
in the natural way.
*
* Also includes a test
method that performs generic parameter
* validation for the evaluate
methods.
* The stored value is a copy of the parameter array, not the array itself *
* @param values data array to store (may be null to remove stored data) * @see #evaluate() */ public void setData(final double[] values) { storedData = (values == null) ? null : values.clone(); } /** * Get a copy of the stored data array. * @return copy of the stored data array (may be null) */ public double[] getData() { return (storedData == null) ? null : storedData.clone(); } /** * Get a reference to the stored data array. * @return reference to the stored data array (may be null) */ protected double[] getDataRef() { return storedData; } /** * Set the data array. * @param values data array to store * @param begin the index of the first element to include * @param length the number of elements to include * @see #evaluate() */ public void setData(final double[] values, final int begin, final int length) { storedData = new double[length]; System.arraycopy(values, begin, storedData, 0, length); } /** * Returns the result of evaluating the statistic over the stored data. ** The stored array is the one which was set by previous calls to *
* @return the value of the statistic applied to the stored data */ public double evaluate() { return evaluate(storedData); } /** * {@inheritDoc} */ public double evaluate(final double[] values) { test(values, 0, 0); return evaluate(values, 0, values.length); } /** * {@inheritDoc} */ public abstract double evaluate(final double[] values, final int begin, final int length); /** * {@inheritDoc} */ public abstract UnivariateStatistic copy(); /** * This method is used byevaluate(double[], int, int)
methods
* to verify that the input parameters designate a subarray of positive length.
* *
true
iff the parameters designate a subarray of
* positive lengthIllegalArgumentException
if the array is null or
* or the indices are invalidfalse
length
is 0.
* evaluate(double[], double[], int, int)
methods
* to verify that the begin and length parameters designate a subarray of positive length
* and the weights are all non-negative, non-NaN, finite, and not all zero.
* *
true
iff the parameters designate a subarray of
* positive length and the weights array contains legitimate values.IllegalArgumentException
if any of the following are true:
* false
length
is 0.
*