You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2009/09/05 19:37:05 UTC
svn commit: r811685 [22/24] - in /commons/proper/math/trunk: ./
src/main/java/org/apache/commons/math/
src/main/java/org/apache/commons/math/analysis/
src/main/java/org/apache/commons/math/analysis/integration/
src/main/java/org/apache/commons/math/ana...
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/CertifiedDataAbstractTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -36,11 +36,11 @@
* @version $Revision$ $Date$
*/
public abstract class CertifiedDataAbstractTest extends TestCase {
-
+
private DescriptiveStatistics descriptives;
-
+
private SummaryStatistics summaries;
-
+
private Map<String, Double> certifiedValues;
@Override
@@ -48,7 +48,7 @@
descriptives = new DescriptiveStatistics();
summaries = new SummaryStatistics();
certifiedValues = new HashMap<String, Double>();
-
+
loadData();
}
@@ -58,12 +58,12 @@
try {
URL resourceURL = getClass().getClassLoader().getResource(getResourceName());
in = new BufferedReader(new InputStreamReader(resourceURL.openStream()));
-
+
String line = in.readLine();
while (line != null) {
-
- /* this call to StringUtils did little for the
- * following conditional structure
+
+ /* this call to StringUtils did little for the
+ * following conditional structure
*/
line = line.trim();
@@ -102,14 +102,14 @@
protected void tearDown() throws Exception {
descriptives.clear();
descriptives = null;
-
+
summaries.clear();
summaries = null;
-
+
certifiedValues.clear();
certifiedValues = null;
}
-
+
public void testCertifiedValues() {
for (String name : certifiedValues.keySet()) {
Double expectedValue = certifiedValues.get(name);
@@ -129,12 +129,12 @@
}
}
}
-
-
+
+
protected Double getProperty(Object bean, String name) {
try {
// Get the value of prop
- String prop = "get" + name.substring(0,1).toUpperCase() + name.substring(1);
+ String prop = "get" + name.substring(0,1).toUpperCase() + name.substring(1);
Method meth = bean.getClass().getMethod(prop, new Class[0]);
Object property = meth.invoke(bean, new Object[0]);
if (meth.getReturnType().equals(Double.TYPE)) {
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LewTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LewTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LewTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LewTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LotteryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LotteryTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LotteryTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/data/LotteryTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatisticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatisticTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatisticTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatisticTest.java Sat Sep 5 17:36:48 2009
@@ -23,38 +23,38 @@
import org.apache.commons.math.stat.descriptive.moment.Mean;
/**
- * Tests for AbstractUnivariateStatistic
+ * Tests for AbstractUnivariateStatistic
*
* @version $Revision$ $Date$
*/
public class AbstractUnivariateStatisticTest extends TestCase {
-
+
public AbstractUnivariateStatisticTest(String name) {
super(name);
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite(AbstractUnivariateStatisticTest.class);
suite.setName("AbstractUnivariateStatistic Tests");
return suite;
}
-
+
protected double[] testArray = {0, 1, 2, 3, 4, 5};
protected double[] testWeightsArray = {0.3, 0.2, 1.3, 1.1, 1.0, 1.8};
protected double[] testNegativeWeightsArray = {-0.3, 0.2, -1.3, 1.1, 1.0, 1.8};
protected double[] nullArray = null;
protected double[] singletonArray = {0};
protected Mean testStatistic = new Mean();
-
+
public void testTestPositive() {
for (int j = 0; j < 6; j++) {
for (int i = 1; i < (7 - j); i++) {
assertTrue(testStatistic.test(testArray, 0, i));
- }
+ }
}
assertTrue(testStatistic.test(singletonArray, 0, 1));
}
-
+
public void testTestNegative() {
assertFalse(testStatistic.test(singletonArray, 0, 0));
assertFalse(testStatistic.test(testArray, 0, 0));
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,7 +34,7 @@
*
*/
public class AggregateSummaryStatisticsTest extends TestCase {
-
+
/**
* Creates and returns a {@code Test} representing all the test cases in this
* class
@@ -46,7 +46,7 @@
suite.setName("AggregateSummaryStatistics tests");
return suite;
}
-
+
/**
* Tests the standard aggregation behavior
*/
@@ -54,11 +54,11 @@
AggregateSummaryStatistics aggregate = new AggregateSummaryStatistics();
SummaryStatistics setOneStats = aggregate.createContributingStatistics();
SummaryStatistics setTwoStats = aggregate.createContributingStatistics();
-
+
assertNotNull("The set one contributing stats are null", setOneStats);
assertNotNull("The set two contributing stats are null", setTwoStats);
assertNotSame("Contributing stats objects are the same", setOneStats, setTwoStats);
-
+
setOneStats.addValue(2);
setOneStats.addValue(3);
setOneStats.addValue(5);
@@ -66,93 +66,93 @@
setOneStats.addValue(11);
assertEquals("Wrong number of set one values", 5, setOneStats.getN());
assertEquals("Wrong sum of set one values", 28.0, setOneStats.getSum());
-
+
setTwoStats.addValue(2);
setTwoStats.addValue(4);
setTwoStats.addValue(8);
assertEquals("Wrong number of set two values", 3, setTwoStats.getN());
assertEquals("Wrong sum of set two values", 14.0, setTwoStats.getSum());
-
+
assertEquals("Wrong number of aggregate values", 8, aggregate.getN());
assertEquals("Wrong aggregate sum", 42.0, aggregate.getSum());
}
-
+
/**
* Verify that aggregating over a partition gives the same results
* as direct computation.
- *
+ *
* 1) Randomly generate a dataset of 10-100 values
* from [-100, 100]
* 2) Divide the dataset it into 2-5 partitions
* 3) Create an AggregateSummaryStatistic and ContributingStatistics
- * for each partition
+ * for each partition
* 4) Compare results from the AggregateSummaryStatistic with values
- * returned by a single SummaryStatistics instance that is provided
+ * returned by a single SummaryStatistics instance that is provided
* the full dataset
*/
public void testAggregationConsistency() throws Exception {
-
+
// Generate a random sample and random partition
double[] totalSample = generateSample();
double[][] subSamples = generatePartition(totalSample);
int nSamples = subSamples.length;
-
+
// Create aggregator and total stats for comparison
AggregateSummaryStatistics aggregate = new AggregateSummaryStatistics();
SummaryStatistics totalStats = new SummaryStatistics();
-
+
// Create array of component stats
SummaryStatistics componentStats[] = new SummaryStatistics[nSamples];
-
+
for (int i = 0; i < nSamples; i++) {
-
+
// Make componentStats[i] a contributing statistic to aggregate
componentStats[i] = aggregate.createContributingStatistics();
-
+
// Add values from subsample
for (int j = 0; j < subSamples[i].length; j++) {
componentStats[i].addValue(subSamples[i][j]);
}
}
-
+
// Compute totalStats directly
for (int i = 0; i < totalSample.length; i++) {
totalStats.addValue(totalSample[i]);
}
-
+
/*
* Compare statistics in totalStats with aggregate.
* Note that guaranteed success of this comparison depends on the
* fact that <aggregate> gets values in exactly the same order
- * as <totalStats>.
- *
+ * as <totalStats>.
+ *
*/
- assertEquals(totalStats.getSummary(), aggregate.getSummary());
-
+ assertEquals(totalStats.getSummary(), aggregate.getSummary());
+
}
-
+
/**
* Test aggregate function by randomly generating a dataset of 10-100 values
* from [-100, 100], dividing it into 2-5 partitions, computing stats for each
* partition and comparing the result of aggregate(...) applied to the collection
* of per-partition SummaryStatistics with a single SummaryStatistics computed
* over the full sample.
- *
+ *
* @throws Exception
*/
public void testAggregate() throws Exception {
-
+
// Generate a random sample and random partition
double[] totalSample = generateSample();
double[][] subSamples = generatePartition(totalSample);
int nSamples = subSamples.length;
-
+
// Compute combined stats directly
SummaryStatistics totalStats = new SummaryStatistics();
for (int i = 0; i < totalSample.length; i++) {
totalStats.addValue(totalSample[i]);
}
-
+
// Now compute subsample stats individually and aggregate
SummaryStatistics[] subSampleStats = new SummaryStatistics[nSamples];
for (int i = 0; i < nSamples; i++) {
@@ -160,28 +160,28 @@
}
Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
for (int i = 0; i < nSamples; i++) {
- for (int j = 0; j < subSamples[i].length; j++) {
+ for (int j = 0; j < subSamples[i].length; j++) {
subSampleStats[i].addValue(subSamples[i][j]);
}
aggregate.add(subSampleStats[i]);
}
-
+
// Compare values
StatisticalSummary aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate);
assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12);
}
-
-
+
+
public void testAggregateDegenerate() throws Exception {
double[] totalSample = {1, 2, 3, 4, 5};
double[][] subSamples = {{1}, {2}, {3}, {4}, {5}};
-
+
// Compute combined stats directly
SummaryStatistics totalStats = new SummaryStatistics();
for (int i = 0; i < totalSample.length; i++) {
totalStats.addValue(totalSample[i]);
}
-
+
// Now compute subsample stats individually and aggregate
SummaryStatistics[] subSampleStats = new SummaryStatistics[5];
for (int i = 0; i < 5; i++) {
@@ -189,27 +189,27 @@
}
Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
for (int i = 0; i < 5; i++) {
- for (int j = 0; j < subSamples[i].length; j++) {
+ for (int j = 0; j < subSamples[i].length; j++) {
subSampleStats[i].addValue(subSamples[i][j]);
}
aggregate.add(subSampleStats[i]);
}
-
+
// Compare values
StatisticalSummaryValues aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate);
assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12);
}
-
+
public void testAggregateSpecialValues() throws Exception {
double[] totalSample = {Double.POSITIVE_INFINITY, 2, 3, Double.NaN, 5};
double[][] subSamples = {{Double.POSITIVE_INFINITY, 2}, {3}, {Double.NaN}, {5}};
-
+
// Compute combined stats directly
SummaryStatistics totalStats = new SummaryStatistics();
for (int i = 0; i < totalSample.length; i++) {
totalStats.addValue(totalSample[i]);
}
-
+
// Now compute subsample stats individually and aggregate
SummaryStatistics[] subSampleStats = new SummaryStatistics[5];
for (int i = 0; i < 4; i++) {
@@ -217,18 +217,18 @@
}
Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
for (int i = 0; i < 4; i++) {
- for (int j = 0; j < subSamples[i].length; j++) {
+ for (int j = 0; j < subSamples[i].length; j++) {
subSampleStats[i].addValue(subSamples[i][j]);
}
aggregate.add(subSampleStats[i]);
}
-
+
// Compare values
StatisticalSummaryValues aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate);
assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12);
-
+
}
-
+
/**
* Verifies that a StatisticalSummary and a StatisticalSummaryValues are equal up
* to delta, with NaNs, infinities returned in the same spots. For max, min, n, values
@@ -244,12 +244,12 @@
TestUtils.assertEquals(expected.getVariance(), observed.getVariance(), delta);
}
-
+
/**
* Generates a random sample of double values.
- * Sample size is random, between 10 and 100 and values are
+ * Sample size is random, between 10 and 100 and values are
* uniformly distributed over [-100, 100].
- *
+ *
* @return array of random double values
*/
private double[] generateSample() {
@@ -259,13 +259,13 @@
for (int i = 0; i < out.length; i++) {
out[i] = randomData.nextUniform(-100, 100);
}
- return out;
+ return out;
}
-
+
/**
* Generates a partition of <sample> into up to 5 sequentially selected
* subsamples with randomly selected partition points.
- *
+ *
* @param sample array to partition
* @return rectangular array with rows = subsamples
*/
@@ -300,5 +300,5 @@
return out;
}
}
-
+
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/DescriptiveStatisticsTest.java Sat Sep 5 17:36:48 2009
@@ -24,7 +24,7 @@
/**
* Test cases for the DescriptiveStatistics class.
- *
+ *
* @version $Revision$ $Date: 2007-08-16 15:36:33 -0500 (Thu, 16 Aug
* 2007) $
*/
@@ -53,7 +53,7 @@
stats.setMeanImpl(new deepMean());
assertEquals(42, stats.getMean(), 1E-10);
}
-
+
public void testCopy() {
DescriptiveStatistics stats = createDescriptiveStatistics();
stats.addValue(1);
@@ -65,7 +65,7 @@
copy = stats.copy();
assertEquals(42, copy.getMean(), 1E-10);
}
-
+
public void testWindowSize() {
DescriptiveStatistics stats = createDescriptiveStatistics();
stats.setWindowSize(300);
@@ -89,7 +89,7 @@
int refSum2 = refSum - (50 * 51) / 2;
assertEquals(refSum2 / 50.0, stats.getMean(), 1E-10);
}
-
+
public void testGetValues() {
DescriptiveStatistics stats = createDescriptiveStatistics();
for (int i = 100; i > 0; --i) {
@@ -107,7 +107,7 @@
}
assertEquals(12.0, stats.getElement(88), 1.0e-10);
}
-
+
public void testToString() {
DescriptiveStatistics stats = createDescriptiveStatistics();
stats.addValue(1);
@@ -161,25 +161,25 @@
assertEquals(reference.getGeometricMean(), shuffled.getSumsq(), 1.0e-10);
}
-
+
public void testPercentileSetter() throws Exception {
DescriptiveStatistics stats = createDescriptiveStatistics();
stats.addValue(1);
stats.addValue(2);
stats.addValue(3);
assertEquals(2, stats.getPercentile(50.0), 1E-10);
-
+
// Inject wrapped Percentile impl
stats.setPercentileImpl(new goodPercentile());
assertEquals(2, stats.getPercentile(50.0), 1E-10);
-
+
// Try "new math" impl
stats.setPercentileImpl(new subPercentile());
assertEquals(10.0, stats.getPercentile(10.0), 1E-10);
-
+
// Try to set bad impl
try {
- stats.setPercentileImpl(new badPercentile());
+ stats.setPercentileImpl(new badPercentile());
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
@@ -225,11 +225,11 @@
assertTrue(MathUtils.equals(mean3, dstat.getMean()));
}
-
+
// Test UnivariateStatistics impls for setter injection tests
-
+
/**
- * A new way to compute the mean
+ * A new way to compute the mean
*/
static class deepMean implements UnivariateStatistic {
@@ -239,12 +239,12 @@
public double evaluate(double[] values) {
return 42;
- }
+ }
public UnivariateStatistic copy() {
return new deepMean();
}
}
-
+
/**
* Test percentile implementation - wraps a Percentile
*/
@@ -258,14 +258,14 @@
}
public double evaluate(double[] values) {
return percentile.evaluate(values);
- }
+ }
public UnivariateStatistic copy() {
goodPercentile result = new goodPercentile();
result.setQuantile(percentile.getQuantile());
return result;
}
}
-
+
/**
* Test percentile subclass - another "new math" impl
* Always returns currently set quantile
@@ -278,7 +278,7 @@
@Override
public double evaluate(double[] values) {
return getQuantile();
- }
+ }
private static final long serialVersionUID = 8040701391045914979L;
@Override
public Percentile copy() {
@@ -286,7 +286,7 @@
return result;
}
}
-
+
/**
* "Bad" test percentile implementation - no setQuantile
*/
@@ -302,5 +302,5 @@
return new badPercentile();
}
}
-
+
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/InteractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/InteractionTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/InteractionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/InteractionTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -67,7 +67,7 @@
public void testInteraction() {
-
+
FourthMoment m4 = new FourthMoment();
Mean m = new Mean(m4);
Variance v = new Variance(m4);
@@ -77,7 +77,7 @@
for (int i = 0; i < testArray.length; i++){
m4.increment(testArray[i]);
}
-
+
assertEquals(mean,m.getResult(),tolerance);
assertEquals(var,v.getResult(),tolerance);
assertEquals(skew ,s.getResult(),tolerance);
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@
/** Serializable version identifier */
private static final long serialVersionUID = -8837442489133392138L;
-
+
/**
* Holds a reference to a list - GENERICs are going to make
* our lives easier here as we could only accept List<Number>
@@ -49,7 +49,7 @@
public ListUnivariateImpl(){
this(new ArrayList<Object>());
}
-
+
/**
* Construct a ListUnivariate with a specific List.
* @param list The list that will back this DescriptiveStatistics
@@ -57,7 +57,7 @@
public ListUnivariateImpl(List<Object> list) {
this(list, new DefaultTransformer());
}
-
+
/**
* Construct a ListUnivariate with a specific List.
* @param list The list that will back this DescriptiveStatistics
@@ -109,13 +109,13 @@
calcIndex = (list.size() - windowSize) + index;
}
-
+
try {
value = transformer.transform(list.get(calcIndex));
} catch (MathException e) {
e.printStackTrace();
}
-
+
return value;
}
@@ -141,9 +141,9 @@
public void addValue(double v) {
list.add(Double.valueOf(v));
}
-
+
/**
- * Adds an object to this list.
+ * Adds an object to this list.
* @param o Object to add to the list
*/
public void addObject(Object o) {
@@ -159,7 +159,7 @@
public void clear() {
list.clear();
}
-
+
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
@@ -174,7 +174,7 @@
}
return Double.NaN;
}
-
+
/**
* Access the number transformer.
* @return the number transformer.
@@ -190,12 +190,12 @@
public void setTransformer(NumberTransformer transformer) {
this.transformer = transformer;
}
-
+
/** {@inheritDoc} */
@Override
public synchronized void setWindowSize(int windowSize) {
this.windowSize = windowSize;
- //Discard elements from the front of the list if the windowSize is less than
+ //Discard elements from the front of the list if the windowSize is less than
// the size of the list.
int extra = list.size() - windowSize;
for (int i = 0; i < extra; i++) {
@@ -209,4 +209,4 @@
return windowSize;
}
-}
\ No newline at end of file
+}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@
*/
public final class ListUnivariateImplTest extends TestCase {
-
+
private double one = 1;
private float two = 2;
private int three = 3;
@@ -46,22 +46,22 @@
private double min = 1;
private double max = 3;
private double tolerance = 10E-15;
-
+
public ListUnivariateImplTest(String name) {
super(name);
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite(ListUnivariateImplTest.class);
suite.setName("Frequency Tests");
return suite;
}
-
+
/** test stats */
public void testStats() {
List<Object> externalList = new ArrayList<Object>();
-
- DescriptiveStatistics u = new ListUnivariateImpl( externalList );
+
+ DescriptiveStatistics u = new ListUnivariateImpl( externalList );
assertEquals("total count",0,u.getN(),tolerance);
u.addValue(one);
@@ -77,14 +77,14 @@
assertEquals("min",min,u.getMin(),tolerance);
assertEquals("max",max,u.getMax(),tolerance);
u.clear();
- assertEquals("total count",0,u.getN(),tolerance);
- }
-
+ assertEquals("total count",0,u.getN(),tolerance);
+ }
+
public void testN0andN1Conditions() throws Exception {
List<Object> list = new ArrayList<Object>();
-
+
DescriptiveStatistics 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() ) );
@@ -93,18 +93,18 @@
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);
+ assertTrue( "Variance of n = 1 set should be zero", u.getVariance() == 0);
}
-
+
public void testSkewAndKurtosis() {
DescriptiveStatistics u = new DescriptiveStatistics();
-
+
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);
@@ -114,7 +114,7 @@
public void testProductAndGeometricMean() throws Exception {
ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList<Object>());
u.setWindowSize(10);
-
+
u.addValue( 1.0 );
u.addValue( 2.0 );
u.addValue( 3.0 );
@@ -128,26 +128,26 @@
u.addValue( i + 2 );
}
// Values should be (2,3,4,5,6,7,8,9,10,11)
-
+
assertEquals( "Geometric mean not expected", 5.755931, u.getGeometricMean(), 0.00001 );
}
-
+
/** test stats */
public void testSerialization() {
-
+
DescriptiveStatistics u = new ListUnivariateImpl();
-
+
assertEquals("total count",0,u.getN(),tolerance);
u.addValue(one);
u.addValue(two);
-
- DescriptiveStatistics u2 = (DescriptiveStatistics)TestUtils.serializeAndRecover(u);
-
+
+ DescriptiveStatistics u2 = (DescriptiveStatistics)TestUtils.serializeAndRecover(u);
+
u2.addValue(two);
u2.addValue(three);
-
+
assertEquals("N",n,u2.getN(),tolerance);
assertEquals("sum",sum,u2.getSum(),tolerance);
assertEquals("sumsq",sumSq,u2.getSumsq(),tolerance);
@@ -158,7 +158,7 @@
assertEquals("max",max,u2.getMax(),tolerance);
u2.clear();
- assertEquals("total count",0,u2.getN(),tolerance);
- }
+ assertEquals("total count",0,u2.getN(),tolerance);
+ }
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,7 +48,7 @@
private double tolerance = 10E-15;
private TransformerMap transformers = new TransformerMap();
-
+
public MixedListUnivariateImplTest(String name) {
super(name);
transformers = new TransformerMap();
@@ -106,7 +106,7 @@
assertTrue(
"Mean of n = 1 set should be value of single item n1, instead it is " + u.getMean() ,
u.getMean() == one);
-
+
assertTrue(
"StdDev of n = 1 set should be zero, instead it is: "
+ u.getStandardDeviation(),
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,7 +38,7 @@
public MultivariateSummaryStatisticsTest(String name) {
super(name);
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite(MultivariateSummaryStatisticsTest.class);
suite.setName("MultivariateSummaryStatistics tests");
@@ -73,7 +73,7 @@
assertEquals(3, u.getMean()[1], 1E-14);
assertEquals(2, u.getDimension());
}
-
+
public void testSetterIllegalState() throws Exception {
MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);
u.addValue(new double[] { 1, 2 });
@@ -139,12 +139,12 @@
TestUtils.assertEquals(reference.getGeometricMean(), shuffled.getSumLog(), 1.0e-10);
}
-
+
/**
* Bogus mean implementation to test setter injection.
* Returns the sum instead of the mean.
*/
- static class sumMean implements StorelessUnivariateStatistic {
+ static class sumMean implements StorelessUnivariateStatistic {
private double sum = 0;
private long n = 0;
public double evaluate(double[] values, int begin, int length) {
@@ -154,7 +154,7 @@
return 0;
}
public void clear() {
- sum = 0;
+ sum = 0;
n = 0;
}
public long getN() {
@@ -170,7 +170,7 @@
public void incrementAll(double[] values, int start, int length) {
}
public void incrementAll(double[] values) {
- }
+ }
public StorelessUnivariateStatistic copy() {
return new sumMean();
}
@@ -216,8 +216,8 @@
assertEquals(2.0 / 3.0, u.getCovariance().getEntry(1, 0), 1.0e-10);
assertEquals(2.0 / 3.0, u.getCovariance().getEntry(1, 1), 1.0e-10);
u.clear();
- assertEquals(0, u.getN());
- }
+ assertEquals(0, u.getN());
+ }
public void testN0andN1Conditions() throws Exception {
MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(1, true);
@@ -230,7 +230,7 @@
assertEquals(1.0, u.getGeometricMean()[0], 1.0e-10);
assertEquals(0.0, u.getStandardDeviation()[0], 1.0e-10);
- /* n=2 */
+ /* n=2 */
u.addValue(new double[] { 2 });
assertTrue(u.getStandardDeviation()[0] > 0);
@@ -238,15 +238,15 @@
public void testNaNContracts() throws DimensionMismatchException {
MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(1, true);
- assertTrue(Double.isNaN(u.getMean()[0]));
- assertTrue(Double.isNaN(u.getMin()[0]));
- assertTrue(Double.isNaN(u.getStandardDeviation()[0]));
+ assertTrue(Double.isNaN(u.getMean()[0]));
+ assertTrue(Double.isNaN(u.getMin()[0]));
+ assertTrue(Double.isNaN(u.getStandardDeviation()[0]));
assertTrue(Double.isNaN(u.getGeometricMean()[0]));
u.addValue(new double[] { 1.0 });
- assertFalse(Double.isNaN(u.getMean()[0]));
- assertFalse(Double.isNaN(u.getMin()[0]));
- assertFalse(Double.isNaN(u.getStandardDeviation()[0]));
+ assertFalse(Double.isNaN(u.getMean()[0]));
+ assertFalse(Double.isNaN(u.getMin()[0]));
+ assertFalse(Double.isNaN(u.getStandardDeviation()[0]));
assertFalse(Double.isNaN(u.getGeometricMean()[0]));
}
@@ -302,7 +302,7 @@
t.addValue(new double[] { 5d, 1d });
assertTrue(t.equals(u));
assertTrue(u.equals(t));
- assertEquals(u.hashCode(), t.hashCode());
+ assertEquals(u.hashCode(), t.hashCode());
// Clear and make sure summaries are indistinguishable from empty summary
u.clear();
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,25 +29,25 @@
*/
public final class StatisticalSummaryValuesTest extends TestCase {
-
-
+
+
public StatisticalSummaryValuesTest(String name) {
super(name);
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite(StatisticalSummaryValuesTest.class);
suite.setName("StatisticalSummaryValues Tests");
return suite;
}
-
+
public void testSerialization() {
StatisticalSummaryValues u = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6);
- TestUtils.checkSerializedEquality(u);
+ TestUtils.checkSerializedEquality(u);
StatisticalSummaryValues t = (StatisticalSummaryValues) TestUtils.serializeAndRecover(u);
verifyEquality(u, t);
}
-
+
public void testEqualsAndHashCode() {
StatisticalSummaryValues u = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6);
StatisticalSummaryValues t = null;
@@ -57,13 +57,13 @@
t = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6);
assertTrue("instances with same data should be equal", t.equals(u));
assertEquals("hash code", u.hashCode(), t.hashCode());
-
+
u = new StatisticalSummaryValues(Double.NaN, 2, 3, 4, 5, 6);
t = new StatisticalSummaryValues(1, Double.NaN, 3, 4, 5, 6);
- assertFalse("instances based on different data should be different",
+ assertFalse("instances based on different data should be different",
(u.equals(t) ||t.equals(u)));
}
-
+
private void verifyEquality(StatisticalSummaryValues s, StatisticalSummaryValues u) {
assertEquals("N",s.getN(),u.getN());
TestUtils.assertEquals("sum",s.getSum(),u.getSum(), 0);
@@ -71,6 +71,6 @@
TestUtils.assertEquals("std",s.getStandardDeviation(),u.getStandardDeviation(), 0);
TestUtils.assertEquals("mean",s.getMean(),u.getMean(), 0);
TestUtils.assertEquals("min",s.getMin(),u.getMin(), 0);
- TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0);
+ TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0);
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public StorelessUnivariateStatisticAbstractTest(String name) {
super(name);
}
-
+
/** Small sample arrays */
protected double[][] smallSamples = {{}, {1}, {1,2}, {1,2,3}, {1,2,3,4}};
@@ -40,32 +40,32 @@
/**Expected value for the testArray defined in UnivariateStatisticAbstractTest */
@Override
public abstract double expectedValue();
-
- /**
- * Verifies that increment() and incrementAll work properly.
+
+ /**
+ * Verifies that increment() and incrementAll work properly.
*/
public void testIncrementation() throws Exception {
StorelessUnivariateStatistic statistic =
(StorelessUnivariateStatistic) getUnivariateStatistic();
-
+
// Add testArray one value at a time and check result
for (int i = 0; i < testArray.length; i++) {
statistic.increment(testArray[i]);
}
-
+
assertEquals(expectedValue(), statistic.getResult(), getTolerance());
assertEquals(testArray.length, statistic.getN());
statistic.clear();
-
+
// Add testArray all at once and check again
statistic.incrementAll(testArray);
assertEquals(expectedValue(), statistic.getResult(), getTolerance());
assertEquals(testArray.length, statistic.getN());
-
+
statistic.clear();
-
+
// Cleared
assertTrue(Double.isNaN(statistic.getResult()));
assertEquals(0, statistic.getN());
@@ -76,7 +76,7 @@
StorelessUnivariateStatistic statistic =
(StorelessUnivariateStatistic) getUnivariateStatistic();
-
+
TestUtils.checkSerializedEquality(statistic);
statistic.clear();
@@ -84,11 +84,11 @@
for (int i = 0; i < testArray.length; i++) {
statistic.increment(testArray[i]);
if(i % 5 == 0)
- statistic = (StorelessUnivariateStatistic)TestUtils.serializeAndRecover(statistic);
+ statistic = (StorelessUnivariateStatistic)TestUtils.serializeAndRecover(statistic);
}
-
+
TestUtils.checkSerializedEquality(statistic);
-
+
assertEquals(expectedValue(), statistic.getResult(), getTolerance());
statistic.clear();
@@ -96,53 +96,53 @@
assertTrue(Double.isNaN(statistic.getResult()));
}
-
+
public void testEqualsAndHashCode() {
StorelessUnivariateStatistic statistic =
(StorelessUnivariateStatistic) getUnivariateStatistic();
StorelessUnivariateStatistic statistic2 = null;
-
+
assertTrue("non-null, compared to null", !statistic.equals(statistic2));
assertTrue("reflexive, non-null", statistic.equals(statistic));
-
+
int emptyHash = statistic.hashCode();
statistic2 = (StorelessUnivariateStatistic) getUnivariateStatistic();
assertTrue("empty stats should be equal", statistic.equals(statistic2));
- assertEquals("empty stats should have the same hashcode",
+ assertEquals("empty stats should have the same hashcode",
emptyHash, statistic2.hashCode());
-
+
statistic.increment(1d);
assertTrue("reflexive, non-empty", statistic.equals(statistic));
assertTrue("non-empty, compared to empty", !statistic.equals(statistic2));
assertTrue("non-empty, compared to empty", !statistic2.equals(statistic));
assertTrue("non-empty stat should have different hashcode from empty stat",
statistic.hashCode() != emptyHash);
-
+
statistic2.increment(1d);
assertTrue("stats with same data should be equal", statistic.equals(statistic2));
- assertEquals("stats with same data should have the same hashcode",
+ assertEquals("stats with same data should have the same hashcode",
statistic.hashCode(), statistic2.hashCode());
-
+
statistic.increment(Double.POSITIVE_INFINITY);
assertTrue("stats with different n's should not be equal", !statistic2.equals(statistic));
assertTrue("stats with different n's should have different hashcodes",
statistic.hashCode() != statistic2.hashCode());
-
+
statistic2.increment(Double.POSITIVE_INFINITY);
assertTrue("stats with same data should be equal", statistic.equals(statistic2));
- assertEquals("stats with same data should have the same hashcode",
- statistic.hashCode(), statistic2.hashCode());
-
+ assertEquals("stats with same data should have the same hashcode",
+ statistic.hashCode(), statistic2.hashCode());
+
statistic.clear();
statistic2.clear();
assertTrue("cleared stats should be equal", statistic.equals(statistic2));
- assertEquals("cleared stats should have thashcode of empty stat",
+ assertEquals("cleared stats should have thashcode of empty stat",
emptyHash, statistic2.hashCode());
- assertEquals("cleared stats should have thashcode of empty stat",
+ assertEquals("cleared stats should have thashcode of empty stat",
emptyHash, statistic.hashCode());
-
+
}
-
+
public void testMomentSmallSamples() {
UnivariateStatistic stat = getUnivariateStatistic();
if (stat instanceof SecondMoment) {
@@ -152,9 +152,9 @@
assertEquals(0d, moment.getResult(), 0);
}
}
-
- /**
- * Make sure that evaluate(double[]) and inrementAll(double[]),
+
+ /**
+ * Make sure that evaluate(double[]) and inrementAll(double[]),
* getResult() give same results.
*/
public void testConsistency() {
@@ -169,39 +169,39 @@
TestUtils.assertEquals(stat.getResult(), stat.evaluate(smallSamples[i]), getTolerance());
}
}
-
+
/**
* Verifies that copied statistics remain equal to originals when
* incremented the same way.
*
*/
public void testCopyConsistency() {
-
+
StorelessUnivariateStatistic master =
(StorelessUnivariateStatistic) getUnivariateStatistic();
-
+
StorelessUnivariateStatistic replica = null;
-
+
// Randomly select a portion of testArray to load first
long index = Math.round((Math.random()) * testArray.length);
-
+
// Put first half in master and copy master to replica
master.incrementAll(testArray, 0, (int) index);
replica = master.copy();
-
+
// Check same
assertTrue(replica.equals(master));
assertTrue(master.equals(replica));
-
+
// Now add second part to both and check again
- master.incrementAll(testArray,
+ master.incrementAll(testArray,
(int) index, (int) (testArray.length - index));
- replica.incrementAll(testArray,
+ replica.incrementAll(testArray,
(int) index, (int) (testArray.length - index));
assertTrue(replica.equals(master));
assertTrue(master.equals(replica));
}
-
+
public void testSerial() {
StorelessUnivariateStatistic s =
(StorelessUnivariateStatistic) getUnivariateStatistic();
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -55,7 +55,7 @@
public SummaryStatisticsTest(String name) {
super(name);
}
-
+
protected SummaryStatistics createSummaryStatistics() {
return new SummaryStatistics();
}
@@ -77,34 +77,34 @@
assertEquals("min",min,u.getMin(),tolerance);
assertEquals("max",max,u.getMax(),tolerance);
u.clear();
- assertEquals("total count",0,u.getN(),tolerance);
- }
+ assertEquals("total count",0,u.getN(),tolerance);
+ }
public void testN0andN1Conditions() throws Exception {
SummaryStatistics u = createSummaryStatistics();
- assertTrue("Mean of n = 0 set should be NaN",
+ assertTrue("Mean of n = 0 set should be NaN",
Double.isNaN( u.getMean() ) );
- assertTrue("Standard Deviation of n = 0 set should be NaN",
+ assertTrue("Standard Deviation of n = 0 set should be NaN",
Double.isNaN( u.getStandardDeviation() ) );
- assertTrue("Variance of n = 0 set should be NaN",
+ assertTrue("Variance of n = 0 set should be NaN",
Double.isNaN(u.getVariance() ) );
/* n=1 */
u.addValue(one);
- assertTrue("mean should be one (n = 1)",
+ assertTrue("mean should be one (n = 1)",
u.getMean() == one);
- assertTrue("geometric should be one (n = 1) instead it is " + u.getGeometricMean(),
+ assertTrue("geometric should be one (n = 1) instead it is " + u.getGeometricMean(),
u.getGeometricMean() == one);
- assertTrue("Std should be zero (n = 1)",
+ assertTrue("Std should be zero (n = 1)",
u.getStandardDeviation() == 0.0);
- assertTrue("variance should be zero (n = 1)",
+ assertTrue("variance should be zero (n = 1)",
u.getVariance() == 0.0);
- /* n=2 */
+ /* n=2 */
u.addValue(twoF);
- assertTrue("Std should not be zero (n = 2)",
+ assertTrue("Std should not be zero (n = 2)",
u.getStandardDeviation() != 0.0);
- assertTrue("variance should not be zero (n = 2)",
+ assertTrue("variance should not be zero (n = 2)",
u.getVariance() != 0.0);
}
@@ -116,25 +116,25 @@
u.addValue( 3.0 );
u.addValue( 4.0 );
- assertEquals( "Geometric mean not expected", 2.213364,
+ assertEquals( "Geometric mean not expected", 2.213364,
u.getGeometricMean(), 0.00001 );
}
public void testNaNContracts() {
SummaryStatistics u = createSummaryStatistics();
- assertTrue("mean not NaN",Double.isNaN(u.getMean()));
- assertTrue("min not NaN",Double.isNaN(u.getMin()));
- assertTrue("std dev not NaN",Double.isNaN(u.getStandardDeviation()));
- assertTrue("var not NaN",Double.isNaN(u.getVariance()));
+ assertTrue("mean not NaN",Double.isNaN(u.getMean()));
+ assertTrue("min not NaN",Double.isNaN(u.getMin()));
+ assertTrue("std dev not NaN",Double.isNaN(u.getStandardDeviation()));
+ assertTrue("var not NaN",Double.isNaN(u.getVariance()));
assertTrue("geom mean not NaN",Double.isNaN(u.getGeometricMean()));
u.addValue(1.0);
- assertEquals( "mean not expected", 1.0,
+ assertEquals( "mean not expected", 1.0,
u.getMean(), Double.MIN_VALUE);
- assertEquals( "variance not expected", 0.0,
+ assertEquals( "variance not expected", 0.0,
u.getVariance(), Double.MIN_VALUE);
- assertEquals( "geometric mean not expected", 1.0,
+ assertEquals( "geometric mean not expected", 1.0,
u.getGeometricMean(), Double.MIN_VALUE);
u.addValue(-1.0);
@@ -160,7 +160,7 @@
verifySummary(u, summary);
u.addValue(2d);
summary = u.getSummary();
- verifySummary(u, summary);
+ verifySummary(u, summary);
}
public void testSerialization() {
@@ -205,7 +205,7 @@
u.addValue(4d);
assertFalse("different n's should make instances not equal", t.equals(u));
assertFalse("different n's should make instances not equal", u.equals(t));
- assertTrue("different n's should make hashcodes different",
+ assertTrue("different n's should make hashcodes different",
u.hashCode() != t.hashCode());
//Add data in same order to t
@@ -215,8 +215,8 @@
t.addValue(4d);
assertTrue("summaries based on same data should be equal", t.equals(u));
assertTrue("summaries based on same data should be equal", u.equals(t));
- assertEquals("summaries based on same data should have same hashcodes",
- u.hashCode(), t.hashCode());
+ assertEquals("summaries based on same data should have same hashcodes",
+ u.hashCode(), t.hashCode());
// Clear and make sure summaries are indistinguishable from empty summary
u.clear();
@@ -226,7 +226,7 @@
assertEquals("empty hash code", emptyHash, t.hashCode());
assertEquals("empty hash code", emptyHash, u.hashCode());
}
-
+
public void testCopy() throws Exception {
SummaryStatistics u = createSummaryStatistics();
u.addValue(2d);
@@ -244,7 +244,7 @@
assertTrue(v.sumsq == v.getSumsqImpl());
assertTrue(v.sumLog == v.getSumLogImpl());
assertTrue(v.variance == v.getVarianceImpl());
-
+
// Make sure both behave the same with additional values added
u.addValue(7d);
u.addValue(9d);
@@ -256,14 +256,14 @@
v.addValue(23d);
assertEquals(u, v);
assertEquals(v, u);
-
+
// Check implementation pointers are preserved
u.clear();
u.setSumImpl(new Sum());
SummaryStatistics.copy(u,v);
assertEquals(u.sum, v.sum);
assertEquals(u.getSumImpl(), v.getSumImpl());
-
+
}
private void verifySummary(SummaryStatistics u, StatisticalSummary s) {
@@ -273,7 +273,7 @@
TestUtils.assertEquals("std",s.getStandardDeviation(),u.getStandardDeviation(),tolerance);
TestUtils.assertEquals("mean",s.getMean(),u.getMean(),tolerance);
TestUtils.assertEquals("min",s.getMin(),u.getMin(),tolerance);
- TestUtils.assertEquals("max",s.getMax(),u.getMax(),tolerance);
+ TestUtils.assertEquals("max",s.getMax(),u.getMax(),tolerance);
}
public void testSetterInjection() throws Exception {
@@ -292,7 +292,7 @@
u.clear();
u.setMeanImpl(new Mean()); // OK after clear
}
-
+
public void testSetterIllegalState() throws Exception {
SummaryStatistics u = createSummaryStatistics();
u.addValue(1);
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java Sat Sep 5 17:36:48 2009
@@ -56,7 +56,7 @@
protected double weightedMean = 12.366995073891626d;
- protected double weightedVar = 9.974760968886391d;
+ protected double weightedVar = 9.974760968886391d;
protected double weightedStd = Math.sqrt(weightedVar);
protected double weightedProduct = 8517647448765288000000d;
protected double weightedSum = 251.05d;
@@ -111,7 +111,7 @@
copy.evaluate(testArray),
getTolerance());
}
-
+
/**
* Tests consistency of weighted statistic computation.
* For statistics that support weighted evaluation, this test case compares
@@ -120,9 +120,9 @@
* value appearing only once but with a weight value equal to its multiplicity
* in the repeating array.
*/
-
+
public void testWeightedConsistency() throws Exception {
-
+
// See if this statistic computes weighted statistics
// If not, skip this test
UnivariateStatistic statistic = getUnivariateStatistic();
@@ -133,23 +133,23 @@
} catch (NoSuchMethodException ex) {
return; // skip test
}
-
+
// Create arrays of values and corresponding integral weights
// and longer array with values repeated according to the weights
final int len = 10; // length of values array
final double mu = 0; // mean of test data
- final double sigma = 5; // std dev of test data
+ final double sigma = 5; // std dev of test data
double[] values = new double[len];
double[] weights = new double[len];
- RandomData randomData = new RandomDataImpl();
-
+ RandomData randomData = new RandomDataImpl();
+
// Fill weights array with random int values between 1 and 5
int[] intWeights = new int[len];
for (int i = 0; i < len; i++) {
intWeights[i] = randomData.nextInt(1, 5);
weights[i] = intWeights[i];
}
-
+
// Fill values array with random data from N(mu, sigma)
// and fill valuesList with values from values array with
// values[i] repeated weights[i] times, each i
@@ -161,21 +161,21 @@
valuesList.add(new Double(value));
}
}
-
+
// Dump valuesList into repeatedValues array
int sumWeights = valuesList.size();
double[] repeatedValues = new double[sumWeights];
for (int i = 0; i < sumWeights; i++) {
repeatedValues[i] = valuesList.get(i);
}
-
+
// Compare result of weighted statistic computation with direct computation
// on array of repeated values
double weightedResult = (Double) evaluateMethod.invoke(
statistic, values, weights, 0, values.length);
TestUtils.assertRelativelyEquals(
- statistic.evaluate(repeatedValues), weightedResult, 10E-14);
-
+ statistic.evaluate(repeatedValues), weightedResult, 10E-14);
+
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FirstMomentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FirstMomentTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FirstMomentTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FirstMomentTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,14 @@
/** descriptive statistic. */
protected FirstMoment stat;
-
+
/**
* @param name
*/
public FirstMomentTest(String name) {
super(name);
}
-
+
/**
* @see org.apache.commons.math.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FourthMomentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FourthMomentTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FourthMomentTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/FourthMomentTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,14 @@
/** descriptive statistic. */
protected FourthMoment stat;
-
+
/**
* @param name
*/
public FourthMomentTest(String name) {
super(name);
}
-
+
/**
* @see org.apache.commons.math.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/GeometricMeanTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/GeometricMeanTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/GeometricMeanTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/GeometricMeanTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public class GeometricMeanTest extends StorelessUnivariateStatisticAbstractTest{
protected GeometricMean stat;
-
+
/**
* @param name
*/
@@ -42,7 +42,7 @@
suite.setName("Mean Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@@ -58,32 +58,32 @@
public double expectedValue() {
return this.geoMean;
}
-
+
public void testSpecialValues() {
GeometricMean mean = new GeometricMean();
// empty
assertTrue(Double.isNaN(mean.getResult()));
-
+
// finite data
mean.increment(1d);
assertFalse(Double.isNaN(mean.getResult()));
-
+
// add 0 -- makes log sum blow to minus infinity, should make 0
mean.increment(0d);
assertEquals(0d, mean.getResult(), 0);
-
+
// add positive infinity - note the minus infinity above
mean.increment(Double.POSITIVE_INFINITY);
assertTrue(Double.isNaN(mean.getResult()));
-
+
// clear
mean.clear();
assertTrue(Double.isNaN(mean.getResult()));
-
+
// positive infinity by itself
mean.increment(Double.POSITIVE_INFINITY);
assertEquals(Double.POSITIVE_INFINITY, mean.getResult(), 0);
-
+
// negative value -- should make NaN
mean.increment(-2d);
assertTrue(Double.isNaN(mean.getResult()));
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/KurtosisTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/KurtosisTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/KurtosisTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/KurtosisTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,14 +29,14 @@
public class KurtosisTest extends StorelessUnivariateStatisticAbstractTest{
protected Kurtosis stat;
-
+
/**
* @param name
*/
public KurtosisTest(String name) {
super(name);
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite(KurtosisTest.class);
suite.setName("Kurtosis Tests");
@@ -58,7 +58,7 @@
public double expectedValue() {
return this.kurt;
}
-
+
/**
* Make sure Double.NaN is returned iff n < 4
*
@@ -73,7 +73,7 @@
kurt.increment(1d);
assertTrue(Double.isNaN(kurt.getResult()));
kurt.increment(1d);
- assertFalse(Double.isNaN(kurt.getResult()));
+ assertFalse(Double.isNaN(kurt.getResult()));
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SecondMomentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SecondMomentTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SecondMomentTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SecondMomentTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,14 @@
/** descriptive statistic. */
protected SecondMoment stat;
-
+
/**
* @param name
*/
public SecondMomentTest(String name) {
super(name);
}
-
+
/**
* @see org.apache.commons.math.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SkewnessTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SkewnessTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SkewnessTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/SkewnessTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,13 +24,13 @@
/**
* Test cases for the {@link UnivariateStatistic} class.
- *
+ *
* @version $Revision$ $Date$
*/
public class SkewnessTest extends StorelessUnivariateStatisticAbstractTest{
protected Skewness stat;
-
+
/**
* @param name
*/
@@ -51,7 +51,7 @@
suite.setName("Skewness Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@@ -59,7 +59,7 @@
public double expectedValue() {
return this.skew;
}
-
+
/**
* Make sure Double.NaN is returned iff n < 3
*
@@ -72,7 +72,7 @@
skew.increment(1d);
assertTrue(Double.isNaN(skew.getResult()));
skew.increment(1d);
- assertFalse(Double.isNaN(skew.getResult()));
+ assertFalse(Double.isNaN(skew.getResult()));
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,13 +24,13 @@
/**
* Test cases for the {@link UnivariateStatistic} class.
- *
+ *
* @version $Revision$ $Date$
*/
public class StandardDeviationTest extends StorelessUnivariateStatisticAbstractTest{
protected StandardDeviation stat;
-
+
/**
* @param name
*/
@@ -51,7 +51,7 @@
suite.setName("StandardDeviation Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@@ -59,7 +59,7 @@
public double expectedValue() {
return this.std;
}
-
+
/**
* Make sure Double.NaN is returned iff n = 0
*
@@ -70,10 +70,10 @@
std.increment(1d);
assertEquals(0d, std.getResult(), 0);
}
-
+
/**
* Test population version of variance
- */
+ */
public void testPopulation() {
double[] values = {-1.0d, 3.1d, 4.0d, -2.1d, 22d, 11.7d, 3d, 14d};
double sigma = populationStandardDeviation(values);
@@ -85,13 +85,13 @@
s1.incrementAll(values);
assertEquals(sigma, s1.getResult(), 1E-14);
s1 = new StandardDeviation(false, m);
- assertEquals(sigma, s1.getResult(), 1E-14);
+ assertEquals(sigma, s1.getResult(), 1E-14);
s1 = new StandardDeviation(false);
assertEquals(sigma, s1.evaluate(values), 1E-14);
s1.incrementAll(values);
- assertEquals(sigma, s1.getResult(), 1E-14);
+ assertEquals(sigma, s1.getResult(), 1E-14);
}
-
+
/**
* Definitional formula for population standard deviation
*/
@@ -99,7 +99,7 @@
double mean = new Mean().evaluate(v);
double sum = 0;
for (int i = 0; i < v.length; i++) {
- sum += (v[i] - mean) * (v[i] - mean);
+ sum += (v[i] - mean) * (v[i] - mean);
}
return Math.sqrt(sum / v.length);
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/ThirdMomentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/ThirdMomentTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/ThirdMomentTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/ThirdMomentTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,14 @@
/** descriptive statistic. */
protected ThirdMoment stat;
-
+
/**
* @param name
*/
public ThirdMomentTest(String name) {
super(name);
}
-
+
/**
* @see org.apache.commons.math.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VarianceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VarianceTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VarianceTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VarianceTest.java Sat Sep 5 17:36:48 2009
@@ -25,13 +25,13 @@
/**
* Test cases for the {@link UnivariateStatistic} class.
- *
+ *
* @version $Revision$ $Date$
*/
public class VarianceTest extends StorelessUnivariateStatisticAbstractTest{
protected Variance stat;
-
+
/**
* @param name
*/
@@ -111,19 +111,19 @@
public void testWeightedVariance() {
Variance variance = new Variance();
- assertEquals(expectedWeightedValue(),
+ assertEquals(expectedWeightedValue(),
variance.evaluate(testArray, testWeightsArray, 0, testArray.length), getTolerance());
-
+
// All weights = 1 -> weighted variance = unweighted variance
assertEquals(expectedValue(),
variance.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance());
-
+
// All weights the same -> when weights are normalized to sum to the length of the values array,
// weighted variance = unweighted value
assertEquals(expectedValue(),
variance.evaluate(testArray, MathUtils.normalizeArray(identicalWeightsArray, testArray.length),
0, testArray.length), getTolerance());
-
+
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java Sat Sep 5 17:36:48 2009
@@ -83,7 +83,7 @@
VectorialCovariance stat = new VectorialCovariance(points[0].length, true);
assertEquals(stat, TestUtils.serializeAndRecover(stat));
}
-
+
@Override
public void setUp() {
points = new double[][] {
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MaxTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MaxTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MaxTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MaxTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public class MaxTest extends StorelessUnivariateStatisticAbstractTest{
protected Max stat;
-
+
/**
* @param name
*/
@@ -42,7 +42,7 @@
suite.setName("Max Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@@ -58,9 +58,9 @@
public double expectedValue() {
return this.max;
}
-
+
public void testSpecialValues() {
- double[] testArray = {0d, Double.NaN, Double.NEGATIVE_INFINITY,
+ double[] testArray = {0d, Double.NaN, Double.NEGATIVE_INFINITY,
Double.POSITIVE_INFINITY};
Max max = new Max();
assertTrue(Double.isNaN(max.getResult()));
@@ -72,16 +72,16 @@
assertEquals(0d, max.getResult(), 0);
max.increment(testArray[3]);
assertEquals(Double.POSITIVE_INFINITY, max.getResult(), 0);
- assertEquals(Double.POSITIVE_INFINITY, max.evaluate(testArray), 0);
+ assertEquals(Double.POSITIVE_INFINITY, max.evaluate(testArray), 0);
}
public void testNaNs() {
Max max = new Max();
double nan = Double.NaN;
- assertEquals(3d, max.evaluate(new double[]{nan, 2d, 3d}), 0);
- assertEquals(3d, max.evaluate(new double[]{1d, nan, 3d}), 0);
- assertEquals(2d, max.evaluate(new double[]{1d, 2d, nan}), 0);
- assertTrue(Double.isNaN(max.evaluate(new double[]{nan, nan, nan})));
+ assertEquals(3d, max.evaluate(new double[]{nan, 2d, 3d}), 0);
+ assertEquals(3d, max.evaluate(new double[]{1d, nan, 3d}), 0);
+ assertEquals(2d, max.evaluate(new double[]{1d, 2d, nan}), 0);
+ assertTrue(Double.isNaN(max.evaluate(new double[]{nan, nan, nan})));
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MedianTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MedianTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MedianTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MedianTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public class MedianTest extends UnivariateStatisticAbstractTest{
protected Median stat;
-
+
/**
* @param name
*/
@@ -42,12 +42,12 @@
suite.setName("Median Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@Override
- public UnivariateStatistic getUnivariateStatistic() {
+ public UnivariateStatistic getUnivariateStatistic() {
return new Median();
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MinTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MinTest.java?rev=811685&r1=811684&r2=811685&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MinTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/rank/MinTest.java Sat Sep 5 17:36:48 2009
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,7 @@
public class MinTest extends StorelessUnivariateStatisticAbstractTest{
protected Min stat;
-
+
/**
* @param name
*/
@@ -42,7 +42,7 @@
suite.setName("Min Tests");
return suite;
}
-
+
/**
* {@inheritDoc}
*/
@@ -58,9 +58,9 @@
public double expectedValue() {
return this.min;
}
-
+
public void testSpecialValues() {
- double[] testArray = {0d, Double.NaN, Double.POSITIVE_INFINITY,
+ double[] testArray = {0d, Double.NaN, Double.POSITIVE_INFINITY,
Double.NEGATIVE_INFINITY};
Min min = new Min();
assertTrue(Double.isNaN(min.getResult()));
@@ -72,16 +72,16 @@
assertEquals(0d, min.getResult(), 0);
min.increment(testArray[3]);
assertEquals(Double.NEGATIVE_INFINITY, min.getResult(), 0);
- assertEquals(Double.NEGATIVE_INFINITY, min.evaluate(testArray), 0);
+ assertEquals(Double.NEGATIVE_INFINITY, min.evaluate(testArray), 0);
}
public void testNaNs() {
Min min = new Min();
double nan = Double.NaN;
- assertEquals(2d, min.evaluate(new double[]{nan, 2d, 3d}), 0);
- assertEquals(1d, min.evaluate(new double[]{1d, nan, 3d}), 0);
- assertEquals(1d, min.evaluate(new double[]{1d, 2d, nan}), 0);
- assertTrue(Double.isNaN(min.evaluate(new double[]{nan, nan, nan})));
+ assertEquals(2d, min.evaluate(new double[]{nan, 2d, 3d}), 0);
+ assertEquals(1d, min.evaluate(new double[]{1d, nan, 3d}), 0);
+ assertEquals(1d, min.evaluate(new double[]{1d, 2d, nan}), 0);
+ assertTrue(Double.isNaN(min.evaluate(new double[]{nan, nan, nan})));
}
-
+
}