remove DinoSampling stuff

This commit is contained in:
Jan Löwenstrom 2020-04-05 13:10:13 +02:00
parent 5b82e7965d
commit ad07c1da8f
5 changed files with 12 additions and 91 deletions

View File

@ -20,9 +20,8 @@ public class RNG {
private static int envSeed = 13;
static {
rng = new Random();
rng.setSeed(seed);
rngEnv = new Random();
rngEnv.setSeed(13);
setSeed(seed, true);
}
public static Random getRandom() {
@ -32,9 +31,16 @@ public class RNG {
return rngEnv;
}
public static void setSeed(int seed){
public static void setSeed(int seed, boolean setEnvRandom) {
RNG.seed = seed;
rng.setSeed(seed);
rngEnv.setSeed(13);
if(setEnvRandom) {
rngEnv.setSeed(13);
}
}
public static void setSeed(int seed) {
setSeed(seed, true);
}
}

View File

@ -5,17 +5,12 @@ import core.Environment;
import core.LearningConfig;
import core.StepResult;
import core.listener.LearningListener;
import example.DinoSampling;
import lombok.Getter;
import lombok.Setter;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -80,18 +75,6 @@ public abstract class EpisodicLearning<A extends Enum> extends Learning<A> imple
private void dispatchEpisodeStart(){
++currentEpisode;
/*
2f 0.02 => 100
1.5f 0.02 => 75
1.4f 0.02 => fail
1.5f 0.1 => 16 !
*/
// if(this.policy instanceof EpsilonGreedyPolicy){
// float ep = 2f/(float)currentEpisode;
// if(ep < 0.02) ep = 0;
// ((EpsilonGreedyPolicy<A>) this.policy).setEpsilon(ep);
// System.out.println(ep);
// }
episodesToLearn.decrementAndGet();
for(LearningListener l: learningListeners){
l.onEpisodeStart();
@ -103,17 +86,6 @@ public abstract class EpisodicLearning<A extends Enum> extends Learning<A> imple
super.dispatchStepEnd();
timestamp++;
timestampCurrentEpisode++;
// TODO: more sophisticated way to check convergence
if(false){
// t
File file = new File(DinoSampling.FILE_NAME);
try {
Files.writeString(Path.of(file.getPath()), currentEpisode/2 + ",", StandardOpenOption.APPEND);
} catch (IOException e) {
e.printStackTrace();
}
// System.out.println("converged after: " + currentEpisode/2 + " episode!");
}
}
@Override

View File

@ -29,6 +29,6 @@ public class CardDeck {
nextInt(int bound) returns random int value from (inclusive) 0
and EXCLUSIVE! bound
*/
return cards.get(RNG.getRandom().nextInt(cards.size()));
return cards.get(RNG.getRandomEnv().nextInt(cards.size()));
}
}

View File

@ -20,7 +20,7 @@ public class ContinuousAnt {
} catch (IOException e) {
e.printStackTrace();
}
RNG.setSeed(13);
RNG.setSeed(13, true);
RLController<AntAction> rl = new RLControllerGUI<>(
new AntWorldContinuous(8, 8),
Method.Q_LEARNING_OFF_POLICY_CONTROL,
@ -33,7 +33,5 @@ public class ContinuousAnt {
rl.setLearningRate(0.9f);
rl.setEpsilon(0.2f);
rl.start();
}
}

View File

@ -1,55 +0,0 @@
package example;
import core.RNG;
import core.algo.Method;
import core.controller.RLController;
import core.controller.RLControllerGUI;
import evironment.jumpingDino.DinoAction;
import evironment.jumpingDino.DinoWorld;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
public class DinoSampling {
public static final String FILE_NAME = "converge.txt";
public static void main(String[] args) {
File file = new File(FILE_NAME);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
for(float f = 0.05f; f <= 1.003; f += 0.05f) {
try {
Files.writeString(Path.of(file.getPath()), f + ",", StandardOpenOption.APPEND);
} catch (IOException e) {
e.printStackTrace();
}
for(int i = 1; i <= 100; i++) {
int seed = i * 13;
System.out.println("seed: " + seed);
RNG.setSeed(seed);
RLController<DinoAction> rl = new RLControllerGUI<>(
new DinoWorld(),
Method.MC_CONTROL_FIRST_VISIT,
DinoAction.values());
rl.setDelay(300);
rl.setDiscountFactor(1f);
rl.setEpsilon(0.5f);
rl.setLearningRate(0.9f);
rl.setNrOfEpisodes(400000);
rl.start();
}
try {
Files.writeString(Path.of(file.getPath()), "\n", StandardOpenOption.APPEND);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}