Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed resolution

  • Loading branch information...
commit 44a24d13ae8498542cdc0f0c92efb840731e2761 1 parent 059d829
@jeffheaton jeffheaton authored
View
14 .classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry combineaccessrules="false" kind="src" path="/encog-core"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/encog-java-core"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
View
38 src/main/java/org/encog/examples/neural/neat/boxes/BoxTrialCase.java
@@ -6,27 +6,17 @@
public class BoxTrialCase {
- private int resolution = 11;
- private int boundIdx = resolution - 1;
+ public static final int BASE_RESOLUTION = 11;
+ public static final int BOUNDS = BASE_RESOLUTION - 1;
private IntPair smallBoxTopLeft;
private IntPair largeBoxTopLeft;
private Random rnd;
-
+
public BoxTrialCase(Random theRnd) {
this.rnd = theRnd;
}
-
-
-
- public int getResolution() {
- return resolution;
- }
-
- public void setResolution(int resolution) {
- this.resolution = resolution;
- }
public IntPair initTestCase(int largeBoxRelativePos) {
IntPair[] loc = generateRandomTestCase(largeBoxRelativePos);
@@ -37,8 +27,8 @@ public IntPair initTestCase(int largeBoxRelativePos) {
}
public double getPixel(double x, double y) {
- int pixelX = (int) (((x + 1.0) * resolution) / 2.0);
- int pixelY = (int) (((y + 1.0) * resolution) / 2.0);
+ int pixelX = (int) (((x + 1.0) * BoxTrialCase.BASE_RESOLUTION) / 2.0);
+ int pixelY = (int) (((y + 1.0) * BoxTrialCase.BASE_RESOLUTION) / 2.0);
if (smallBoxTopLeft.getX() == pixelX
&& smallBoxTopLeft.getY() == pixelY) {
@@ -52,10 +42,10 @@ public double getPixel(double x, double y) {
}
private IntPair[] generateRandomTestCase(int largeBoxRelativePos) {
- IntPair smallBoxPos = new IntPair(rnd.nextInt(resolution),
- rnd.nextInt(resolution));
+ IntPair smallBoxPos = new IntPair(rnd.nextInt(BoxTrialCase.BASE_RESOLUTION),
+ rnd.nextInt(BoxTrialCase.BASE_RESOLUTION));
- IntPair largeBoxPos = (IntPair)smallBoxPos.clone();
+ IntPair largeBoxPos = (IntPair) smallBoxPos.clone();
switch (largeBoxRelativePos) {
case 0:
largeBoxPos.addX(5);
@@ -72,25 +62,25 @@ public double getPixel(double x, double y) {
break;
}
- if (largeBoxPos.getX() > boundIdx) {
- largeBoxPos.addX(-resolution);
+ if (largeBoxPos.getX() > BoxTrialCase.BOUNDS) {
+ largeBoxPos.addX(-BoxTrialCase.BASE_RESOLUTION);
if (0 == largeBoxPos.getX()) {
largeBoxPos.add(1);
}
- } else if (boundIdx == largeBoxPos.getX()) {
+ } else if (BoxTrialCase.BOUNDS == largeBoxPos.getX()) {
largeBoxPos.addX(-1);
} else if (largeBoxPos.getX() == 0) {
largeBoxPos.addX(1);
}
- if (largeBoxPos.getY() > boundIdx) {
- largeBoxPos.addY(-resolution);
+ if (largeBoxPos.getY() > BoxTrialCase.BOUNDS) {
+ largeBoxPos.addY(-BoxTrialCase.BASE_RESOLUTION);
if (0 == largeBoxPos.getY()) {
largeBoxPos.addY(1);
}
- } else if (boundIdx == largeBoxPos.getY()) {
+ } else if (BoxTrialCase.BOUNDS == largeBoxPos.getY()) {
largeBoxPos.addY(-1);
} else if (0 == largeBoxPos.getY()) {
largeBoxPos.addY(1);
View
8 src/main/java/org/encog/examples/neural/neat/boxes/DisplayBoxesPanel.java
@@ -18,6 +18,7 @@
private BoxTrialCase testCase = new BoxTrialCase(new Random());
private NEATPopulation pop;
+ private int resolution = BoxTrialCase.BASE_RESOLUTION;
public DisplayBoxesPanel(NEATPopulation thePopulation) {
testCase.initTestCase(0);
@@ -25,7 +26,7 @@ public DisplayBoxesPanel(NEATPopulation thePopulation) {
}
public void paint(Graphics g) {
- int resolution = this.testCase.getResolution();
+
NEATGenome genome = (NEATGenome)this.pop.getGenomes().get(0);
Substrate substrate = SubstrateFactory.factorSandwichSubstrate(resolution, resolution);
HyperNEATCODEC codec = new HyperNEATCODEC();
@@ -34,6 +35,9 @@ public void paint(Graphics g) {
TrialEvaluation trial = new TrialEvaluation(phenotype, this.testCase);
IntPair actualPos = trial.query(resolution);
+ // clear what was there before
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getWidth(), getHeight());
//
int boxWidth = this.getWidth()/resolution;
@@ -70,7 +74,7 @@ public void paint(Graphics g) {
public void createNewCase(int theResolution) {
Random r = new Random();
- this.testCase.setResolution(theResolution);
+ this.resolution = theResolution;
this.testCase.initTestCase(r.nextInt(3));
this.repaint();
}

0 comments on commit 44a24d1

Please sign in to comment.
Something went wrong with that request. Please try again.