Bugzilla #22002: applied Brent W's patch which dealt with URSFactory and URSFImpl as well as numerous improvements to javadoc

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140988 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim O'Brien 2003-07-30 21:58:11 +00:00
parent 2f4e703627
commit 233420ee6b
13 changed files with 112 additions and 232 deletions

View File

@ -118,7 +118,7 @@ The Math project is a library of lightweight, self-contained mathematics and sta
<report>maven-license-plugin</report>
<!-- <report>maven-linkcheck-plugin</report> -->
<report>maven-statcvs-plugin</report>
<!-- <report>maven-tasklist-plugin</report> -->
<report>maven-tasklist-plugin</report>
</reports>
</project>

View File

@ -56,18 +56,19 @@ package org.apache.commons.math;
/**
* Signals a configuration problem with any of the factory methods.
*
* @version $Revision: 1.4 $ $Date: 2003/07/09 20:02:44 $
* @version $Revision: 1.5 $ $Date: 2003/07/30 21:58:10 $
*/
public class MathConfigurationException extends MathException {
/**
*
* Default constructor.
*/
public MathConfigurationException() {
super();
}
/**
* Construct an exception with the given message.
* @param message message describing the problem
*/
public MathConfigurationException(String message) {
@ -75,6 +76,7 @@ public class MathConfigurationException extends MathException {
}
/**
* Construct an exception with the given message and root cause.
* @param message message describing the problem
* @param throwable caught exception causing this problem
*/
@ -83,10 +85,10 @@ public class MathConfigurationException extends MathException {
}
/**
* Construct an exception with the given root cause.
* @param throwable caught exception causing this problem
*/
public MathConfigurationException(Throwable throwable) {
super(throwable);
}
}

View File

@ -56,29 +56,35 @@ package org.apache.commons.math.analysis;
/**
* Computes a natural spline interpolation for the data set.
*
* @version $Revision: 1.2 $ $Date: 2003/07/09 20:02:43 $
* @version $Revision: 1.3 $ $Date: 2003/07/30 21:58:10 $
*
*/
public class SplineInterpolator implements UnivariateRealInterpolator {
private double[][] c = null ;
private double[][] c = null;
/* (non-Javadoc)
* @see org.apache.commons.math.UnivariateRealInterpolator#interpolate(double[], double[])
/**
* Computes an interpolating function for the data set.
* @param xval the arguments for the interpolation points
* @param yval the values for the interpolation points
* @return a function which interpolates the data set
* @throws MathException if arguments violate assumptions made by the
* interpolationg algorithm
*/
public UnivariateRealFunction interpolate(double[] xval, double[] yval) {
if (xval.length != yval.length) {
throw new IllegalArgumentException("Dataset arrays must have same length.");
throw new IllegalArgumentException(
"Dataset arrays must have same length.");
}
if ( c == null )
{
if (c == null) {
// Number of intervals. The number of data points is N+1.
int n = xval.length - 1;
// Check whether the xval vector has ascending values.
// Separation should be checked too (not implemented: which criteria?).
for (int i = 0; i < n; i++) {
if (xval[i]>=xval[i+1]) {
throw new IllegalArgumentException("Dataset must specify sorted, ascending x values.");
if (xval[i] >= xval[i + 1]) {
throw new IllegalArgumentException(
"Dataset must specify sorted, ascending x values.");
}
}
// Vectors for the equation system. There are n-1 equations for the unknowns s[i] (1<=i<=N-1),
@ -104,10 +110,9 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
// (yval[i + 2] - yval[i + 1]) / (xval[i + 2] - xval[i + 1])
// take it from the previous loop pass. Note: the interesting part of performance
// loss is the range check in the array access, not the computation itself.
b[i] =
6.0
* ((yval[i + 2] - yval[i + 1]) / (xval[i + 2] - xval[i + 1])
- (yval[i + 1] - yval[i]) / (xval[i + 1] - xval[i]));
b[i] = 6.0 * ((yval[i + 2] - yval[i + 1]) / (xval[i + 2] -
xval[i + 1]) - (yval[i + 1] - yval[i]) / (xval[i + 1] -
xval[i]));
d[i] = 2.0 * (xval[i + 2] - xval[i]);
}
// Set up upper and lower diagonal. Keep the offsets in mind.
@ -132,26 +137,21 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
c = new double[n][4];
c[0][3] = d[0] / (xval[1] - xval[0]) / 6.0;
c[0][2] = 0.0;
c[0][1] =
(yval[1] - yval[0]) / (xval[1] - xval[0])
- d[0] * (xval[1] - xval[0]) / 6.0;
c[0][1] = (yval[1] - yval[0]) / (xval[1] - xval[0]) - d[0] *
(xval[1] - xval[0]) / 6.0;
for (int i = 1; i < n - 2; i++) {
// TODO: This relies on compiler for CSE of xval[i + 1] - xval[i]. Is this a reasonable assumption?
c[i][3] = (d[i] - d[i - 1]) / (xval[i + 1] - xval[i]) / 6.0;
c[i][2] = d[i - 1] / 2.0;
c[i][1] =
(yval[i + 1] - yval[i]) / (xval[i + 1] - xval[i])
- d[i] * (xval[i + 1] - xval[i]) / 6.0
- d[i
- 1] * (xval[i + 1] - xval[i]) / 3.0;
c[i][1] = (yval[i + 1] - yval[i]) / (xval[i + 1] - xval[i]) -
d[i] * (xval[i + 1] - xval[i]) / 6.0 - d[i - 1] *
(xval[i + 1] - xval[i]) / 3.0;
}
// TODO: again, CSE aspects.
c[n - 1][3] = -d[n - 2] / (xval[n] - xval[n - 1]) / 6.0;
c[n - 1][2] = d[n - 2] / 2.0;
c[n - 1][1] =
(yval[n] - yval[n - 1]) / (xval[n] - xval[n - 1])
- d[n
- 2] * (xval[n] - xval[n - 1]) / 3.0;
c[n - 1][1] = (yval[n] - yval[n - 1]) / (xval[n] - xval[n - 1]) -
d[n - 2] * (xval[n] - xval[n - 1]) / 3.0;
for (int i = 0; i < n; i++) {
c[i][0] = yval[i];
}

View File

@ -62,7 +62,7 @@ import org.apache.commons.math.MathException;
* that derivatives are evaluated after the value, the evaluation algorithm
* should throw an InvalidStateException if it can't cope with this.
*
* @version $Revision: 1.3 $ $Date: 2003/07/11 15:59:14 $
* @version $Revision: 1.4 $ $Date: 2003/07/30 21:58:10 $
*/
public interface UnivariateRealFunction {
/**
@ -71,8 +71,6 @@ public interface UnivariateRealFunction {
* @return the value
* @throws MathException if the function couldn't be computed due to
* missing additional data or other environmental problems.
* @throws RuntimeException if the operation isn't supported, the argument
* was outside the supported domain or any other problem.
*/
public double value(double x) throws MathException;
@ -85,8 +83,6 @@ public interface UnivariateRealFunction {
* @param x the point for which the first derivative should be computed
* @return the value
* @throws MathException if the derivative couldn't be computed.
* @throws RuntimeException if the operation isn't supported, the argument
* was outside the supported domain or any other problem.
*/
public double firstDerivative(double x) throws MathException;
@ -99,8 +95,6 @@ public interface UnivariateRealFunction {
* @param x the point for which the first derivative should be computed
* @return the value
* @throws MathException if the second derivative couldn't be computed.
* @throws RuntimeException if the operation isn't supported, the argument
* was outside the supported domain or any other problem.
*/
public double secondDerivative(double x) throws MathException;
}

View File

@ -53,11 +53,6 @@
*/
package org.apache.commons.math.analysis;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.math.MathConfigurationException;
import org.apache.commons.math.MathException;
/**
* A factory to easily get a default solver and some convenience
* functions.
@ -66,106 +61,58 @@ import org.apache.commons.math.MathException;
* (this may be controversial, because the configuration data
* may also be used for the default solver used by the static
* solve() method).
* @version $Revision: 1.3 $ $Date: 2003/07/11 15:59:14 $
* @version $Revision: 1.4 $ $Date: 2003/07/30 21:58:10 $
*/
public class UnivariateRealSolverFactory {
public abstract class UnivariateRealSolverFactory {
/**
* Default constructor.
*/
private UnivariateRealSolverFactory() {
protected UnivariateRealSolverFactory() {
}
/**
* @return a new factory.
* @todo add comment
* @todo for now, return the only concrete factory. Later, allow for a
* plugable implementation, possibly using SPI and commons-discovery.
*/
public static UnivariateRealSolverFactory newInstance() {
return new UnivariateRealSolverFactoryImpl();
}
/**
* Create a new {@link UnivariateRealSolver} for the given function. The
* actual solver returned can be controlled by defining the
* <code>org.apache.commons.math.analysis.UnivariateRealSolver</code>
* property on the JVM command-line (<code>
* -Dorg.apache.commons.math.analysis.UnivariateRealSolver=
* <i>class name</i></code>). The value of the property should be any,
* fully qualified class name for a type that implements the
* {@link UnivariateRealSolver} interface. By default, an instance of
* {@link BrentSolver} is returned.
* actual solver returned is determined by the underlying factory.
* @param f the function.
* @return the new solver.
* @throws MathConfigurationException if a
*/
public static UnivariateRealSolver newSolver(UnivariateRealFunction f)
throws MathConfigurationException {
String solverClassName =
System.getProperty(
"org.apache.commons.math.analysis.UnivariateRealSolver",
"org.apache.commons.math.analysis.BrentSolver");
try {
Class clazz = Class.forName(solverClassName);
Class paramClass[] = new Class[1];
paramClass[0] = UnivariateRealFunction.class;
Object param[] = new Object[1];
param[0] = f;
return (UnivariateRealSolver)clazz.getConstructor(
paramClass).newInstance(
param);
} catch (IllegalArgumentException e) {
throw new MathConfigurationException(e);
} catch (SecurityException e) {
throw new MathConfigurationException(
"Can't access " + solverClassName,
e);
} catch (ClassNotFoundException e) {
throw new MathConfigurationException(
"Class not found: " + solverClassName,
e);
} catch (InstantiationException e) {
throw new MathConfigurationException(
"Can't instantiate " + solverClassName,
e);
} catch (IllegalAccessException e) {
throw new MathConfigurationException(
"Can't access " + solverClassName,
e);
} catch (InvocationTargetException e) {
throw new MathConfigurationException(e);
} catch (NoSuchMethodException e) {
throw new MathConfigurationException(
"No constructor with UnivariateRealFunction in " +
solverClassName,
e);
}
}
public abstract UnivariateRealSolver newDefaultSolver(
UnivariateRealFunction f);
/**
* Convience method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* Create a new {@link UnivariateRealSolver} for the given function. The
* solver is an implementation of the bisection method.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
* @return the new solver.
*/
public static double solve(UnivariateRealFunction f, double x0, double x1)
throws MathException {
return newSolver(f).solve(x0, x1);
}
public abstract UnivariateRealSolver newBisectionSolver(
UnivariateRealFunction f);
/**
* Convience method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* Create a new {@link UnivariateRealSolver} for the given function. The
* solver is an implementation of the Brent method.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @param absoluteAccuracy the accuracy to be used by the solver.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
* @return the new solver.
*/
public static double solve(
UnivariateRealFunction f,
double x0,
double x1,
double absoluteAccuracy)
throws MathException {
UnivariateRealSolver solver = newSolver(f);
solver.setAbsoluteAccuracy(absoluteAccuracy);
return solver.solve(x0, x1);
}
public abstract UnivariateRealSolver newBrentSolver(
UnivariateRealFunction f);
/**
* Create a new {@link UnivariateRealSolver} for the given function. The
* solver is an implementation of the secant method.
* @param f the function.
* @return the new solver.
*/
public abstract UnivariateRealSolver newSecantSolver(
UnivariateRealFunction f);
}

View File

@ -56,14 +56,14 @@ package org.apache.commons.math.stat.distribution;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.RootFinding;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.UnivariateRealSolverFactory;
import org.apache.commons.math.analysis.UnivariateRealSolverUtil;
/**
* Base class for various continuous distributions. It provides default
* implementations for some of the methods that do not vary from distribution
* to distribution.
*
* @version $Revision: 1.7 $ $Date: 2003/07/09 20:03:23 $
* @version $Revision: 1.8 $ $Date: 2003/07/30 21:58:11 $
*/
public abstract class AbstractContinuousDistribution
implements ContinuousDistribution {
@ -126,7 +126,7 @@ public abstract class AbstractContinuousDistribution
getDomainUpperBound(p));
// find root
double root = UnivariateRealSolverFactory.solve(
double root = UnivariateRealSolverUtil.solve(
rootFindingFunction, bracket[0], bracket[1]);
return root;

View File

@ -70,7 +70,7 @@ package org.apache.commons.math.stat.distribution;
* ChiSquaredDistribution chi = factory.createChiSquareDistribution(5.0);
* </pre>
*
* @version $Revision: 1.8 $ $Date: 2003/07/09 20:03:22 $
* @version $Revision: 1.9 $ $Date: 2003/07/30 21:58:11 $
*/
public abstract class DistributionFactory {
/**
@ -83,11 +83,10 @@ public abstract class DistributionFactory {
/**
* Create an instance of a <code>DistributionFactory</code>
* @return a new factory.
* @todo for now, return the only concrete factory. Later, allow for a
* plugable implementation, possibly using SPI and commons-discovery.
*/
public static DistributionFactory newInstance() {
// for now, return the only concrete factory.
// later, allow for a plugable implementation, possible using SPI and
// commons-discovery.
return new DistributionFactoryImpl();
}

View File

@ -78,7 +78,7 @@ import java.io.Serializable;
* explicitly invoke <code>LUDecompose()</code> to recompute the decomposition
* before using any of the methods above.
*
* @version $Revision: 1.3 $ $Date: 2003/07/07 23:19:22 $
* @version $Revision: 1.4 $ $Date: 2003/07/30 21:58:10 $
*/
public class RealMatrixImpl implements RealMatrix, Serializable {
@ -384,8 +384,9 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
*/
public double getEntry(int row, int column)
throws IllegalArgumentException {
if (row < 1 || column < 1 || row > this.getRowDimension()
|| column > this.getColumnDimension()) {
if (row < 1 || column < 1 || row > this.getRowDimension() ||
column > this.getColumnDimension()) {
throw new IllegalArgumentException
("matrix entry does not exist");
}
@ -400,8 +401,9 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
*/
public void setEntry(int row, int column, double value)
throws IllegalArgumentException {
if (row < 1 || column < 1 || row > this.getRowDimension()
|| column > this.getColumnDimension()) {
if (row < 1 || column < 1 || row > this.getRowDimension() ||
column > this.getColumnDimension()) {
throw new IllegalArgumentException
("matrix entry does not exist");
}
@ -587,7 +589,6 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
}
int nCol = this.getColumnDimension();
int nRow = this.getRowDimension();
int nColB = b.getColumnDimension();
int nRowB = b.getRowDimension();

View File

@ -59,7 +59,7 @@ import org.apache.commons.math.util.ContinuedFraction;
* This is a utility class that provides computation methods related to the
* Beta family of functions.
*
* @version $Revision: 1.7 $ $Date: 2003/07/09 20:03:09 $
* @version $Revision: 1.8 $ $Date: 2003/07/30 21:58:10 $
*/
public class Beta {
/** Maximum allowed numerical error. */
@ -143,8 +143,8 @@ public class Beta {
double ret;
if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b) || (x < 0)
|| (x > 1) || (a <= 0.0) || (b <= 0.0)) {
if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b) || (x < 0) ||
(x > 1) || (a <= 0.0) || (b <= 0.0)) {
ret = Double.NaN;
} else {
ContinuedFraction fraction = new ContinuedFraction() {
@ -158,15 +158,12 @@ public class Beta {
default :
if (n % 2 == 0) { // even
m = (n - 2.0) / 2.0;
ret =
-((a + m) * (a + b + m) * x)
/ ((a + (2 * m))
* (a + (2 * m) + 1.0));
ret = -((a + m) * (a + b + m) * x) /
((a + (2 * m)) * (a + (2 * m) + 1.0));
} else {
m = (n - 1.0) / 2.0;
ret =
(m * (b - m) * x)
/ ((a + (2 * m) - 1) * (a + (2 * m)));
ret = (m * (b - m) * x) /
((a + (2 * m) - 1) * (a + (2 * m)));
}
break;
}
@ -186,9 +183,9 @@ public class Beta {
return ret;
}
};
ret = Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x))
- Math.log(a) - logBeta(a, b, epsilon, maxIterations))
* fraction.evaluate(x, epsilon, maxIterations);
ret = Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x)) -
Math.log(a) - logBeta(a, b, epsilon, maxIterations)) *
fraction.evaluate(x, epsilon, maxIterations);
}
return ret;
@ -230,8 +227,8 @@ public class Beta {
if (Double.isNaN(a) || Double.isNaN(b) || (a <= 0.0) || (b <= 0.0)) {
ret = Double.NaN;
} else {
ret = Gamma.logGamma(a) + Gamma.logGamma(b)
- Gamma.logGamma(a + b);
ret = Gamma.logGamma(a) + Gamma.logGamma(b) -
Gamma.logGamma(a + b);
}
return ret;

View File

@ -59,7 +59,7 @@ import org.apache.commons.math.analysis.ConvergenceException;
* This is a utility class that provides computation methods related to the
* Gamma family of functions.
*
* @version $Revision: 1.9 $ $Date: 2003/07/09 20:03:09 $
* @version $Revision: 1.10 $ $Date: 2003/07/30 21:58:10 $
*/
public class Gamma {
/** Maximum allowed numerical error. */
@ -156,10 +156,7 @@ public class Gamma {
throw new ConvergenceException(
"maximum number of iterations reached");
} else {
ret = Math.exp(-x +
(a * Math.log(x)) -
logGamma(a))
* sum;
ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * sum;
}
}
@ -198,8 +195,8 @@ public class Gamma {
sum = sum + lanczos[0];
double tmp = x + g + .5;
ret = ((x + .5) * Math.log(tmp)) - tmp
+ (.5 * Math.log(2.0 * Math.PI)) + Math.log(sum) - Math.log(x);
ret = ((x + .5) * Math.log(tmp)) - tmp +
(.5 * Math.log(2.0 * Math.PI)) + Math.log(sum) - Math.log(x);
}
return ret;

View File

@ -59,7 +59,7 @@ package org.apache.commons.math.stat.univariate;
* Provides the ability to extend polymophically so that
* indiviual statistics do not need to implement these methods unless
* there are better algorithms for handling the calculation.
* @version $Revision: 1.5 $ $Date: 2003/07/15 03:37:10 $
* @version $Revision: 1.6 $ $Date: 2003/07/30 21:58:11 $
*/
public abstract class AbstractStorelessUnivariateStatistic
extends AbstractUnivariateStatistic
@ -77,7 +77,7 @@ public abstract class AbstractStorelessUnivariateStatistic
if (this.test(values, begin, length)) {
this.clear();
int l = begin + length;
for (int i = begin; i < begin + length; i++) {
for (int i = begin; i < l; i++) {
increment(values[i]);
}
}

View File

@ -282,27 +282,27 @@ public final class RealSolverTest extends TestCase {
// 14 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 15);
// Static solve method
result = UnivariateRealSolverFactory.solve(f, -0.2, 0.2);
result = UnivariateRealSolverUtil.solve(f, -0.2, 0.2);
assertEquals(result, 0, solver.getAbsoluteAccuracy());
result = UnivariateRealSolverFactory.solve(f, -0.1, 0.3);
result = UnivariateRealSolverUtil.solve(f, -0.1, 0.3);
Assert.assertEquals(result, 0, 1E-8);
result = UnivariateRealSolverFactory.solve(f, -0.3, 0.45);
result = UnivariateRealSolverUtil.solve(f, -0.3, 0.45);
Assert.assertEquals(result, 0, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.3, 0.7);
result = UnivariateRealSolverUtil.solve(f, 0.3, 0.7);
Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.2, 0.6);
result = UnivariateRealSolverUtil.solve(f, 0.2, 0.6);
Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.05, 0.95);
result = UnivariateRealSolverUtil.solve(f, 0.05, 0.95);
Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.85, 1.25);
result = UnivariateRealSolverUtil.solve(f, 0.85, 1.25);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.8, 1.2);
result = UnivariateRealSolverUtil.solve(f, 0.8, 1.2);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.85, 1.75);
result = UnivariateRealSolverUtil.solve(f, 0.85, 1.75);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.55, 1.45);
result = UnivariateRealSolverUtil.solve(f, 0.55, 1.45);
Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverFactory.solve(f, 0.85, 5);
result = UnivariateRealSolverUtil.solve(f, 0.85, 5);
Assert.assertEquals(result, 1.0, 1E-6);
}
}

View File

@ -66,7 +66,7 @@ import org.apache.commons.math.beans.*;
* Test cases for the {@link BeanListUnivariateImpl} class.
*
* @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
* @version $Revision: 1.2 $ $Date: 2003/06/22 03:57:53 $
* @version $Revision: 1.3 $ $Date: 2003/07/30 21:58:11 $
*/
public final class BeanListUnivariateImplTest extends TestCase {
@ -138,62 +138,5 @@ public final class BeanListUnivariateImplTest extends TestCase {
ageU.getMax(), 0.001 );
}
/* public void testN0andN1Conditions() throws Exception {
List list = new ArrayList();
StoreUnivariate u = new ListUnivariateImpl( list );
assertTrue("Mean of n = 0 set should be NaN", Double.isNaN( u.getMean() ) );
assertTrue("Standard Deviation of n = 0 set should be NaN", Double.isNaN( u.getStandardDeviation() ) );
assertTrue("Variance of n = 0 set should be NaN", Double.isNaN(u.getVariance() ) );
list.add( new Double(one));
assertTrue( "Mean of n = 1 set should be value of single item n1", u.getMean() == one);
assertTrue( "StdDev of n = 1 set should be zero, instead it is: " + u.getStandardDeviation(), u.getStandardDeviation() == 0);
assertTrue( "Variance of n = 1 set should be zero", u.getVariance() == 0);
}
public void testSkewAndKurtosis() {
StoreUnivariate u = new StoreUnivariateImpl();
double[] testArray = { 12.5, 12, 11.8, 14.2, 14.9, 14.5, 21, 8.2, 10.3, 11.3, 14.1,
9.9, 12.2, 12, 12.1, 11, 19.8, 11, 10, 8.8, 9, 12.3 };
for( int i = 0; i < testArray.length; i++) {
u.addValue( testArray[i]);
}
assertEquals("mean", 12.40455, u.getMean(), 0.0001);
assertEquals("variance", 10.00236, u.getVariance(), 0.0001);
assertEquals("skewness", 1.437424, u.getSkewness(), 0.0001);
assertEquals("kurtosis", 2.37719, u.getKurtosis(), 0.0001);
}
public void testProductAndGeometricMean() throws Exception {
ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList());
u.setWindowSize(10);
u.addValue( 1.0 );
u.addValue( 2.0 );
u.addValue( 3.0 );
u.addValue( 4.0 );
assertEquals( "Product not expected", 24.0, u.getProduct(), Double.MIN_VALUE );
assertEquals( "Geometric mean not expected", 2.213364, u.getGeometricMean(), 0.00001 );
// Now test rolling - UnivariateImpl should discount the contribution
// of a discarded element
for( int i = 0; i < 10; i++ ) {
u.addValue( i + 2 );
}
// Values should be (2,3,4,5,6,7,8,9,10,11)
assertEquals( "Product not expected", 39916800.0, u.getProduct(), 0.00001 );
assertEquals( "Geometric mean not expected", 5.755931, u.getGeometricMean(), 0.00001 );
} */
}