color palette

master
Peter Babič 9 years ago
parent 71beee220d
commit d08f6dfec0
  1. 4
      .classpath
  2. 14
      .gitignore
  3. 11
      .settings/org.eclipse.jdt.core.prefs
  4. BIN
      hello.png
  5. BIN
      hello_lol.png
  6. 20
      src/neural/BattlefieldParameterEvaluator.java

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="neural/ColorMap.java" kind="src" path="src"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="/home/delmadord/dev/Java/lib/encog-core-3.3.0/lib/encog-core-3.3.0.jar"/>
<classpathentry kind="lib" path="/opt/robocode/libs/robocode.jar" sourcepath="/home/delmadord/dev/Java/robocode-source/robocode-1.9.2.3-src.zip">
<attributes>
<attribute name="javadoc_location" value="file:/opt/robocode/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/delmadord/dev/Java/lib/encog-core-3.3.0/lib/encog-core-3.3.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

14
.gitignore vendored

@ -1,15 +1 @@
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
/png/

@ -1,11 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

BIN
hello.png (Stored with Git LFS)

Binary file not shown.

BIN
hello_lol.png (Stored with Git LFS)

Binary file not shown.

@ -21,7 +21,6 @@ import org.encog.neural.networks.training.propagation.resilient.ResilientPropaga
import robocode.BattleResults;
import robocode.control.*;
import robocode.control.events.*;
import neural.Palette;
public class BattlefieldParameterEvaluator {
@ -45,6 +44,10 @@ public class BattlefieldParameterEvaluator {
final static double NN_TRAINING_ERROR = 0.001;
// Maximum robot score obtained - used for scaling <0,1>
final static int BATTLE_MAX_SCORE = 250;
/* The name of the palette. Must be one of "Spectrum",
* "PaleSpectrum", "Grayscale", "CyclicGrayscale", "CyclicRedCyan",
* "EarthSky", "HotCold", or "Fire". */
final static String PALETTE = "PaleSpectrum";
static int NdxBattle;
static double[] FinalScore1;
@ -75,7 +78,7 @@ public class BattlefieldParameterEvaluator {
RobotSpecification[] competingRobots = engine.getLocalRepository("sample.RamFire,sample.TrackFire");
RobotSetup[] robotSetups = new RobotSetup[2];
for (NdxBattle = 0; NdxBattle < NUMSAMPLES; NdxBattle++) {
// Choose the battlefield size and gun cooling rate  
// Choose the battlefield size and gun cooling rate
BattlefieldSize[NdxBattle] = rangedRand(rng, MINBATTLEFIELDSIZE, MAXBATTLEFIELDSIZE);
GunCoolingRate[NdxBattle] = rangedRand(rng, MINGUNCOOLINGRATE, MAXGUNCOOLINGRATE);
// BattlefieldSize[NdxBattle] = MAXBATTLEFIELDSIZE * (0.1 + 0.9 * rng.nextDouble());
@ -99,12 +102,13 @@ public class BattlefieldParameterEvaluator {
System.out.println(Arrays.toString(GunCoolingRate));
System.out.println(Arrays.toString(FinalScore1));
System.out.println(Arrays.toString(FinalScore2));
// Create the training dataset for the neural network
double[][] RawInputs = new double[NUMSAMPLES][NUM_NN_INPUTS];
double[][] RawOutputs = new double[NUMSAMPLES][1];
for (int NdxSample = 0; NdxSample < NUMSAMPLES; NdxSample++) {
// IMPORTANT: normalize the inputs and the outputs to
// the interval [0,1]  
// the interval [0,1]
RawInputs[NdxSample][0] = BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE;
RawInputs[NdxSample][1] = GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE;
RawOutputs[NdxSample][0] = FinalScore1[NdxSample] / BATTLE_MAX_SCORE;
@ -112,7 +116,7 @@ public class BattlefieldParameterEvaluator {
BasicMLDataSet MyDataSet = new BasicMLDataSet(RawInputs, RawOutputs);
// Create and train the neural network   
// Create and train the neural network
BasicNetwork network = new BasicNetwork();
network.addLayer(new BasicLayer(null, true, NUM_NN_INPUTS));
network.addLayer(new BasicLayer(new ActivationSigmoid(), true, NUM_NN_HIDDEN_UNITS));
@ -149,7 +153,9 @@ public class BattlefieldParameterEvaluator {
}
}
Palette palette = new Palette();
// Palette palette = new Palette();
Palette palette = Palette.makeDefaultPalette(PALETTE);
// Simulate the neural network with the test samples and fill a matrix
for (int NdxBattleSize = 0; NdxBattleSize < NUMBATTLEFIELDSIZES; NdxBattleSize++) {
@ -186,7 +192,7 @@ public class BattlefieldParameterEvaluator {
}
BufferedImage img = new BufferedImage(NUMCOOLINGRATES, NUMBATTLEFIELDSIZES, BufferedImage.TYPE_INT_RGB);
img.setRGB(0, 0, NUMCOOLINGRATES, NUMBATTLEFIELDSIZES, OutputRGBint, 0, NUMCOOLINGRATES);
File f = new File("hello.png");
File f = new File("hello_" + PALETTE + ".png");
try {
ImageIO.write(img, "png", f);
}
@ -217,7 +223,7 @@ public class BattlefieldParameterEvaluator {
static class BattleObserver extends BattleAdaptor {
// Called when the battle is completed successfully with battle results
public void onBattleCompleted(BattleCompletedEvent e) {
System.out.println("‐‐ Battle has completed ‐‐");
System.out.println("Battle has completed.");
// Get the indexed battle results
BattleResults[] results = e.getIndexedResults();
// Print out the indexed results with the robot names

Loading…
Cancel
Save