psteitz 2004/07/04 15:03:03
Modified: math/src/java/org/apache/commons/math/stat/univariate
StorelessUnivariateStatistic.java
AbstractStorelessUnivariateStatistic.java
Log:
Added incrementAll(double[]) methods.
Revision Changes Path
1.17 +27 -3
jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/StorelessUnivariateStatistic.java
Index: StorelessUnivariateStatistic.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/StorelessUnivariateStatistic.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- StorelessUnivariateStatistic.java 23 Jun 2004 16:26:16 -0000 1.16
+++ StorelessUnivariateStatistic.java 4 Jul 2004 22:03:03 -0000 1.17
@@ -16,8 +16,9 @@
package org.apache.commons.math.stat.univariate;
/**
- * Extends the definition of [EMAIL PROTECTED] UnivariateStatistic} with an [EMAIL
PROTECTED] #increment}
- * method for adding values and updating internal state incrementally.
+ * Extends the definition of [EMAIL PROTECTED] UnivariateStatistic} with
+ * [EMAIL PROTECTED] #increment} and [EMAIL PROTECTED] #incrementAll(double[])}
methods for adding
+ * values and updating internal state.
* <p>
* This interface is designed to be used for calculating statistics that can be
computed in
* one pass through the data without storing the full array of sample values.
@@ -31,6 +32,29 @@
* @param d the new value.
*/
void increment(double d);
+
+ /**
+ * Updates the internal state of the statistic to reflect addition of
+ * all values in the values array. Does not clear the statistic first --
+ * i.e., the values are added <strong>incrementally</stong> to the dataset.
+ *
+ * @param values array holding the new values to add
+ * @throws IllegalArgumentException if the array is null
+ */
+ void incrementAll(double[] values);
+
+ /**
+ * Updates the internal state of the statistic to reflect addition of
+ * the values in the designated portion of the values array. Does not
+ * clear the statistic first -- i.e., the values are added
+ * <strong>incrementally</stong> to the dataset.
+ *
+ * @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
+ */
+ void incrementAll(double[] values, int start, int length);
/**
* Returns the current value of the Statistic.
1.18 +81 -12
jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java
Index: AbstractStorelessUnivariateStatistic.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- AbstractStorelessUnivariateStatistic.java 23 Jun 2004 16:26:16 -0000 1.17
+++ AbstractStorelessUnivariateStatistic.java 4 Jul 2004 22:03:03 -0000 1.18
@@ -22,7 +22,10 @@
*
* Abstract Implementation for the [EMAIL PROTECTED] StorelessUnivariateStatistic}
interface.
* <p>
- * Provides a default <code>evaluate()</code> implementation.
+ * Provides default <code>evaluate()</code> and <code>incrementAll(double[])<code>
+ * implementations.
+ * <p>
+ * <strong>Note that these implementations are not synchronized.</strong>
*
* @version $Revision$ $Date$
*/
@@ -34,21 +37,49 @@
static final long serialVersionUID = -44915725420072521L;
/**
- * This default implementation just calls [EMAIL PROTECTED] #increment} in a
loop over the input array and
- * then [EMAIL PROTECTED] #getResult} to compute the return value.
+ * This default implementation calls [EMAIL PROTECTED] #clear}, then invokes
+ * [EMAIL PROTECTED] #increment} in a loop over the the input array, and then
uses
+ * [EMAIL PROTECTED] #getResult} to compute the return value.
* <p>
- * Most implementations will override this method with a more efficient
implementation that works
- * directly with the input array.
+ * Note that this implementation changes the internal state of the
+ * statistic. Its side effects are the same as invoking [EMAIL PROTECTED]
#clear} and
+ * then [EMAIL PROTECTED] #incrementAll(double[])}.
+ * <p>
+ * Implementations may override this method with a more efficient
+ * implementation that works directly with the input array.
+ * <p>
+ * If the array is null, an IllegalArgumentException is thrown.
+ *
+ * @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[])
+ */
+ public double evaluate(final double[] values) {
+ if (values == null) {
+ throw new IllegalArgumentException("input value array is null");
+ }
+ return evaluate(values, 0, values.length);
+ }
+
+ /**
+ * This default implementation calls [EMAIL PROTECTED] #clear}, then invokes
+ * [EMAIL PROTECTED] #increment} in a loop over the specified portion of the
input
+ * array, and then uses [EMAIL PROTECTED] #getResult} to compute the return
value.
+ * <p>
+ * Note that this implementation changes the internal state of the
+ * statistic. Its side effects are the same as invoking [EMAIL PROTECTED]
#clear} and
+ * then [EMAIL PROTECTED] #incrementAll(double[], int, int)}.
+ * <p>
+ * Implementations may override this method with a more efficient
+ * implementation that works directly with the input array.
+ * <p>
+ * If the array is null or the index parameters are not valid, an
+ * IllegalArgumentException is thrown.
*
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
public double evaluate(final double[] values, final int begin, final int
length) {
- if (this.test(values, begin, length)) {
- this.clear();
- int l = begin + length;
- for (int i = begin; i < l; i++) {
- increment(values[i]);
- }
+ if (test(values, begin, length)) {
+ clear();
+ incrementAll(values, begin, length);
}
return getResult();
}
@@ -67,6 +98,44 @@
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
public abstract void increment(final double d);
+
+ /**
+ * This default implementation just calls [EMAIL PROTECTED] #increment} in a
loop over
+ * the input array.
+ * <p>
+ * Throws IllegalArgumentException if the input values array is null.
+ *
+ * @param values values to add
+ * @throws IllegalArgumentException if values is null
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#incrementAll(double[])
+ */
+ public void incrementAll(double[] values) {
+ if (values == null) {
+ throw new IllegalArgumentException("input values array is null");
+ }
+ incrementAll(values, 0, values.length);
+ }
+
+ /**
+ * This default implementation just calls [EMAIL PROTECTED] #increment} in a
loop over
+ * the specified portion of the input array.
+ * <p>
+ * Throws IllegalArgumentException if the input values array is null.
+ *
+ * @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
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#incrementAll(double[],
int, int)
+ */
+ public void incrementAll(double[] values, int begin, int length) {
+ if (test(values, begin, length)) {
+ int k = begin + length;
+ for (int i = begin; i < k; i++) {
+ increment(values[i]);
+ }
+ }
+ }
/**
* Returns true iff <code>object</code> is an
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]