diff --git a/build.xml b/build.xml index 4984b6d78..09177b03e 100644 --- a/build.xml +++ b/build.xml @@ -245,7 +245,7 @@ doctitle="<h1>${component.title} ${component.version}</h1>" windowtitle="${component.title} ${component.version}" bottom="Copyright (c) 2003-${current.year} Apache Software Foundation" - additionalparam="-header '<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'" + additionalparam="-header '<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'" classpathref="compile.classpath"> diff --git a/src/test/java/org/apache/commons/math3/distribution/AbstractIntegerDistributionTest.java b/src/test/java/org/apache/commons/math3/distribution/AbstractIntegerDistributionTest.java index d6f668bb2..6e140eb56 100644 --- a/src/test/java/org/apache/commons/math3/distribution/AbstractIntegerDistributionTest.java +++ b/src/test/java/org/apache/commons/math3/distribution/AbstractIntegerDistributionTest.java @@ -30,20 +30,20 @@ public class AbstractIntegerDistributionTest { @Test public void testInverseCumulativeProbabilityMethod() { - double precision = 0.000000000000001; - Assert.assertEquals(1, diceDistribution.inverseCumulativeProbability(0)); - Assert.assertEquals(1, diceDistribution.inverseCumulativeProbability((1d-Double.MIN_VALUE)/6d)); - Assert.assertEquals(2, diceDistribution.inverseCumulativeProbability((1d+precision)/6d)); - Assert.assertEquals(2, diceDistribution.inverseCumulativeProbability((2d-Double.MIN_VALUE)/6d)); - Assert.assertEquals(3, diceDistribution.inverseCumulativeProbability((2d+precision)/6d)); - Assert.assertEquals(3, diceDistribution.inverseCumulativeProbability((3d-Double.MIN_VALUE)/6d)); - Assert.assertEquals(4, diceDistribution.inverseCumulativeProbability((3d+precision)/6d)); - Assert.assertEquals(4, diceDistribution.inverseCumulativeProbability((4d-Double.MIN_VALUE)/6d)); - Assert.assertEquals(5, diceDistribution.inverseCumulativeProbability((4d+precision)/6d)); - Assert.assertEquals(5, diceDistribution.inverseCumulativeProbability((5d-precision)/6d));//Can't use Double.MIN - Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((5d+precision)/6d)); - Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((6d-precision)/6d));//Can't use Double.MIN - Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((6d)/6d)); + double precision = 0.000000000000001; + Assert.assertEquals(1, diceDistribution.inverseCumulativeProbability(0)); + Assert.assertEquals(1, diceDistribution.inverseCumulativeProbability((1d-Double.MIN_VALUE)/6d)); + Assert.assertEquals(2, diceDistribution.inverseCumulativeProbability((1d+precision)/6d)); + Assert.assertEquals(2, diceDistribution.inverseCumulativeProbability((2d-Double.MIN_VALUE)/6d)); + Assert.assertEquals(3, diceDistribution.inverseCumulativeProbability((2d+precision)/6d)); + Assert.assertEquals(3, diceDistribution.inverseCumulativeProbability((3d-Double.MIN_VALUE)/6d)); + Assert.assertEquals(4, diceDistribution.inverseCumulativeProbability((3d+precision)/6d)); + Assert.assertEquals(4, diceDistribution.inverseCumulativeProbability((4d-Double.MIN_VALUE)/6d)); + Assert.assertEquals(5, diceDistribution.inverseCumulativeProbability((4d+precision)/6d)); + Assert.assertEquals(5, diceDistribution.inverseCumulativeProbability((5d-precision)/6d));//Can't use Double.MIN + Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((5d+precision)/6d)); + Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((6d-precision)/6d));//Can't use Double.MIN + Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((6d)/6d)); } @Test diff --git a/src/test/java/org/apache/commons/math3/ml/distance/EarthMoversDistanceTest.java b/src/test/java/org/apache/commons/math3/ml/distance/EarthMoversDistanceTest.java index 01d1e7977..43d3b6f52 100644 --- a/src/test/java/org/apache/commons/math3/ml/distance/EarthMoversDistanceTest.java +++ b/src/test/java/org/apache/commons/math3/ml/distance/EarthMoversDistanceTest.java @@ -26,25 +26,25 @@ import org.junit.Test; */ public class EarthMoversDistanceTest { - final DistanceMeasure distance = new EarthMoversDistance(); - final double[] a = { 0.1, 0.3, 0.2, 0.0, 0.25, 0.15 }; - final double[] b = { 0.3, 0.0, 0.4, 0.1, 0.0, 0.2 }; - - @Test - public void testZero() { - Assert.assertEquals(0, distance.compute(a, a), 0d); - } - - @Test - public void testZero2() { - final double[] zero = new double[] { 0, 0 }; - Assert.assertEquals(0, distance.compute(zero, zero), 0d); - } + final DistanceMeasure distance = new EarthMoversDistance(); + final double[] a = { 0.1, 0.3, 0.2, 0.0, 0.25, 0.15 }; + final double[] b = { 0.3, 0.0, 0.4, 0.1, 0.0, 0.2 }; - @Test - public void test() { - double expected = 0.65; //0.2 + 0.1 + 0.1 + 0.2 + 0.05 + 0.0; - Assert.assertEquals(expected, distance.compute(a, b), 1e-10); - Assert.assertEquals(expected, distance.compute(b, a), 1e-10); - } + @Test + public void testZero() { + Assert.assertEquals(0, distance.compute(a, a), 0d); + } + + @Test + public void testZero2() { + final double[] zero = new double[] { 0, 0 }; + Assert.assertEquals(0, distance.compute(zero, zero), 0d); + } + + @Test + public void test() { + double expected = 0.65; //0.2 + 0.1 + 0.1 + 0.2 + 0.05 + 0.0; + Assert.assertEquals(expected, distance.compute(a, b), 1e-10); + Assert.assertEquals(expected, distance.compute(b, a), 1e-10); + } } diff --git a/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java b/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java index ba77d8709..f104d6542 100644 --- a/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java +++ b/src/test/java/org/apache/commons/math3/stat/descriptive/SummaryStatisticsTest.java @@ -338,20 +338,20 @@ public class SummaryStatisticsTest { @Test public void testToString() { - SummaryStatistics u = createSummaryStatistics(); - for (int i = 0; i < 5; i++) { - u.addValue(i); - } - final String[] labels = {"min", "max", "sum", "geometric mean", "variance", - "population variance", "second moment", "sum of squares", "standard deviation", - "sum of logs"}; - final double[] values = {u.getMin(), u.getMax(), u.getSum(), u.getGeometricMean(), - u.getVariance(), u.getPopulationVariance(), u.getSecondMoment(), u.getSumsq(), - u.getStandardDeviation(), u.getSumOfLogs()}; - final String toString = u.toString(); - Assert.assertTrue(toString.indexOf("n: " + u.getN()) > 0); // getN() returns a long - for (int i = 0; i < values.length; i++) { - Assert.assertTrue(toString.indexOf(labels[i] + ": " + String.valueOf(values[i])) > 0); - } + SummaryStatistics u = createSummaryStatistics(); + for (int i = 0; i < 5; i++) { + u.addValue(i); + } + final String[] labels = {"min", "max", "sum", "geometric mean", "variance", + "population variance", "second moment", "sum of squares", "standard deviation", + "sum of logs"}; + final double[] values = {u.getMin(), u.getMax(), u.getSum(), u.getGeometricMean(), + u.getVariance(), u.getPopulationVariance(), u.getSecondMoment(), u.getSumsq(), + u.getStandardDeviation(), u.getSumOfLogs()}; + final String toString = u.toString(); + Assert.assertTrue(toString.indexOf("n: " + u.getN()) > 0); // getN() returns a long + for (int i = 0; i < values.length; i++) { + Assert.assertTrue(toString.indexOf(labels[i] + ": " + String.valueOf(values[i])) > 0); + } } } diff --git a/src/userguide/java/org/apache/commons/math3/userguide/genetics/HelloWorldExample.java b/src/userguide/java/org/apache/commons/math3/userguide/genetics/HelloWorldExample.java index 00c40e819..b4db00fcd 100644 --- a/src/userguide/java/org/apache/commons/math3/userguide/genetics/HelloWorldExample.java +++ b/src/userguide/java/org/apache/commons/math3/userguide/genetics/HelloWorldExample.java @@ -38,16 +38,16 @@ import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.Precision; public class HelloWorldExample { - public static final int POPULATION_SIZE = 1000; - public static final double CROSSOVER_RATE = 0.9; - public static final double MUTATION_RATE = 0.03; - public static final double ELITISM_RATE = 0.1; - public static final int TOURNAMENT_ARITY = 2; + public static final int POPULATION_SIZE = 1000; + public static final double CROSSOVER_RATE = 0.9; + public static final double MUTATION_RATE = 0.03; + public static final double ELITISM_RATE = 0.1; + public static final int TOURNAMENT_ARITY = 2; - public static final String TARGET_STRING = "Hello World!"; - public static final int DIMENSION = TARGET_STRING.length(); + public static final String TARGET_STRING = "Hello World!"; + public static final int DIMENSION = TARGET_STRING.length(); - public static void main(String[] args) { + public static void main(String[] args) { long startTime = System.currentTimeMillis(); // initialize a new genetic algorithm @@ -93,8 +93,8 @@ public class HelloWorldExample { Chromosome best = finalPopulation.getFittestChromosome(); System.out.println("Generation " + ga.getGenerationsEvolved() + ": " + best.toString()); System.out.println("Total execution time: " + (endTime - startTime) + "ms"); - } - + } + private static List randomRepresentation(int length) { return asList(RandomStringUtils.randomAscii(length)); } @@ -112,20 +112,20 @@ public class HelloWorldExample { return new ElitisticListPopulation(popList, 2 * popList.size(), ELITISM_RATE); } - /** - * String Chromosome represented by a list of characters. - */ - public static class StringChromosome extends AbstractListChromosome { + /** + * String Chromosome represented by a list of characters. + */ + public static class StringChromosome extends AbstractListChromosome { - public StringChromosome(List repr) { - super(repr); - } + public StringChromosome(List repr) { + super(repr); + } - public StringChromosome(String str) { - this(asList(str)); - } + public StringChromosome(String str) { + this(asList(str)); + } - public double fitness() { + public double fitness() { String target = TARGET_STRING; int f = 0; // start at 0; the best fitness List chromosome = getRepresentation(); @@ -137,51 +137,51 @@ public class HelloWorldExample { return f; } - @Override - protected void checkValidity(List repr) throws InvalidRepresentationException { - for (char c : repr) { - if (c < 32 || c > 126) { - throw new InvalidRepresentationException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME); - } - } - } + @Override + protected void checkValidity(List repr) throws InvalidRepresentationException { + for (char c : repr) { + if (c < 32 || c > 126) { + throw new InvalidRepresentationException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME); + } + } + } - public List getStringRepresentation() { - return getRepresentation(); - } + public List getStringRepresentation() { + return getRepresentation(); + } - @Override - public StringChromosome newFixedLengthChromosome(List repr) { - return new StringChromosome(repr); - } + @Override + public StringChromosome newFixedLengthChromosome(List repr) { + return new StringChromosome(repr); + } - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - for (Character i : getRepresentation()) { - sb.append(i.charValue()); - } - return String.format("(f=%s '%s')", getFitness(), sb.toString()); - } + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Character i : getRepresentation()) { + sb.append(i.charValue()); + } + return String.format("(f=%s '%s')", getFitness(), sb.toString()); + } - } + } - private static class RandomCharacterMutation implements MutationPolicy { - public Chromosome mutate(Chromosome original) { - if (!(original instanceof StringChromosome)) { - throw new IllegalArgumentException(); - } + private static class RandomCharacterMutation implements MutationPolicy { + public Chromosome mutate(Chromosome original) { + if (!(original instanceof StringChromosome)) { + throw new IllegalArgumentException(); + } - StringChromosome strChromosome = (StringChromosome) original; - List characters = strChromosome.getStringRepresentation(); - - int mutationIndex = GeneticAlgorithm.getRandomGenerator().nextInt(characters.size()); + StringChromosome strChromosome = (StringChromosome) original; + List characters = strChromosome.getStringRepresentation(); + + int mutationIndex = GeneticAlgorithm.getRandomGenerator().nextInt(characters.size()); - List mutatedChromosome = new ArrayList(characters); - char newValue = (char) (32 + GeneticAlgorithm.getRandomGenerator().nextInt(127 - 32)); - mutatedChromosome.set(mutationIndex, newValue); + List mutatedChromosome = new ArrayList(characters); + char newValue = (char) (32 + GeneticAlgorithm.getRandomGenerator().nextInt(127 - 32)); + mutatedChromosome.set(mutationIndex, newValue); - return strChromosome.newFixedLengthChromosome(mutatedChromosome); - } - } + return strChromosome.newFixedLengthChromosome(mutatedChromosome); + } + } } diff --git a/src/userguide/java/org/apache/commons/math3/userguide/sofm/ChineseRingsClassifier.java b/src/userguide/java/org/apache/commons/math3/userguide/sofm/ChineseRingsClassifier.java index d27d0d9c4..871d9d6ae 100644 --- a/src/userguide/java/org/apache/commons/math3/userguide/sofm/ChineseRingsClassifier.java +++ b/src/userguide/java/org/apache/commons/math3/userguide/sofm/ChineseRingsClassifier.java @@ -58,7 +58,7 @@ public class ChineseRingsClassifier { /** Distance function. */ private final DistanceMeasure distance = new EuclideanDistance(); - public static void main(String[] args) { + public static void main(String[] args) { final ChineseRings rings = new ChineseRings(new Vector3D(1, 2, 3), 25, 2, 20, 1,