add new results of needed timestamps in total

This commit is contained in:
2020-04-04 17:07:43 +02:00
parent a40e279f48
commit 595451e88b
11 changed files with 115 additions and 60 deletions
+3 -3
View File
@@ -17,11 +17,12 @@ public class RNG {
private static Random rng;
private static Random rngEnv;
private static int seed = 123;
private static int envSeed = 13;
static {
rng = new Random();
rng.setSeed(seed);
rngEnv = new Random();
rngEnv.setSeed(seed);
rngEnv.setSeed(13);
}
public static Random getRandom() {
@@ -34,7 +35,6 @@ public class RNG {
public static void setSeed(int seed){
RNG.seed = seed;
rng.setSeed(seed);
rngEnv = new Random();
rngEnv.setSeed(seed);
rngEnv.setSeed(13);
}
}
@@ -32,6 +32,7 @@ public class QLearningOffPolicyTDControl<A extends Enum> extends EpisodicLearnin
@Override
protected void nextEpisode() {
State state = environment.reset();
try {
Thread.sleep(delay);
@@ -72,19 +73,19 @@ public class QLearningOffPolicyTDControl<A extends Enum> extends EpisodicLearnin
}*/
if(reward == Reward.FOOD_DROP_DOWN_SUCCESS){
if(reward == Reward.FOOD_DROP_DOWN_SUCCESS) {
foodCollected++;
foodTimestampsTotal += timestampTilFood;
if(foodCollected % 1000 == 0){
System.out.println(foodTimestampsTotal / 1000f + " " + timestampCurrentEpisode);
File file = new File(ContinuousAnt.FILE_NAME);
//System.out.println(foodCollected + " " + timestampCurrentEpisode);
File file = new File(ContinuousAnt.FILE_NAME);
if(foodCollected % 1000 == 0) {
try {
Files.writeString(Path.of(file.getPath()), foodTimestampsTotal/1000f +",", StandardOpenOption.APPEND);
Files.writeString(Path.of(file.getPath()), timestampCurrentEpisode + ",", StandardOpenOption.APPEND);
} catch (IOException e) {
e.printStackTrace();
}
foodTimestampsTotal = 0;
}
foodTimestampsTotal = 0;
if(foodCollected == 1000){
((EpsilonGreedyPolicy<A>) this.policy).setEpsilon(0.15f);
}
@@ -98,8 +99,7 @@ public class QLearningOffPolicyTDControl<A extends Enum> extends EpisodicLearnin
System.out.println("final 0 expl");
((EpsilonGreedyPolicy<A>) this.policy).setEpsilon(0.00f);
}
if(foodCollected == 15000){
File file = new File(ContinuousAnt.FILE_NAME);
if(foodCollected == 30000) {
try {
Files.writeString(Path.of(file.getPath()), "\n", StandardOpenOption.APPEND);
} catch (IOException e) {
+33 -17
View File
@@ -8,31 +8,47 @@ import evironment.antGame.AntWorldContinuous;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ContinuousAnt {
public static final String FILE_NAME = "converge22.txt";
public static final String FILE_NAME = "optDiscTimestampsNew.txt";
public static void main(String[] args) {
int i = 4+4+4+6+6+6+8+10+12+14+14+16+16+16+18+18+18+20+20+20+22+22+22+24+24+24+24+26+26+26+26+26+28+28+28+28+28+30+30+30+30+32+32+32+34+34+34+36+36+38+40+42;
System.out.println(i/52f);
int k = 4 + 4 + 4 + 6 + 6 + 6 + 8 + 10 + 12 + 14 + 14 + 16 + 16 + 16 + 18 + 18 + 18 + 20 + 20 + 20 + 22 + 22 + 22 + 24 + 24 + 24 + 24 + 26 + 26 + 26 + 26 + 26 + 28 + 28 + 28 + 28 + 28 + 30 + 30 + 30 + 30 + 32 + 32 + 32 + 34 + 34 + 34 + 36 + 36 + 38 + 40 + 42;
System.out.println(k / 52f);
File file = new File(FILE_NAME);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
RNG.setSeed(56);
RLController<AntAction> rl = new RLController<>(
new AntWorldContinuous(8, 8),
Method.Q_LEARNING_OFF_POLICY_CONTROL,
AntAction.values());
rl.setDelay(0);
rl.setNrOfEpisodes(1);
//0.99 0.9 0.5
//0.99 0.95 0.9 0.7 0.5 0.3 0.1
rl.setDiscountFactor(0.1f);
// 0.1, 0.3, 0.5, 0.7 0.9
rl.setLearningRate(0.9f);
rl.setEpsilon(0.2f);
rl.start();
List<Float> discValues = new ArrayList<>() {
};
discValues.add(0.05f);
discValues.add(0.1f);
discValues.add(0.3f);
discValues.add(0.5f);
discValues.add(0.7f);
discValues.add(0.9f);
discValues.add(0.95f);
discValues.add(0.99f);
for(float disc : discValues) {
RNG.setSeed(13);
RLController<AntAction> rl = new RLController<>(
new AntWorldContinuous(8, 8),
Method.Q_LEARNING_OFF_POLICY_CONTROL,
AntAction.values());
rl.setDelay(0);
rl.setNrOfEpisodes(1);
//0.99 0.9 0.5
//0.99 0.95 0.9 0.7 0.5 0.3 0.1
rl.setDiscountFactor(disc);
// 0.1, 0.3, 0.5, 0.7 0.9
rl.setLearningRate(0.9f);
rl.setEpsilon(0.2f);
rl.start();
}
}
}