Skip to content
Snippets Groups Projects
Commit 0227004c authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Refactored Hyperpoint to rename it to Vector. Added a few additional...

Refactored Hyperpoint to rename it to Vector. Added a few additional operations to the Vector class.

git-svn-id: svn://svn.syncleus.com/dANN/trunk@437 6ae8b97b-f314-0410-8212-aecf10b92ded
parent 529adf60
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ package com.syncleus.core.dann.examples.colormap; ...@@ -21,7 +21,7 @@ package com.syncleus.core.dann.examples.colormap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import com.syncleus.dann.math.Hyperpoint; import com.syncleus.dann.math.Vector;
import com.syncleus.dann.neural.som.brain.ExponentialDecaySomBrain; import com.syncleus.dann.neural.som.brain.ExponentialDecaySomBrain;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.awt.Color; import java.awt.Color;
...@@ -52,7 +52,7 @@ public final class ColorMap1dCallable implements Callable<Color[]> ...@@ -52,7 +52,7 @@ public final class ColorMap1dCallable implements Callable<Color[]>
//create the output latice //create the output latice
for(double x = 0; x < getWidth(); x++) for(double x = 0; x < getWidth(); x++)
brain.createOutput(new Hyperpoint(new double[]{x})); brain.createOutput(new Vector(new double[]{x}));
//run through random training data for all iterations //run through random training data for all iterations
for(int iteration = 0; iteration < getIterations(); iteration++) for(int iteration = 0; iteration < getIterations(); iteration++)
...@@ -67,13 +67,13 @@ public final class ColorMap1dCallable implements Callable<Color[]> ...@@ -67,13 +67,13 @@ public final class ColorMap1dCallable implements Callable<Color[]>
} }
//pull the output weight vectors //pull the output weight vectors
Map<Hyperpoint, double[]> outputWeightVectors = brain.getOutputWeightVectors(); Map<Vector, double[]> outputWeightVectors = brain.getOutputWeightVectors();
//construct the color array //construct the color array
Color[] colorPositions = new Color[getWidth()]; Color[] colorPositions = new Color[getWidth()];
for(Entry<Hyperpoint, double[]> weightVector : outputWeightVectors.entrySet()) for(Entry<Vector, double[]> weightVector : outputWeightVectors.entrySet())
{ {
Hyperpoint currentPoint = weightVector.getKey(); Vector currentPoint = weightVector.getKey();
double[] currentVector = weightVector.getValue(); double[] currentVector = weightVector.getValue();
//convert the current Vector to a color. //convert the current Vector to a color.
......
...@@ -21,7 +21,7 @@ package com.syncleus.core.dann.examples.colormap; ...@@ -21,7 +21,7 @@ package com.syncleus.core.dann.examples.colormap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import com.syncleus.dann.math.Hyperpoint; import com.syncleus.dann.math.Vector;
import com.syncleus.dann.neural.som.brain.ExponentialDecaySomBrain; import com.syncleus.dann.neural.som.brain.ExponentialDecaySomBrain;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.awt.Color; import java.awt.Color;
...@@ -58,7 +58,7 @@ public class ColorMap2dCallable implements Callable<Color[][]> ...@@ -58,7 +58,7 @@ public class ColorMap2dCallable implements Callable<Color[][]>
//create the output latice //create the output latice
for(double x = 0; x < getWidth(); x++) for(double x = 0; x < getWidth(); x++)
for(double y = 0; y < getHeight(); y++) for(double y = 0; y < getHeight(); y++)
brain.createOutput(new Hyperpoint(new double[]{x, y})); brain.createOutput(new Vector(new double[]{x, y}));
//run through random training data //run through random training data
for(int iteration = 0; iteration < getIterations(); iteration++) for(int iteration = 0; iteration < getIterations(); iteration++)
...@@ -73,13 +73,13 @@ public class ColorMap2dCallable implements Callable<Color[][]> ...@@ -73,13 +73,13 @@ public class ColorMap2dCallable implements Callable<Color[][]>
} }
//pull the output weight vectors //pull the output weight vectors
Map<Hyperpoint, double[]> outputWeightVectors = brain.getOutputWeightVectors(); Map<Vector, double[]> outputWeightVectors = brain.getOutputWeightVectors();
//construct the color array //construct the color array
Color[][] colorPositions = new Color[getWidth()][getHeight()]; Color[][] colorPositions = new Color[getWidth()][getHeight()];
for(Entry<Hyperpoint, double[]> weightVector : outputWeightVectors.entrySet()) for(Entry<Vector, double[]> weightVector : outputWeightVectors.entrySet())
{ {
Hyperpoint currentPoint = weightVector.getKey(); Vector currentPoint = weightVector.getKey();
double[] currentVector = weightVector.getValue(); double[] currentVector = weightVector.getValue();
//convert the current Vector to a color. //convert the current Vector to a color.
......
...@@ -24,7 +24,7 @@ import java.util.concurrent.ExecutorService; ...@@ -24,7 +24,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javax.swing.*; import javax.swing.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.syncleus.dann.math.Hyperpoint; import com.syncleus.dann.math.Vector;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.HashSet; import java.util.HashSet;
...@@ -55,7 +55,7 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener ...@@ -55,7 +55,7 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener
private PopulationEvolveCallable populationCallable = null; private PopulationEvolveCallable populationCallable = null;
private Future<TravellingSalesmanChromosome> futureWinner = null; private Future<TravellingSalesmanChromosome> futureWinner = null;
private TravellingSalesmanChromosome currentWinner = null; private TravellingSalesmanChromosome currentWinner = null;
private Hyperpoint cities[] = null; private Vector cities[] = null;
private static class PopulationEvolveCallable implements Callable<TravellingSalesmanChromosome> private static class PopulationEvolveCallable implements Callable<TravellingSalesmanChromosome>
{ {
...@@ -139,7 +139,7 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener ...@@ -139,7 +139,7 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener
if(this.cities != null) if(this.cities != null)
{ {
for(Hyperpoint city : this.cities) for(Vector city : this.cities)
{ {
int currentX = (int) city.getCoordinate(1); int currentX = (int) city.getCoordinate(1);
int currentY = (int) city.getCoordinate(2); int currentY = (int) city.getCoordinate(2);
...@@ -151,16 +151,16 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener ...@@ -151,16 +151,16 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener
if((this.cities != null)&&(this.currentWinner != null)) if((this.cities != null)&&(this.currentWinner != null))
{ {
int ordering[] = this.currentWinner.getCitiesOrder(); int ordering[] = this.currentWinner.getCitiesOrder();
Hyperpoint[] orderedPoints = new Hyperpoint[ordering.length]; Vector[] orderedPoints = new Vector[ordering.length];
for(int cityIndex = 0; cityIndex < this.cities.length; cityIndex++) for(int cityIndex = 0; cityIndex < this.cities.length; cityIndex++)
{ {
orderedPoints[ordering[cityIndex]] = this.cities[cityIndex]; orderedPoints[ordering[cityIndex]] = this.cities[cityIndex];
} }
//draw the points //draw the points
Hyperpoint firstPoint = null; Vector firstPoint = null;
Hyperpoint lastPoint = null; Vector lastPoint = null;
for(Hyperpoint point : orderedPoints) for(Vector point : orderedPoints)
{ {
if(lastPoint == null) if(lastPoint == null)
{ {
...@@ -194,16 +194,16 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener ...@@ -194,16 +194,16 @@ public class TravellingSalesmanDemo extends JFrame implements ActionListener
} }
private static Hyperpoint[] getRandomPoints(int cityCount) private static Vector[] getRandomPoints(int cityCount)
{ {
if(cityCount < 4) if(cityCount < 4)
throw new IllegalArgumentException("cityCount must have atleast 4 elements"); throw new IllegalArgumentException("cityCount must have atleast 4 elements");
HashSet<Hyperpoint> pointsSet = new HashSet<Hyperpoint>(); HashSet<Vector> pointsSet = new HashSet<Vector>();
while(pointsSet.size() < cityCount) while(pointsSet.size() < cityCount)
pointsSet.add(new Hyperpoint(new double[]{RANDOM.nextDouble() * MAP_WIDTH, RANDOM.nextDouble() * MAP_HEIGHT})); pointsSet.add(new Vector(new double[]{RANDOM.nextDouble() * MAP_WIDTH, RANDOM.nextDouble() * MAP_HEIGHT}));
Hyperpoint[] points = new Hyperpoint[cityCount]; Vector[] points = new Vector[cityCount];
pointsSet.toArray(points); pointsSet.toArray(points);
return points; return points;
......
...@@ -19,16 +19,16 @@ ...@@ -19,16 +19,16 @@
package com.syncleus.core.dann.examples.tsp; package com.syncleus.core.dann.examples.tsp;
import com.syncleus.dann.genetics.*; import com.syncleus.dann.genetics.*;
import com.syncleus.dann.math.Hyperpoint; import com.syncleus.dann.math.Vector;
import java.util.List; import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
public class TravellingSalesmanFitnessFunction extends AbstractGeneticAlgorithmFitnessFunction<TravellingSalesmanFitnessFunction> public class TravellingSalesmanFitnessFunction extends AbstractGeneticAlgorithmFitnessFunction<TravellingSalesmanFitnessFunction>
{ {
final private Hyperpoint cities[]; final private Vector cities[];
private double totalDistance = 0.0; private double totalDistance = 0.0;
public TravellingSalesmanFitnessFunction(final TravellingSalesmanChromosome chromosome, final Hyperpoint[] cities) public TravellingSalesmanFitnessFunction(final TravellingSalesmanChromosome chromosome, final Vector[] cities)
{ {
super(chromosome); super(chromosome);
...@@ -83,11 +83,11 @@ public class TravellingSalesmanFitnessFunction extends AbstractGeneticAlgorithmF ...@@ -83,11 +83,11 @@ public class TravellingSalesmanFitnessFunction extends AbstractGeneticAlgorithmF
//calculate the distance going through the genes sorted by city priority //calculate the distance going through the genes sorted by city priority
double currentDistance = 0.0; double currentDistance = 0.0;
Hyperpoint firstPosition = null; Vector firstPosition = null;
Hyperpoint lastPosition = null; Vector lastPosition = null;
for(AbstractValueGene sortedGene : sortedGenes) for(AbstractValueGene sortedGene : sortedGenes)
{ {
final Hyperpoint currentPosition = this.cities[indexedGenes.indexOf(sortedGene)]; final Vector currentPosition = this.cities[indexedGenes.indexOf(sortedGene)];
if(lastPosition == null) if(lastPosition == null)
{ {
lastPosition = currentPosition; lastPosition = currentPosition;
......
...@@ -22,13 +22,13 @@ import com.syncleus.dann.genetics.*; ...@@ -22,13 +22,13 @@ import com.syncleus.dann.genetics.*;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import com.syncleus.dann.math.Hyperpoint; import com.syncleus.dann.math.Vector;
public class TravellingSalesmanPopulation extends AbstractGeneticAlgorithmPopulation public class TravellingSalesmanPopulation extends AbstractGeneticAlgorithmPopulation
{ {
private final Hyperpoint cities[]; private final Vector cities[];
public TravellingSalesmanPopulation(final Hyperpoint cities[], final double mutationDeviation, final double crossoverPercentage, final double dieOffPercentage) public TravellingSalesmanPopulation(final Vector cities[], final double mutationDeviation, final double crossoverPercentage, final double dieOffPercentage)
{ {
super(mutationDeviation, crossoverPercentage, dieOffPercentage); super(mutationDeviation, crossoverPercentage, dieOffPercentage);
...@@ -40,7 +40,7 @@ public class TravellingSalesmanPopulation extends AbstractGeneticAlgorithmPopula ...@@ -40,7 +40,7 @@ public class TravellingSalesmanPopulation extends AbstractGeneticAlgorithmPopula
this.cities = cities.clone(); this.cities = cities.clone();
} }
public TravellingSalesmanPopulation(final Hyperpoint cities[], final double mutationDeviation, final double crossoverPercentage, final double dieOffPercentage, final ThreadPoolExecutor threadExecutor) public TravellingSalesmanPopulation(final Vector cities[], final double mutationDeviation, final double crossoverPercentage, final double dieOffPercentage, final ThreadPoolExecutor threadExecutor)
{ {
super(mutationDeviation, crossoverPercentage, dieOffPercentage, threadExecutor); super(mutationDeviation, crossoverPercentage, dieOffPercentage, threadExecutor);
...@@ -88,7 +88,7 @@ public class TravellingSalesmanPopulation extends AbstractGeneticAlgorithmPopula ...@@ -88,7 +88,7 @@ public class TravellingSalesmanPopulation extends AbstractGeneticAlgorithmPopula
return (TravellingSalesmanChromosome) winner; return (TravellingSalesmanChromosome) winner;
} }
public Hyperpoint[] getCities() public Vector[] getCities()
{ {
return cities.clone(); return cities.clone();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment