Tab police

This commit is contained in:
Sebb 2015-01-12 18:54:16 +00:00
parent a14acdf639
commit c4768568c9
6 changed files with 111 additions and 111 deletions

View File

@ -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">
<link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
</javadoc>

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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<Character> 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<Character> {
/**
* String Chromosome represented by a list of characters.
*/
public static class StringChromosome extends AbstractListChromosome<Character> {
public StringChromosome(List<Character> repr) {
super(repr);
}
public StringChromosome(List<Character> 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<Character> chromosome = getRepresentation();
@ -137,51 +137,51 @@ public class HelloWorldExample {
return f;
}
@Override
protected void checkValidity(List<Character> 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<Character> repr) throws InvalidRepresentationException {
for (char c : repr) {
if (c < 32 || c > 126) {
throw new InvalidRepresentationException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
}
}
}
public List<Character> getStringRepresentation() {
return getRepresentation();
}
public List<Character> getStringRepresentation() {
return getRepresentation();
}
@Override
public StringChromosome newFixedLengthChromosome(List<Character> repr) {
return new StringChromosome(repr);
}
@Override
public StringChromosome newFixedLengthChromosome(List<Character> 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<Character> characters = strChromosome.getStringRepresentation();
int mutationIndex = GeneticAlgorithm.getRandomGenerator().nextInt(characters.size());
StringChromosome strChromosome = (StringChromosome) original;
List<Character> characters = strChromosome.getStringRepresentation();
int mutationIndex = GeneticAlgorithm.getRandomGenerator().nextInt(characters.size());
List<Character> mutatedChromosome = new ArrayList<Character>(characters);
char newValue = (char) (32 + GeneticAlgorithm.getRandomGenerator().nextInt(127 - 32));
mutatedChromosome.set(mutationIndex, newValue);
List<Character> mutatedChromosome = new ArrayList<Character>(characters);
char newValue = (char) (32 + GeneticAlgorithm.getRandomGenerator().nextInt(127 - 32));
mutatedChromosome.set(mutationIndex, newValue);
return strChromosome.newFixedLengthChromosome(mutatedChromosome);
}
}
return strChromosome.newFixedLengthChromosome(mutatedChromosome);
}
}
}

View File

@ -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,