Added throws declarations, improved javadoc, made Kurtosis increment consistent with other moment statistics. JIRA: MATH-854.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1382332 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8f2fb815f
commit
ae26b9bf23
|
@ -105,9 +105,9 @@ public class Frequency implements Serializable {
|
|||
* </p>
|
||||
*
|
||||
* @param v the value to add.
|
||||
* @throws IllegalArgumentException if <code>v</code> is not comparable with previous entries
|
||||
* @throws MathIllegalArgumentException if <code>v</code> is not comparable with previous entries
|
||||
*/
|
||||
public void addValue(Comparable<?> v){
|
||||
public void addValue(Comparable<?> v) throws MathIllegalArgumentException {
|
||||
Comparable<?> obj = v;
|
||||
if (v instanceof Integer) {
|
||||
obj = Long.valueOf(((Integer) v).longValue());
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
|
@ -87,9 +88,10 @@ public final class StatUtils {
|
|||
* @param values array of values to sum
|
||||
* @return the sum of the values or <code>Double.NaN</code> if the array
|
||||
* is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public static double sum(final double[] values) {
|
||||
public static double sum(final double[] values)
|
||||
throws MathIllegalArgumentException {
|
||||
return SUM.evaluate(values);
|
||||
}
|
||||
|
||||
|
@ -104,11 +106,11 @@ public final class StatUtils {
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the sum of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public static double sum(final double[] values, final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return SUM.evaluate(values, begin, length);
|
||||
}
|
||||
|
||||
|
@ -121,9 +123,9 @@ public final class StatUtils {
|
|||
* @param values input array
|
||||
* @return the sum of the squared values or <code>Double.NaN</code> if the
|
||||
* array is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public static double sumSq(final double[] values) {
|
||||
public static double sumSq(final double[] values) throws MathIllegalArgumentException {
|
||||
return SUM_OF_SQUARES.evaluate(values);
|
||||
}
|
||||
|
||||
|
@ -138,11 +140,11 @@ public final class StatUtils {
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the sum of the squares of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public static double sumSq(final double[] values, final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return SUM_OF_SQUARES.evaluate(values, begin, length);
|
||||
}
|
||||
|
||||
|
@ -154,9 +156,10 @@ public final class StatUtils {
|
|||
*
|
||||
* @param values the input array
|
||||
* @return the product of the values or Double.NaN if the array is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public static double product(final double[] values) {
|
||||
public static double product(final double[] values)
|
||||
throws MathIllegalArgumentException {
|
||||
return PRODUCT.evaluate(values);
|
||||
}
|
||||
|
||||
|
@ -171,11 +174,11 @@ public final class StatUtils {
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the product of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public static double product(final double[] values, final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return PRODUCT.evaluate(values, begin, length);
|
||||
}
|
||||
|
||||
|
@ -191,9 +194,10 @@ public final class StatUtils {
|
|||
* @param values the input array
|
||||
* @return the sum of the natural logs of the values or Double.NaN if
|
||||
* the array is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public static double sumLog(final double[] values) {
|
||||
public static double sumLog(final double[] values)
|
||||
throws MathIllegalArgumentException {
|
||||
return SUM_OF_LOGS.evaluate(values);
|
||||
}
|
||||
|
||||
|
@ -212,11 +216,11 @@ public final class StatUtils {
|
|||
* @param length the number of elements to include
|
||||
* @return the sum of the natural logs of the values or Double.NaN if
|
||||
* length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public static double sumLog(final double[] values, final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return SUM_OF_LOGS.evaluate(values, begin, length);
|
||||
}
|
||||
|
||||
|
@ -231,9 +235,10 @@ public final class StatUtils {
|
|||
*
|
||||
* @param values the input array
|
||||
* @return the mean of the values or Double.NaN if the array is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public static double mean(final double[] values) {
|
||||
public static double mean(final double[] values)
|
||||
throws MathIllegalArgumentException {
|
||||
return MEAN.evaluate(values);
|
||||
}
|
||||
|
||||
|
@ -251,11 +256,11 @@ public final class StatUtils {
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the mean of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public static double mean(final double[] values, final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return MEAN.evaluate(values, begin, length);
|
||||
}
|
||||
|
||||
|
@ -270,9 +275,10 @@ public final class StatUtils {
|
|||
*
|
||||
* @param values the input array
|
||||
* @return the geometric mean of the values or Double.NaN if the array is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public static double geometricMean(final double[] values) {
|
||||
public static double geometricMean(final double[] values)
|
||||
throws MathIllegalArgumentException {
|
||||
return GEOMETRIC_MEAN.evaluate(values);
|
||||
}
|
||||
|
||||
|
@ -290,11 +296,11 @@ public final class StatUtils {
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the geometric mean of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public static double geometricMean(final double[] values, final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return GEOMETRIC_MEAN.evaluate(values, begin, length);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
import org.apache.commons.math3.util.Precision;
|
||||
|
@ -49,13 +50,14 @@ public abstract class AbstractStorelessUnivariateStatistic
|
|||
* possibly more accurate implementation that works directly with the
|
||||
* input array.</p>
|
||||
* <p>
|
||||
* If the array is null, an IllegalArgumentException is thrown.</p>
|
||||
* If the array is null, a MathIllegalArgumentException is thrown.</p>
|
||||
* @param values input array
|
||||
* @return the value of the statistic applied to the input array
|
||||
* @throws MathIllegalArgumentException if values is null
|
||||
* @see org.apache.commons.math3.stat.descriptive.UnivariateStatistic#evaluate(double[])
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values) {
|
||||
public double evaluate(final double[] values) throws MathIllegalArgumentException {
|
||||
if (values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
}
|
||||
|
@ -76,15 +78,17 @@ public abstract class AbstractStorelessUnivariateStatistic
|
|||
* input array.</p>
|
||||
* <p>
|
||||
* If the array is null or the index parameters are not valid, an
|
||||
* IllegalArgumentException is thrown.</p>
|
||||
* MathIllegalArgumentException is thrown.</p>
|
||||
* @param values the input array
|
||||
* @param begin the index of the first element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the value of the statistic applied to the included array entries
|
||||
* @throws MathIllegalArgumentException if the array is null or the indices are not valid
|
||||
* @see org.apache.commons.math3.stat.descriptive.UnivariateStatistic#evaluate(double[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values, final int begin, final int length) {
|
||||
public double evaluate(final double[] values, final int begin,
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
if (test(values, begin, length)) {
|
||||
clear();
|
||||
incrementAll(values, begin, length);
|
||||
|
@ -120,10 +124,10 @@ public abstract class AbstractStorelessUnivariateStatistic
|
|||
* Throws IllegalArgumentException if the input values array is null.</p>
|
||||
*
|
||||
* @param values values to add
|
||||
* @throws IllegalArgumentException if values is null
|
||||
* @throws MathIllegalArgumentException if values is null
|
||||
* @see org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic#incrementAll(double[])
|
||||
*/
|
||||
public void incrementAll(double[] values) {
|
||||
public void incrementAll(double[] values) throws MathIllegalArgumentException {
|
||||
if (values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
}
|
||||
|
@ -139,10 +143,10 @@ public abstract class AbstractStorelessUnivariateStatistic
|
|||
* @param values array holding values to add
|
||||
* @param begin index of the first array element to add
|
||||
* @param length number of array elements to add
|
||||
* @throws IllegalArgumentException if values is null
|
||||
* @throws MathIllegalArgumentException if values is null
|
||||
* @see org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic#incrementAll(double[], int, int)
|
||||
*/
|
||||
public void incrementAll(double[] values, int begin, int length) {
|
||||
public void incrementAll(double[] values, int begin, int length) throws MathIllegalArgumentException {
|
||||
if (test(values, begin, length)) {
|
||||
int k = begin + length;
|
||||
for (int i = begin; i < k; i++) {
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class AbstractUnivariateStatistic
|
|||
/**
|
||||
* Set the data array.
|
||||
* <p>
|
||||
* The stored value is a copy of the parameter array, not the array itself
|
||||
* The stored value is a copy of the parameter array, not the array itself.
|
||||
* </p>
|
||||
* @param values data array to store (may be null to remove stored data)
|
||||
* @see #evaluate()
|
||||
|
@ -71,13 +71,33 @@ public abstract class AbstractUnivariateStatistic
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the data array.
|
||||
* Set the data array. The input array is copied, not referenced.
|
||||
*
|
||||
* @param values data array to store
|
||||
* @param begin the index of the first element to include
|
||||
* @param length the number of elements to include
|
||||
* @throws MathIllegalArgumentException if values is null or the indices
|
||||
* are not valid
|
||||
* @see #evaluate()
|
||||
*/
|
||||
public void setData(final double[] values, final int begin, final int length) {
|
||||
public void setData(final double[] values, final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
if (values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
}
|
||||
|
||||
if (begin < 0) {
|
||||
throw new NotPositiveException(LocalizedFormats.START_POSITION, begin);
|
||||
}
|
||||
|
||||
if (length < 0) {
|
||||
throw new NotPositiveException(LocalizedFormats.LENGTH, length);
|
||||
}
|
||||
|
||||
if (begin + length > values.length) {
|
||||
throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END,
|
||||
begin + length, values.length, true);
|
||||
}
|
||||
storedData = new double[length];
|
||||
System.arraycopy(values, begin, storedData, 0, length);
|
||||
}
|
||||
|
@ -85,18 +105,19 @@ public abstract class AbstractUnivariateStatistic
|
|||
/**
|
||||
* Returns the result of evaluating the statistic over the stored data.
|
||||
* <p>
|
||||
* The stored array is the one which was set by previous calls to
|
||||
* The stored array is the one which was set by previous calls to {@link #setData(double[])}.
|
||||
* </p>
|
||||
* @return the value of the statistic applied to the stored data
|
||||
* @throws MathIllegalArgumentException if the stored data array is null
|
||||
*/
|
||||
public double evaluate() {
|
||||
public double evaluate() throws MathIllegalArgumentException {
|
||||
return evaluate(storedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public double evaluate(final double[] values) {
|
||||
public double evaluate(final double[] values) throws MathIllegalArgumentException {
|
||||
test(values, 0, 0);
|
||||
return evaluate(values, 0, values.length);
|
||||
}
|
||||
|
@ -104,7 +125,8 @@ public abstract class AbstractUnivariateStatistic
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public abstract double evaluate(final double[] values, final int begin, final int length);
|
||||
public abstract double evaluate(final double[] values, final int begin, final int length)
|
||||
throws MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -118,7 +140,7 @@ public abstract class AbstractUnivariateStatistic
|
|||
* <ul>
|
||||
* <li>returns <code>true</code> iff the parameters designate a subarray of
|
||||
* positive length</li>
|
||||
* <li>throws <code>IllegalArgumentException</code> if the array is null or
|
||||
* <li>throws <code>MathIllegalArgumentException</code> if the array is null or
|
||||
* or the indices are invalid</li>
|
||||
* <li>returns <code>false</li> if the array is non-null, but
|
||||
* <code>length</code> is 0.
|
||||
|
@ -128,12 +150,12 @@ public abstract class AbstractUnivariateStatistic
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return true if the parameters are valid and designate a subarray of positive length
|
||||
* @throws IllegalArgumentException if the indices are invalid or the array is null
|
||||
* @throws MathIllegalArgumentException if the indices are invalid or the array is null
|
||||
*/
|
||||
protected boolean test(
|
||||
final double[] values,
|
||||
final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return test(values, begin, length, false);
|
||||
}
|
||||
|
||||
|
@ -155,10 +177,11 @@ public abstract class AbstractUnivariateStatistic
|
|||
* @param length the number of elements to include
|
||||
* @param allowEmpty if <code>true</code> then zero length arrays are allowed
|
||||
* @return true if the parameters are valid
|
||||
* @throws IllegalArgumentException if the indices are invalid or the array is null
|
||||
* @throws MathIllegalArgumentException if the indices are invalid or the array is null
|
||||
* @since 3.0
|
||||
*/
|
||||
protected boolean test(final double[] values, final int begin, final int length, final boolean allowEmpty){
|
||||
protected boolean test(final double[] values, final int begin,
|
||||
final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
|
||||
|
||||
if (values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
|
@ -211,14 +234,14 @@ public abstract class AbstractUnivariateStatistic
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return true if the parameters are valid and designate a subarray of positive length
|
||||
* @throws IllegalArgumentException if the indices are invalid or the array is null
|
||||
* @throws MathIllegalArgumentException if the indices are invalid or the array is null
|
||||
* @since 2.1
|
||||
*/
|
||||
protected boolean test(
|
||||
final double[] values,
|
||||
final double[] weights,
|
||||
final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
return test(values, weights, begin, length, false);
|
||||
}
|
||||
|
||||
|
@ -230,7 +253,7 @@ public abstract class AbstractUnivariateStatistic
|
|||
* <ul>
|
||||
* <li>returns <code>true</code> iff the parameters designate a subarray of
|
||||
* non-negative length and the weights array contains legitimate values.</li>
|
||||
* <li>throws <code>IllegalArgumentException</code> if any of the following are true:
|
||||
* <li>throws <code>MathIllegalArgumentException</code> if any of the following are true:
|
||||
* <ul><li>the values array is null</li>
|
||||
* <li>the weights array is null</li>
|
||||
* <li>the weights array does not have the same length as the values array</li>
|
||||
|
@ -249,13 +272,16 @@ public abstract class AbstractUnivariateStatistic
|
|||
* @param length the number of elements to include.
|
||||
* @param allowEmpty if {@code true} than allow zero length arrays to pass.
|
||||
* @return {@code true} if the parameters are valid.
|
||||
* @throws IllegalArgumentException if the indices are invalid or the array
|
||||
* is {@code null}.
|
||||
* @throws NullArgumentException if either of the arrays are null
|
||||
* @throws MathIllegalArgumentException if the array indices are not valid,
|
||||
* the weights array contains NaN, infinite or negative elements, or there
|
||||
* are no positive weights.
|
||||
* @since 3.0
|
||||
*/
|
||||
protected boolean test(final double[] values, final double[] weights, final int begin, final int length, final boolean allowEmpty){
|
||||
protected boolean test(final double[] values, final double[] weights,
|
||||
final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
|
||||
|
||||
if (weights == null) {
|
||||
if (weights == null || values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.io.Serializable;
|
|||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* An aggregator for {@code SummaryStatistics} from several data sets or
|
||||
|
@ -73,6 +75,7 @@ public class AggregateSummaryStatistics implements StatisticalSummary,
|
|||
*
|
||||
*/
|
||||
public AggregateSummaryStatistics() {
|
||||
// No try-catch or throws NAE because arg is guaranteed non-null
|
||||
this(new SummaryStatistics());
|
||||
}
|
||||
|
||||
|
@ -90,9 +93,10 @@ public class AggregateSummaryStatistics implements StatisticalSummary,
|
|||
* If {@code null}, a new, default statistics object is used. Any statistic
|
||||
* values in the prototype are propagated to contributing statistics
|
||||
* objects and (once) into these aggregate statistics.
|
||||
* @throws NullArgumentException if prototypeStatistics is null
|
||||
* @see #createContributingStatistics()
|
||||
*/
|
||||
public AggregateSummaryStatistics(SummaryStatistics prototypeStatistics) {
|
||||
public AggregateSummaryStatistics(SummaryStatistics prototypeStatistics) throws NullArgumentException {
|
||||
this(prototypeStatistics,
|
||||
prototypeStatistics == null ? null : new SummaryStatistics(prototypeStatistics));
|
||||
}
|
||||
|
@ -281,6 +285,7 @@ public class AggregateSummaryStatistics implements StatisticalSummary,
|
|||
SummaryStatistics contributingStatistics
|
||||
= new AggregatingSummaryStatistics(statistics);
|
||||
|
||||
// No try - catch or advertising NAE because neither argument will ever be null
|
||||
SummaryStatistics.copy(statisticsPrototype, contributingStatistics);
|
||||
|
||||
return contributingStatistics;
|
||||
|
|
|
@ -121,8 +121,10 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
* Construct a DescriptiveStatistics instance with the specified window
|
||||
*
|
||||
* @param window the window size.
|
||||
* @throws MathIllegalArgumentException if window size is less than 1 but
|
||||
* not equal to {@link #INFINITE_WINDOW}
|
||||
*/
|
||||
public DescriptiveStatistics(int window) {
|
||||
public DescriptiveStatistics(int window) throws MathIllegalArgumentException {
|
||||
setWindowSize(window);
|
||||
}
|
||||
|
||||
|
@ -145,8 +147,9 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
* is a copy of original.
|
||||
*
|
||||
* @param original DescriptiveStatistics instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public DescriptiveStatistics(DescriptiveStatistics original) {
|
||||
public DescriptiveStatistics(DescriptiveStatistics original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -329,15 +332,20 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* WindowSize controls the number of values which contribute
|
||||
* to the reported statistics. For example, if
|
||||
* windowSize is set to 3 and the values {1,2,3,4,5}
|
||||
* have been added <strong> in that order</strong>
|
||||
* then the <i>available values</i> are {3,4,5} and all
|
||||
* reported statistics will be based on these values
|
||||
* WindowSize controls the number of values that contribute to the
|
||||
* reported statistics. For example, if windowSize is set to 3 and the
|
||||
* values {1,2,3,4,5} have been added <strong> in that order</strong> then
|
||||
* the <i>available values</i> are {3,4,5} and all reported statistics will
|
||||
* be based on these values. If {@code windowSize} is decreased as a result
|
||||
* of this call and there are more than the new value of elements in the
|
||||
* current dataset, values from the front of the array are discarded to
|
||||
* reduce the dataset to {@code windowSize} elements.
|
||||
*
|
||||
* @param windowSize sets the size of the window.
|
||||
* @throws MathIllegalArgumentException if window size is less than 1 but
|
||||
* not equal to {@link #INFINITE_WINDOW}
|
||||
*/
|
||||
public void setWindowSize(int windowSize) {
|
||||
public void setWindowSize(int windowSize) throws MathIllegalArgumentException {
|
||||
if (windowSize < 1) {
|
||||
if (windowSize != INFINITE_WINDOW) {
|
||||
throw new MathIllegalArgumentException(
|
||||
|
@ -406,10 +414,10 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
*
|
||||
* @param p the requested percentile (scaled from 0 - 100)
|
||||
* @return An estimate for the pth percentile of the stored data
|
||||
* @throws IllegalStateException if percentile implementation has been
|
||||
* @throws MathIllegalStateException if percentile implementation has been
|
||||
* overridden and the supplied implementation does not support setQuantile
|
||||
*/
|
||||
public double getPercentile(double p) {
|
||||
public double getPercentile(double p) throws MathIllegalStateException {
|
||||
if (percentileImpl instanceof Percentile) {
|
||||
((Percentile) percentileImpl).setQuantile(p);
|
||||
} else {
|
||||
|
@ -450,7 +458,11 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
outBuffer.append("mean: ").append(getMean()).append(endl);
|
||||
outBuffer.append("std dev: ").append(getStandardDeviation())
|
||||
.append(endl);
|
||||
outBuffer.append("median: ").append(getPercentile(50)).append(endl);
|
||||
try {
|
||||
outBuffer.append("median: ").append(getPercentile(50)).append(endl);
|
||||
} catch (MathIllegalStateException ex) {
|
||||
outBuffer.append("median: unavailable").append(endl);
|
||||
}
|
||||
outBuffer.append("skewness: ").append(getSkewness()).append(endl);
|
||||
outBuffer.append("kurtosis: ").append(getKurtosis()).append(endl);
|
||||
return outBuffer.toString();
|
||||
|
@ -462,6 +474,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
* @return the computed value of the statistic.
|
||||
*/
|
||||
public double apply(UnivariateStatistic stat) {
|
||||
// No try-catch or advertised exception here because arguments are guaranteed valid
|
||||
return stat.evaluate(eDA.getInternalValues(), eDA.start(), eDA.getNumElements());
|
||||
}
|
||||
|
||||
|
@ -590,12 +603,12 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
* <code>IllegalArgumentException</code> is thrown.
|
||||
*
|
||||
* @param percentileImpl the percentileImpl to set
|
||||
* @throws IllegalArgumentException if the supplied implementation does not
|
||||
* @throws MathIllegalArgumentException if the supplied implementation does not
|
||||
* provide a <code>setQuantile</code> method
|
||||
* @since 1.2
|
||||
*/
|
||||
public synchronized void setPercentileImpl(
|
||||
UnivariateStatistic percentileImpl) {
|
||||
public synchronized void setPercentileImpl(UnivariateStatistic percentileImpl)
|
||||
throws MathIllegalArgumentException {
|
||||
try {
|
||||
percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME,
|
||||
new Class[] {Double.TYPE}).invoke(percentileImpl,
|
||||
|
@ -707,6 +720,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
|||
*/
|
||||
public DescriptiveStatistics copy() {
|
||||
DescriptiveStatistics result = new DescriptiveStatistics();
|
||||
// No try-catch or advertised exception because parms are guaranteed valid
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ public class MultivariateSummaryStatistics
|
|||
* @throws DimensionMismatchException if the length of the array
|
||||
* does not match the one used at construction
|
||||
*/
|
||||
public void addValue(double[] value) {
|
||||
public void addValue(double[] value) throws DimensionMismatchException {
|
||||
checkDimension(value.length);
|
||||
for (int i = 0; i < k; ++i) {
|
||||
double v = value[i];
|
||||
|
@ -412,11 +412,12 @@ public class MultivariateSummaryStatistics
|
|||
* @param oldImpl old implementations for statistics
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e. if n > 0)
|
||||
*/
|
||||
private void setImpl(StorelessUnivariateStatistic[] newImpl,
|
||||
StorelessUnivariateStatistic[] oldImpl) {
|
||||
StorelessUnivariateStatistic[] oldImpl) throws MathIllegalStateException,
|
||||
DimensionMismatchException {
|
||||
checkEmpty();
|
||||
checkDimension(newImpl.length);
|
||||
System.arraycopy(newImpl, 0, oldImpl, 0, newImpl.length);
|
||||
|
@ -441,10 +442,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the Sum
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setSumImpl(StorelessUnivariateStatistic[] sumImpl) {
|
||||
public void setSumImpl(StorelessUnivariateStatistic[] sumImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException {
|
||||
setImpl(sumImpl, this.sumImpl);
|
||||
}
|
||||
|
||||
|
@ -467,10 +469,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the sum of squares
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setSumsqImpl(StorelessUnivariateStatistic[] sumsqImpl) {
|
||||
public void setSumsqImpl(StorelessUnivariateStatistic[] sumsqImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException {
|
||||
setImpl(sumsqImpl, this.sumSqImpl);
|
||||
}
|
||||
|
||||
|
@ -493,10 +496,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the minimum
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setMinImpl(StorelessUnivariateStatistic[] minImpl) {
|
||||
public void setMinImpl(StorelessUnivariateStatistic[] minImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException {
|
||||
setImpl(minImpl, this.minImpl);
|
||||
}
|
||||
|
||||
|
@ -519,10 +523,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the maximum
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setMaxImpl(StorelessUnivariateStatistic[] maxImpl) {
|
||||
public void setMaxImpl(StorelessUnivariateStatistic[] maxImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException{
|
||||
setImpl(maxImpl, this.maxImpl);
|
||||
}
|
||||
|
||||
|
@ -545,10 +550,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the log sum
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setSumLogImpl(StorelessUnivariateStatistic[] sumLogImpl) {
|
||||
public void setSumLogImpl(StorelessUnivariateStatistic[] sumLogImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException{
|
||||
setImpl(sumLogImpl, this.sumLogImpl);
|
||||
}
|
||||
|
||||
|
@ -571,10 +577,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the geometric mean
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setGeoMeanImpl(StorelessUnivariateStatistic[] geoMeanImpl) {
|
||||
public void setGeoMeanImpl(StorelessUnivariateStatistic[] geoMeanImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException {
|
||||
setImpl(geoMeanImpl, this.geoMeanImpl);
|
||||
}
|
||||
|
||||
|
@ -597,10 +604,11 @@ public class MultivariateSummaryStatistics
|
|||
* for computing the mean
|
||||
* @throws DimensionMismatchException if the array dimension
|
||||
* does not match the one used at construction
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setMeanImpl(StorelessUnivariateStatistic[] meanImpl) {
|
||||
public void setMeanImpl(StorelessUnivariateStatistic[] meanImpl)
|
||||
throws MathIllegalStateException, DimensionMismatchException{
|
||||
setImpl(meanImpl, this.meanImpl);
|
||||
}
|
||||
|
||||
|
@ -608,7 +616,7 @@ public class MultivariateSummaryStatistics
|
|||
* Throws MathIllegalStateException if the statistic is not empty.
|
||||
* @throws MathIllegalStateException if n > 0.
|
||||
*/
|
||||
private void checkEmpty() {
|
||||
private void checkEmpty() throws MathIllegalStateException {
|
||||
if (n > 0) {
|
||||
throw new MathIllegalStateException(
|
||||
LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, n);
|
||||
|
@ -620,7 +628,7 @@ public class MultivariateSummaryStatistics
|
|||
* @param dimension dimension to check
|
||||
* @throws DimensionMismatchException if dimension != k
|
||||
*/
|
||||
private void checkDimension(int dimension) {
|
||||
private void checkDimension(int dimension) throws DimensionMismatchException {
|
||||
if (dimension != k) {
|
||||
throw new DimensionMismatchException(dimension, k);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Extends the definition of {@link UnivariateStatistic} with
|
||||
* {@link #increment} and {@link #incrementAll(double[])} methods for adding
|
||||
|
@ -41,9 +43,9 @@ public interface StorelessUnivariateStatistic extends UnivariateStatistic {
|
|||
* i.e., the values are added <strong>incrementally</strong> to the dataset.
|
||||
*
|
||||
* @param values array holding the new values to add
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
void incrementAll(double[] values);
|
||||
void incrementAll(double[] values) throws MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Updates the internal state of the statistic to reflect addition of
|
||||
|
@ -54,9 +56,9 @@ public interface StorelessUnivariateStatistic extends UnivariateStatistic {
|
|||
* @param values array holding the new values to add
|
||||
* @param start the array index of the first value to add
|
||||
* @param length the number of elements to add
|
||||
* @throws IllegalArgumentException if the array is null or the index
|
||||
* @throws MathIllegalArgumentException if the array is null or the index
|
||||
*/
|
||||
void incrementAll(double[] values, int start, int length);
|
||||
void incrementAll(double[] values, int start, int length) throws MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns the current value of the Statistic.
|
||||
|
|
|
@ -127,8 +127,9 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* A copy constructor. Creates a deep-copy of the {@code original}.
|
||||
*
|
||||
* @param original the {@code SummaryStatistics} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public SummaryStatistics(SummaryStatistics original) {
|
||||
public SummaryStatistics(SummaryStatistics original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -423,11 +424,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param sumImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the Sum
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n >0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setSumImpl(StorelessUnivariateStatistic sumImpl) {
|
||||
public void setSumImpl(StorelessUnivariateStatistic sumImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.sumImpl = sumImpl;
|
||||
}
|
||||
|
@ -452,11 +453,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param sumsqImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the sum of squares
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl) {
|
||||
public void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.sumsqImpl = sumsqImpl;
|
||||
}
|
||||
|
@ -481,11 +482,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param minImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the minimum
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setMinImpl(StorelessUnivariateStatistic minImpl) {
|
||||
public void setMinImpl(StorelessUnivariateStatistic minImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.minImpl = minImpl;
|
||||
}
|
||||
|
@ -510,11 +511,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param maxImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the maximum
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setMaxImpl(StorelessUnivariateStatistic maxImpl) {
|
||||
public void setMaxImpl(StorelessUnivariateStatistic maxImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.maxImpl = maxImpl;
|
||||
}
|
||||
|
@ -539,11 +540,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param sumLogImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the log sum
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl) {
|
||||
public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.sumLogImpl = sumLogImpl;
|
||||
geoMean.setSumLogImpl(sumLogImpl);
|
||||
|
@ -569,11 +570,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param geoMeanImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the geometric mean
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl) {
|
||||
public void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.geoMeanImpl = geoMeanImpl;
|
||||
}
|
||||
|
@ -598,11 +599,11 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param meanImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the mean
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setMeanImpl(StorelessUnivariateStatistic meanImpl) {
|
||||
public void setMeanImpl(StorelessUnivariateStatistic meanImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.meanImpl = meanImpl;
|
||||
}
|
||||
|
@ -627,19 +628,20 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
* </p>
|
||||
* @param varianceImpl the StorelessUnivariateStatistic instance to use for
|
||||
* computing the variance
|
||||
* @throws IllegalStateException if data has already been added (i.e if n >
|
||||
* 0)
|
||||
* @throws MathIllegalStateException if data has already been added (i.e if n > 0)
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl) {
|
||||
public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.varianceImpl = varianceImpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws IllegalStateException if n > 0.
|
||||
* @throws MathIllegalStateException if data has been added
|
||||
*/
|
||||
private void checkEmpty() {
|
||||
private void checkEmpty() throws MathIllegalStateException {
|
||||
if (n > 0) {
|
||||
throw new MathIllegalStateException(
|
||||
LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, n);
|
||||
|
@ -653,6 +655,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
|
|||
*/
|
||||
public SummaryStatistics copy() {
|
||||
SummaryStatistics result = new SummaryStatistics();
|
||||
// No try-catch or advertised exception because arguments are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
|
||||
|
@ -41,14 +42,17 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics {
|
|||
* Construct an instance with infinite window
|
||||
*/
|
||||
public SynchronizedDescriptiveStatistics() {
|
||||
// no try-catch or advertized IAE because arg is valid
|
||||
this(INFINITE_WINDOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance with finite window
|
||||
* @param window the finite window size.
|
||||
* @throws MathIllegalArgumentException if window size is less than 1 but
|
||||
* not equal to {@link #INFINITE_WINDOW}
|
||||
*/
|
||||
public SynchronizedDescriptiveStatistics(int window) {
|
||||
public SynchronizedDescriptiveStatistics(int window) throws MathIllegalArgumentException {
|
||||
super(window);
|
||||
}
|
||||
|
||||
|
@ -56,8 +60,10 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics {
|
|||
* A copy constructor. Creates a deep-copy of the {@code original}.
|
||||
*
|
||||
* @param original the {@code SynchronizedDescriptiveStatistics} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public SynchronizedDescriptiveStatistics(SynchronizedDescriptiveStatistics original) {
|
||||
public SynchronizedDescriptiveStatistics(SynchronizedDescriptiveStatistics original)
|
||||
throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -129,7 +135,7 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setWindowSize(int windowSize) {
|
||||
public synchronized void setWindowSize(int windowSize) throws MathIllegalArgumentException {
|
||||
super.setWindowSize(windowSize);
|
||||
}
|
||||
|
||||
|
@ -151,6 +157,7 @@ public class SynchronizedDescriptiveStatistics extends DescriptiveStatistics {
|
|||
public synchronized SynchronizedDescriptiveStatistics copy() {
|
||||
SynchronizedDescriptiveStatistics result =
|
||||
new SynchronizedDescriptiveStatistics();
|
||||
// No try-catch or advertised exception because arguments are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math3.linear.RealMatrix;
|
||||
|
||||
/**
|
||||
|
@ -51,7 +53,7 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void addValue(double[] value) {
|
||||
public synchronized void addValue(double[] value) throws DimensionMismatchException {
|
||||
super.addValue(value);
|
||||
}
|
||||
|
||||
|
@ -187,7 +189,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSumImpl(StorelessUnivariateStatistic[] sumImpl) {
|
||||
public synchronized void setSumImpl(StorelessUnivariateStatistic[] sumImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException {
|
||||
super.setSumImpl(sumImpl);
|
||||
}
|
||||
|
||||
|
@ -203,7 +206,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSumsqImpl(StorelessUnivariateStatistic[] sumsqImpl) {
|
||||
public synchronized void setSumsqImpl(StorelessUnivariateStatistic[] sumsqImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException {
|
||||
super.setSumsqImpl(sumsqImpl);
|
||||
}
|
||||
|
||||
|
@ -219,7 +223,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setMinImpl(StorelessUnivariateStatistic[] minImpl) {
|
||||
public synchronized void setMinImpl(StorelessUnivariateStatistic[] minImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException {
|
||||
super.setMinImpl(minImpl);
|
||||
}
|
||||
|
||||
|
@ -235,7 +240,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setMaxImpl(StorelessUnivariateStatistic[] maxImpl) {
|
||||
public synchronized void setMaxImpl(StorelessUnivariateStatistic[] maxImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException{
|
||||
super.setMaxImpl(maxImpl);
|
||||
}
|
||||
|
||||
|
@ -251,7 +257,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSumLogImpl(StorelessUnivariateStatistic[] sumLogImpl) {
|
||||
public synchronized void setSumLogImpl(StorelessUnivariateStatistic[] sumLogImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException {
|
||||
super.setSumLogImpl(sumLogImpl);
|
||||
}
|
||||
|
||||
|
@ -267,7 +274,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setGeoMeanImpl(StorelessUnivariateStatistic[] geoMeanImpl) {
|
||||
public synchronized void setGeoMeanImpl(StorelessUnivariateStatistic[] geoMeanImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException {
|
||||
super.setGeoMeanImpl(geoMeanImpl);
|
||||
}
|
||||
|
||||
|
@ -283,7 +291,8 @@ public class SynchronizedMultivariateSummaryStatistics
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setMeanImpl(StorelessUnivariateStatistic[] meanImpl) {
|
||||
public synchronized void setMeanImpl(StorelessUnivariateStatistic[] meanImpl)
|
||||
throws DimensionMismatchException, MathIllegalStateException {
|
||||
super.setMeanImpl(meanImpl);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
|
||||
|
@ -48,8 +49,10 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* A copy constructor. Creates a deep-copy of the {@code original}.
|
||||
*
|
||||
* @param original the {@code SynchronizedSummaryStatistics} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public SynchronizedSummaryStatistics(SynchronizedSummaryStatistics original) {
|
||||
public SynchronizedSummaryStatistics(SynchronizedSummaryStatistics original)
|
||||
throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -193,7 +196,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSumImpl(StorelessUnivariateStatistic sumImpl) {
|
||||
public synchronized void setSumImpl(StorelessUnivariateStatistic sumImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setSumImpl(sumImpl);
|
||||
}
|
||||
|
||||
|
@ -209,7 +213,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl) {
|
||||
public synchronized void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setSumsqImpl(sumsqImpl);
|
||||
}
|
||||
|
||||
|
@ -225,7 +230,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setMinImpl(StorelessUnivariateStatistic minImpl) {
|
||||
public synchronized void setMinImpl(StorelessUnivariateStatistic minImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setMinImpl(minImpl);
|
||||
}
|
||||
|
||||
|
@ -241,7 +247,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setMaxImpl(StorelessUnivariateStatistic maxImpl) {
|
||||
public synchronized void setMaxImpl(StorelessUnivariateStatistic maxImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setMaxImpl(maxImpl);
|
||||
}
|
||||
|
||||
|
@ -257,7 +264,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl) {
|
||||
public synchronized void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setSumLogImpl(sumLogImpl);
|
||||
}
|
||||
|
||||
|
@ -273,7 +281,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl) {
|
||||
public synchronized void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setGeoMeanImpl(geoMeanImpl);
|
||||
}
|
||||
|
||||
|
@ -289,7 +298,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setMeanImpl(StorelessUnivariateStatistic meanImpl) {
|
||||
public synchronized void setMeanImpl(StorelessUnivariateStatistic meanImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setMeanImpl(meanImpl);
|
||||
}
|
||||
|
||||
|
@ -305,7 +315,8 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setVarianceImpl(StorelessUnivariateStatistic varianceImpl) {
|
||||
public synchronized void setVarianceImpl(StorelessUnivariateStatistic varianceImpl)
|
||||
throws MathIllegalStateException {
|
||||
super.setVarianceImpl(varianceImpl);
|
||||
}
|
||||
|
||||
|
@ -319,6 +330,7 @@ public class SynchronizedSummaryStatistics extends SummaryStatistics {
|
|||
public synchronized SynchronizedSummaryStatistics copy() {
|
||||
SynchronizedSummaryStatistics result =
|
||||
new SynchronizedSummaryStatistics();
|
||||
// No try-catch or advertised exception because arguments are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Base interface implemented by all statistics.
|
||||
|
@ -29,8 +31,9 @@ public interface UnivariateStatistic {
|
|||
*
|
||||
* @param values input array
|
||||
* @return the value of the statistic applied to the input array
|
||||
* @throws MathIllegalArgumentException if values is null
|
||||
*/
|
||||
double evaluate(double[] values);
|
||||
double evaluate(double[] values) throws MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns the result of evaluating the statistic over the specified entries
|
||||
|
@ -40,8 +43,9 @@ public interface UnivariateStatistic {
|
|||
* @param begin the index of the first element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the value of the statistic applied to the included array entries
|
||||
* @throws MathIllegalArgumentException if values is null or the indices are invalid
|
||||
*/
|
||||
double evaluate(double[] values, int begin, int length);
|
||||
double evaluate(double[] values, int begin, int length) throws MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns a copy of the statistic with the same internal state.
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.math3.stat.descriptive;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Weighted evaluation for statistics.
|
||||
*
|
||||
|
@ -31,8 +33,11 @@ public interface WeightedEvaluation {
|
|||
* @param values input array
|
||||
* @param weights array of weights
|
||||
* @return the value of the weighted statistic applied to the input array
|
||||
* @throws MathIllegalArgumentException if either array is null, lengths
|
||||
* do not match, weights contain NaN, negative or infinite values, or
|
||||
* weights does not include at least on positive value
|
||||
*/
|
||||
double evaluate(double[] values, double[] weights);
|
||||
double evaluate(double[] values, double[] weights) throws MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns the result of evaluating the statistic over the specified entries
|
||||
|
@ -43,7 +48,11 @@ public interface WeightedEvaluation {
|
|||
* @param begin the index of the first element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the value of the weighted statistic applied to the included array entries
|
||||
* @throws MathIllegalArgumentException if either array is null, lengths
|
||||
* do not match, indices are invalid, weights contain NaN, negative or
|
||||
* infinite values, or weights does not include at least on positive value
|
||||
*/
|
||||
double evaluate(double[] values, double[] weights, int begin, int length);
|
||||
double evaluate(double[] values, double[] weights, int begin, int length)
|
||||
throws MathIllegalArgumentException;
|
||||
|
||||
}
|
||||
|
|
|
@ -88,8 +88,9 @@ class FirstMoment extends AbstractStorelessUnivariateStatistic
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code FirstMoment} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public FirstMoment(FirstMoment original) {
|
||||
public FirstMoment(FirstMoment original) throws NullArgumentException {
|
||||
super();
|
||||
copy(original, this);
|
||||
}
|
||||
|
@ -141,6 +142,7 @@ class FirstMoment extends AbstractStorelessUnivariateStatistic
|
|||
@Override
|
||||
public FirstMoment copy() {
|
||||
FirstMoment result = new FirstMoment();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -74,8 +74,9 @@ class FourthMoment extends ThirdMoment implements Serializable{
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code FourthMoment} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public FourthMoment(FourthMoment original) {
|
||||
public FourthMoment(FourthMoment original) throws NullArgumentException {
|
||||
super();
|
||||
copy(original, this);
|
||||
}
|
||||
|
@ -126,6 +127,7 @@ class FourthMoment extends ThirdMoment implements Serializable{
|
|||
@Override
|
||||
public FourthMoment copy() {
|
||||
FourthMoment result = new FourthMoment();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.descriptive.moment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
|
@ -71,8 +72,9 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code GeometricMean} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public GeometricMean(GeometricMean original) {
|
||||
public GeometricMean(GeometricMean original) throws NullArgumentException {
|
||||
super();
|
||||
copy(original, this);
|
||||
}
|
||||
|
@ -91,6 +93,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
|
|||
@Override
|
||||
public GeometricMean copy() {
|
||||
GeometricMean result = new GeometricMean();
|
||||
// no try-catch or advertised exception because args guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
@ -136,12 +139,13 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
|
|||
* @param length the number of elements to include
|
||||
* @return the geometric mean or Double.NaN if length = 0 or
|
||||
* any of the values are <= 0.
|
||||
* @throws IllegalArgumentException if the input array is null or the array
|
||||
* @throws MathIllegalArgumentException if the input array is null or the array
|
||||
* index parameters are not valid
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(
|
||||
final double[] values, final int begin, final int length) {
|
||||
final double[] values, final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
return FastMath.exp(
|
||||
sumOfLogs.evaluate(values, begin, length) / length);
|
||||
}
|
||||
|
@ -161,11 +165,11 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
|
|||
*
|
||||
* @param sumLogImpl the StorelessUnivariateStatistic instance to use
|
||||
* for computing the log sum
|
||||
* @throws IllegalStateException if data has already been added
|
||||
* @throws MathIllegalStateException if data has already been added
|
||||
* (i.e if n > 0)
|
||||
*/
|
||||
public void setSumLogImpl(
|
||||
StorelessUnivariateStatistic sumLogImpl) {
|
||||
public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
|
||||
throws MathIllegalStateException {
|
||||
checkEmpty();
|
||||
this.sumOfLogs = sumLogImpl;
|
||||
}
|
||||
|
@ -197,9 +201,10 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
|
|||
|
||||
|
||||
/**
|
||||
* Throws IllegalStateException if n > 0.
|
||||
* Throws MathIllegalStateException if n > 0.
|
||||
* @throws MathIllegalStateException if data has been added to this statistic
|
||||
*/
|
||||
private void checkEmpty() {
|
||||
private void checkEmpty() throws MathIllegalStateException {
|
||||
if (getN() > 0) {
|
||||
throw new MathIllegalStateException(
|
||||
LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC,
|
||||
|
|
|
@ -18,9 +18,8 @@ package org.apache.commons.math3.stat.descriptive.moment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
|
@ -85,20 +84,22 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code Kurtosis} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public Kurtosis(Kurtosis original) {
|
||||
public Kurtosis(Kurtosis original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Note that when {@link #Kurtosis(FourthMoment)} is used to
|
||||
* create a Variance, this method does nothing. In that case, the
|
||||
* FourthMoment should be incremented directly.</p>
|
||||
*/
|
||||
@Override
|
||||
public void increment(final double d) {
|
||||
if (incMoment) {
|
||||
moment.increment(d);
|
||||
} else {
|
||||
throw new MathIllegalStateException(LocalizedFormats.CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,8 +131,6 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S
|
|||
public void clear() {
|
||||
if (incMoment) {
|
||||
moment.clear();
|
||||
} else {
|
||||
throw new MathIllegalStateException(LocalizedFormats.CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,13 +154,13 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S
|
|||
* @param values the input array
|
||||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the kurtosis of the values or Double.NaN if length is less than
|
||||
* 4
|
||||
* @throws IllegalArgumentException if the input array is null or the array
|
||||
* @return the kurtosis of the values or Double.NaN if length is less than 4
|
||||
* @throws MathIllegalArgumentException if the input array is null or the array
|
||||
* index parameters are not valid
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values,final int begin, final int length) {
|
||||
public double evaluate(final double[] values,final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
// Initialize the kurtosis
|
||||
double kurt = Double.NaN;
|
||||
|
||||
|
@ -201,6 +200,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S
|
|||
@Override
|
||||
public Kurtosis copy() {
|
||||
Kurtosis result = new Kurtosis();
|
||||
// No try-catch because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.descriptive.moment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic;
|
||||
import org.apache.commons.math3.stat.descriptive.WeightedEvaluation;
|
||||
|
@ -96,13 +97,17 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code Mean} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public Mean(Mean original) {
|
||||
public Mean(Mean original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Note that when {@link #Mean(FirstMoment)} is used to
|
||||
* create a Mean, this method does nothing. In that case, the
|
||||
* FirstMoment should be incremented directly.</p>
|
||||
*/
|
||||
@Override
|
||||
public void increment(final double d) {
|
||||
|
@ -149,11 +154,12 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the mean of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values,final int begin, final int length) {
|
||||
public double evaluate(final double[] values,final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
if (test(values, begin, length)) {
|
||||
Sum sum = new Sum();
|
||||
double sampleSize = length;
|
||||
|
@ -197,11 +203,11 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the mean of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
* @since 2.1
|
||||
*/
|
||||
public double evaluate(final double[] values, final double[] weights,
|
||||
final int begin, final int length) {
|
||||
final int begin, final int length) throws MathIllegalArgumentException {
|
||||
if (test(values, weights, begin, length)) {
|
||||
Sum sum = new Sum();
|
||||
|
||||
|
@ -222,13 +228,13 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
/**
|
||||
* Returns the weighted arithmetic mean of the entries in the input array.
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if either array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if either array is null.</p>
|
||||
* <p>
|
||||
* See {@link Mean} for details on the computing algorithm. The two-pass algorithm
|
||||
* described above is used here, with weights applied in computing both the original
|
||||
* estimate and the correction factor.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if any of the following are true:
|
||||
* Throws <code>MathIllegalArgumentException</code> if any of the following are true:
|
||||
* <ul><li>the values array is null</li>
|
||||
* <li>the weights array is null</li>
|
||||
* <li>the weights array does not have the same length as the values array</li>
|
||||
|
@ -240,10 +246,11 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
* @param values the input array
|
||||
* @param weights the weights array
|
||||
* @return the mean of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
* @since 2.1
|
||||
*/
|
||||
public double evaluate(final double[] values, final double[] weights) {
|
||||
public double evaluate(final double[] values, final double[] weights)
|
||||
throws MathIllegalArgumentException {
|
||||
return evaluate(values, weights, 0, values.length);
|
||||
}
|
||||
|
||||
|
@ -253,6 +260,7 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
@Override
|
||||
public Mean copy() {
|
||||
Mean result = new Mean();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -66,8 +66,10 @@ public class SecondMoment extends FirstMoment implements Serializable {
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code SecondMoment} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public SecondMoment(SecondMoment original) {
|
||||
public SecondMoment(SecondMoment original)
|
||||
throws NullArgumentException {
|
||||
super(original);
|
||||
this.m2 = original.m2;
|
||||
}
|
||||
|
@ -107,6 +109,7 @@ public class SecondMoment extends FirstMoment implements Serializable {
|
|||
@Override
|
||||
public SecondMoment copy() {
|
||||
SecondMoment result = new SecondMoment();
|
||||
// no try-catch or advertised NAE because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
package org.apache.commons.math3.stat.descriptive.moment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
|
||||
|
@ -133,8 +134,9 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code SemiVariance} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public SemiVariance(final SemiVariance original) {
|
||||
public SemiVariance(final SemiVariance original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -145,6 +147,7 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
|
|||
@Override
|
||||
public SemiVariance copy() {
|
||||
SemiVariance result = new SemiVariance();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
@ -167,25 +170,6 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
|
|||
dest.varianceDirection = source.varianceDirection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method calculates {@link SemiVariance} for the entire array against the mean, using
|
||||
* instance properties varianceDirection and biasCorrection.
|
||||
*
|
||||
* @param values the input array
|
||||
* @return the SemiVariance
|
||||
* @throws IllegalArgumentException if values is null
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values) {
|
||||
if (values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
}
|
||||
return evaluate(values, 0, values.length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns the {@link SemiVariance} of the designated values against the mean, using
|
||||
* instance properties varianceDirection and biasCorrection.</p>
|
||||
|
@ -197,11 +181,12 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
|
|||
* @param start index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the SemiVariance
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values, final int start, final int length) {
|
||||
public double evaluate(final double[] values, final int start, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
double m = (new Mean()).evaluate(values, start, length);
|
||||
return evaluate(values, m, varianceDirection, biasCorrected, 0, values.length);
|
||||
}
|
||||
|
@ -214,10 +199,11 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
|
|||
* @param values the input array
|
||||
* @param direction the {@link Direction} of the semivariance
|
||||
* @return the SemiVariance
|
||||
* @throws IllegalArgumentException if values is null
|
||||
* @throws MathIllegalArgumentException if values is null
|
||||
*
|
||||
*/
|
||||
public double evaluate(final double[] values, Direction direction) {
|
||||
public double evaluate(final double[] values, Direction direction)
|
||||
throws MathIllegalArgumentException {
|
||||
double m = (new Mean()).evaluate(values);
|
||||
return evaluate (values, m, direction, biasCorrected, 0, values.length);
|
||||
}
|
||||
|
@ -270,11 +256,11 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
|
|||
* @param start index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the SemiVariance
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
*
|
||||
*/
|
||||
public double evaluate (final double[] values, final double cutoff, final Direction direction,
|
||||
final boolean corrected, final int start, final int length) {
|
||||
final boolean corrected, final int start, final int length) throws MathIllegalArgumentException {
|
||||
|
||||
test(values, start, length);
|
||||
if (values.length == 0) {
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.descriptive.moment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
@ -78,13 +79,17 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code Skewness} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public Skewness(Skewness original) {
|
||||
public Skewness(Skewness original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Note that when {@link #Skewness(ThirdMoment)} is used to
|
||||
* create a Skewness, this method does nothing. In that case, the
|
||||
* ThirdMoment should be incremented directly.</p>
|
||||
*/
|
||||
@Override
|
||||
public void increment(final double d) {
|
||||
|
@ -146,12 +151,12 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* @param length the number of elements to include
|
||||
* @return the skewness of the values or Double.NaN if length is less than
|
||||
* 3
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values,final int begin,
|
||||
final int length) {
|
||||
final int length) throws MathIllegalArgumentException {
|
||||
|
||||
// Initialize the skewness
|
||||
double skew = Double.NaN;
|
||||
|
@ -195,6 +200,7 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se
|
|||
@Override
|
||||
public Skewness copy() {
|
||||
Skewness result = new Skewness();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.descriptive.moment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
@ -142,16 +143,16 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @return the standard deviation of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values) {
|
||||
public double evaluate(final double[] values) throws MathIllegalArgumentException {
|
||||
return FastMath.sqrt(variance.evaluate(values));
|
||||
}
|
||||
|
||||
|
@ -162,7 +163,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample. </p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
*
|
||||
|
@ -170,11 +171,12 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the standard deviation of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values, final int begin, final int length) {
|
||||
public double evaluate(final double[] values, final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
return FastMath.sqrt(variance.evaluate(values, begin, length));
|
||||
}
|
||||
|
||||
|
@ -199,11 +201,11 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the standard deviation of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public double evaluate(final double[] values, final double mean,
|
||||
final int begin, final int length) {
|
||||
final int begin, final int length) throws MathIllegalArgumentException {
|
||||
return FastMath.sqrt(variance.evaluate(values, mean, begin, length));
|
||||
}
|
||||
|
||||
|
@ -219,16 +221,17 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
* is supplied only to save computation when the mean has already been
|
||||
* computed.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @param mean the precomputed mean value
|
||||
* @return the standard deviation of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public double evaluate(final double[] values, final double mean) {
|
||||
public double evaluate(final double[] values, final double mean)
|
||||
throws MathIllegalArgumentException {
|
||||
return FastMath.sqrt(variance.evaluate(values, mean));
|
||||
}
|
||||
|
||||
|
@ -252,6 +255,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
@Override
|
||||
public StandardDeviation copy() {
|
||||
StandardDeviation result = new StandardDeviation();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -76,8 +76,9 @@ class ThirdMoment extends SecondMoment implements Serializable {
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code ThirdMoment} instance to copy
|
||||
* @throws NullArgumentException if orginal is null
|
||||
*/
|
||||
public ThirdMoment(ThirdMoment original) {
|
||||
public ThirdMoment(ThirdMoment original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -121,6 +122,7 @@ class ThirdMoment extends SecondMoment implements Serializable {
|
|||
@Override
|
||||
public ThirdMoment copy() {
|
||||
ThirdMoment result = new ThirdMoment();
|
||||
// No try-catch or advertised exception because args are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.commons.math3.stat.descriptive.moment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.stat.descriptive.WeightedEvaluation;
|
||||
|
@ -146,8 +147,9 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* to the {@code original}
|
||||
*
|
||||
* @param original the {@code Variance} instance to copy
|
||||
* @throws NullArgumentException if original is null
|
||||
*/
|
||||
public Variance(Variance original) {
|
||||
public Variance(Variance original) throws NullArgumentException {
|
||||
copy(original, this);
|
||||
}
|
||||
|
||||
|
@ -214,16 +216,16 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @return the variance of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values) {
|
||||
public double evaluate(final double[] values) throws MathIllegalArgumentException {
|
||||
if (values == null) {
|
||||
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
|
||||
}
|
||||
|
@ -241,17 +243,18 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the variance of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
@Override
|
||||
public double evaluate(final double[] values, final int begin, final int length) {
|
||||
public double evaluate(final double[] values, final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
|
||||
double var = Double.NaN;
|
||||
|
||||
|
@ -300,18 +303,18 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if either array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if either array is null.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @param weights the weights array
|
||||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the weighted variance of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
* @since 2.1
|
||||
*/
|
||||
public double evaluate(final double[] values, final double[] weights,
|
||||
final int begin, final int length) {
|
||||
final int begin, final int length) throws MathIllegalArgumentException {
|
||||
|
||||
double var = Double.NaN;
|
||||
|
||||
|
@ -347,7 +350,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if any of the following are true:
|
||||
* Throws <code>MathIllegalArgumentException</code> if any of the following are true:
|
||||
* <ul><li>the values array is null</li>
|
||||
* <li>the weights array is null</li>
|
||||
* <li>the weights array does not have the same length as the values array</li>
|
||||
|
@ -358,15 +361,16 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if either array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if either array is null.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @param weights the weights array
|
||||
* @return the weighted variance of the values
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
* @since 2.1
|
||||
*/
|
||||
public double evaluate(final double[] values, final double[] weights) {
|
||||
public double evaluate(final double[] values, final double[] weights)
|
||||
throws MathIllegalArgumentException {
|
||||
return evaluate(values, weights, 0, values.length);
|
||||
}
|
||||
|
||||
|
@ -384,7 +388,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
*
|
||||
|
@ -393,11 +397,11 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the variance of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the array is null or the array index
|
||||
* @throws MathIllegalArgumentException if the array is null or the array index
|
||||
* parameters are not valid
|
||||
*/
|
||||
public double evaluate(final double[] values, final double mean,
|
||||
final int begin, final int length) {
|
||||
final int begin, final int length) throws MathIllegalArgumentException {
|
||||
|
||||
double var = Double.NaN;
|
||||
|
||||
|
@ -440,16 +444,16 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if the array is null.</p>
|
||||
* Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
|
||||
* <p>
|
||||
* Does not change the internal state of the statistic.</p>
|
||||
*
|
||||
* @param values the input array
|
||||
* @param mean the precomputed mean value
|
||||
* @return the variance of the values or Double.NaN if the array is empty
|
||||
* @throws IllegalArgumentException if the array is null
|
||||
* @throws MathIllegalArgumentException if the array is null
|
||||
*/
|
||||
public double evaluate(final double[] values, final double mean) {
|
||||
public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException {
|
||||
return evaluate(values, mean, 0, values.length);
|
||||
}
|
||||
|
||||
|
@ -477,7 +481,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if any of the following are true:
|
||||
* Throws <code>MathIllegalArgumentException</code> if any of the following are true:
|
||||
* <ul><li>the values array is null</li>
|
||||
* <li>the weights array is null</li>
|
||||
* <li>the weights array does not have the same length as the values array</li>
|
||||
|
@ -495,11 +499,12 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* @param begin index of the first array element to include
|
||||
* @param length the number of elements to include
|
||||
* @return the variance of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
* @since 2.1
|
||||
*/
|
||||
public double evaluate(final double[] values, final double[] weights,
|
||||
final double mean, final int begin, final int length) {
|
||||
final double mean, final int begin, final int length)
|
||||
throws MathIllegalArgumentException {
|
||||
|
||||
double var = Double.NaN;
|
||||
|
||||
|
@ -554,7 +559,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* <p>
|
||||
* Returns 0 for a single-value (i.e. length = 1) sample.</p>
|
||||
* <p>
|
||||
* Throws <code>IllegalArgumentException</code> if any of the following are true:
|
||||
* Throws <code>MathIllegalArgumentException</code> if any of the following are true:
|
||||
* <ul><li>the values array is null</li>
|
||||
* <li>the weights array is null</li>
|
||||
* <li>the weights array does not have the same length as the values array</li>
|
||||
|
@ -569,10 +574,11 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
* @param weights the weights array
|
||||
* @param mean the precomputed weighted mean value
|
||||
* @return the variance of the values or Double.NaN if length = 0
|
||||
* @throws IllegalArgumentException if the parameters are not valid
|
||||
* @throws MathIllegalArgumentException if the parameters are not valid
|
||||
* @since 2.1
|
||||
*/
|
||||
public double evaluate(final double[] values, final double[] weights, final double mean) {
|
||||
public double evaluate(final double[] values, final double[] weights, final double mean)
|
||||
throws MathIllegalArgumentException {
|
||||
return evaluate(values, weights, mean, 0, values.length);
|
||||
}
|
||||
|
||||
|
@ -596,6 +602,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
|
|||
@Override
|
||||
public Variance copy() {
|
||||
Variance result = new Variance();
|
||||
// No try-catch or advertised exception because parameters are guaranteed non-null
|
||||
copy(this, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class VectorialMean implements Serializable {
|
|||
* @param v vector to add
|
||||
* @throws DimensionMismatchException if the vector does not have the right dimension
|
||||
*/
|
||||
public void increment(double[] v) {
|
||||
public void increment(double[] v) throws DimensionMismatchException {
|
||||
if (v.length != means.length) {
|
||||
throw new DimensionMismatchException(v.length, means.length);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue