testing the RNG range function

master
Peter Babič 9 years ago
parent 4c93ae38fe
commit 45d35d2125
  1. 1
      .gitignore
  2. BIN
      hello_strange.png
  3. 16
      src/neural/BattlefieldParameterEvaluator.java

1
.gitignore vendored

@ -11,3 +11,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
/bin/

BIN
hello_strange.png (Stored with Git LFS)

Binary file not shown.

@ -41,6 +41,8 @@ public class BattlefieldParameterEvaluator {
final static int NUM_TRAINING_EPOCHS = 100000; final static int NUM_TRAINING_EPOCHS = 100000;
// The requested error in nn training // The requested error in nn training
final static double NN_TRAINING_ERROR = 0.01; final static double NN_TRAINING_ERROR = 0.01;
// Maximum robot score obtained - used for scaling <0,1>
final static int BATTLE_MAX_SCORE = 250;
static int NdxBattle; static int NdxBattle;
static double[] FinalScore1; static double[] FinalScore1;
@ -72,8 +74,10 @@ public class BattlefieldParameterEvaluator {
RobotSetup[] robotSetups = new RobotSetup[2]; RobotSetup[] robotSetups = new RobotSetup[2];
for (NdxBattle = 0; NdxBattle < NUMSAMPLES; NdxBattle++) { 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); // BattlefieldSize[NdxBattle] = rangedRand(rng, MINBATTLEFIELDSIZE, MAXBATTLEFIELDSIZE);
GunCoolingRate[NdxBattle] = rangedRand(rng, MINGUNCOOLINGRATE, MAXGUNCOOLINGRATE); // GunCoolingRate[NdxBattle] = rangedRand(rng, MINGUNCOOLINGRATE, MAXGUNCOOLINGRATE);
BattlefieldSize[NdxBattle] = MAXBATTLEFIELDSIZE * (0.1 + 0.9 * rng.nextDouble());
GunCoolingRate[NdxBattle] = MAXGUNCOOLINGRATE * (0.1 + 0.9 * rng.nextDouble());
// Create the battlefield // Create the battlefield
BattlefieldSpecification battlefield = new BattlefieldSpecification((int) BattlefieldSize[NdxBattle], BattlefieldSpecification battlefield = new BattlefieldSpecification((int) BattlefieldSize[NdxBattle],
(int) BattlefieldSize[NdxBattle]); (int) BattlefieldSize[NdxBattle]);
@ -101,7 +105,7 @@ public class BattlefieldParameterEvaluator {
// the interval [0,1]   // the interval [0,1]  
RawInputs[NdxSample][0] = BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE; RawInputs[NdxSample][0] = BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE;
RawInputs[NdxSample][1] = GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE; RawInputs[NdxSample][1] = GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE;
RawOutputs[NdxSample][0] = FinalScore1[NdxSample] / 250; RawOutputs[NdxSample][0] = FinalScore1[NdxSample] / BATTLE_MAX_SCORE;
} }
BasicMLDataSet MyDataSet = new BasicMLDataSet(RawInputs, RawOutputs); BasicMLDataSet MyDataSet = new BasicMLDataSet(RawInputs, RawOutputs);
@ -144,12 +148,10 @@ public class BattlefieldParameterEvaluator {
// Simulate the neural network with the test samples and fill a matrix // Simulate the neural network with the test samples and fill a matrix
for (int NdxBattleSize = 0; NdxBattleSize < NUMBATTLEFIELDSIZES; NdxBattleSize++) { for (int NdxBattleSize = 0; NdxBattleSize < NUMBATTLEFIELDSIZES; NdxBattleSize++) {
for (int NdxCooling = 0; NdxCooling < NUMCOOLINGRATES; NdxCooling++) { for (int NdxCooling = 0; NdxCooling < NUMCOOLINGRATES; NdxCooling++) {
// TODO INSERT SOMETHING HERE // Get the output data using teached neural network
BasicMLData input = new BasicMLData(MyTestData[NdxCooling + NdxBattleSize * NUMCOOLINGRATES]); BasicMLData input = new BasicMLData(MyTestData[NdxCooling + NdxBattleSize * NUMCOOLINGRATES]);
final MLData output = network.compute(input.clone()); final MLData output = network.compute(input.clone());
double MyResult = output.getData()[0]; double MyResult = output.getData()[0];
// double MyResult = 0.0; // MyTestData[NdxCooling+NdxBattleSize*NUMCOOLINGRATES];
// double MyResult = MyTestData[NdxCooling + NdxBattleSize * NUMCOOLINGRATES];
MyValue = ClipColor(MyResult); MyValue = ClipColor(MyResult);
MyColor = new Color((float) MyValue, (float) MyValue, (float) MyValue); MyColor = new Color((float) MyValue, (float) MyValue, (float) MyValue);
OutputRGBint[NdxCooling + NdxBattleSize * NUMCOOLINGRATES] = MyColor.getRGB(); OutputRGBint[NdxCooling + NdxBattleSize * NUMCOOLINGRATES] = MyColor.getRGB();
@ -158,7 +160,7 @@ public class BattlefieldParameterEvaluator {
System.out.println("Testing completed."); System.out.println("Testing completed.");
// Plot the training samples // Plot the training samples
for (int NdxSample = 0; NdxSample < NUMSAMPLES; NdxSample++) { for (int NdxSample = 0; NdxSample < NUMSAMPLES; NdxSample++) {
MyValue = ClipColor(FinalScore1[NdxSample] / 250); MyValue = ClipColor(FinalScore1[NdxSample] / BATTLE_MAX_SCORE);
MyColor = new Color((float) MyValue, (float) MyValue, (float) MyValue); MyColor = new Color((float) MyValue, (float) MyValue, (float) MyValue);
int MyPixelIndex = (int) (Math.round(NUMCOOLINGRATES * ((GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE) - 0.1) / 0.9) + Math int MyPixelIndex = (int) (Math.round(NUMCOOLINGRATES * ((GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE) - 0.1) / 0.9) + Math
.round(NUMBATTLEFIELDSIZES * ((BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE) - 0.1) / 0.9) .round(NUMBATTLEFIELDSIZES * ((BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE) - 0.1) / 0.9)

Loading…
Cancel
Save