add fix RNG, add extended interface EpsilonPolicy and move rewardHistory to model instead of view

- only setting the seed of RNG once at the beginning and not reseeding it afterwards. Deep copying
the initial AntWorld to use as blueprint for resetting the world instead of reseeding and creating pesudo random again. Reseeding the RNG has influence action selecting to always
choose the same trajectory.
- instance of is used to determine if policy has epsilon or not and the view will adopt to this, only showing epsilon slider if policy has epsilon
This commit is contained in:
2019-12-20 16:51:09 +01:00
parent e0160ca1df
commit 7db5a2af3b
16 changed files with 130 additions and 74 deletions
@@ -7,9 +7,9 @@ import core.algo.Learning;
import core.algo.Method;
import core.algo.mc.MonteCarloOnPolicyEGreedy;
import core.gui.View;
import core.policy.EpsilonPolicy;
import javax.swing.*;
import java.util.Optional;
public class RLController<A extends Enum> implements ViewListener{
protected Environment<A> environment;
@@ -30,28 +30,38 @@ public class RLController<A extends Enum> implements ViewListener{
switch (method){
case MC_ONPOLICY_EGREEDY:
learning = new MonteCarloOnPolicyEGreedy<>(environment, discreteActionSpace);
learning = new MonteCarloOnPolicyEGreedy<>(environment, discreteActionSpace, delay);
break;
case TD_ONPOLICY:
break;
default:
throw new RuntimeException("Undefined method");
}
SwingUtilities.invokeLater(() ->{
view = new View<>(learning, this);
learning.addListener(view);
});
/*
not using SwingUtilities here on purpose to ensure the view is fully
initialized and can be passed as LearningListener.
*/
view = new View<>(learning, this);
learning.addListener(view);
learning.learn(nrOfEpisodes);
}
@Override
public void onEpsilonChange(float epsilon) {
learning.setEpsilon(epsilon);
SwingUtilities.invokeLater(() -> view.updateLearningInfoPanel());
if(learning.getPolicy() instanceof EpsilonPolicy){
((EpsilonPolicy<A>) learning.getPolicy()).setEpsilon(epsilon);
SwingUtilities.invokeLater(() -> view.updateLearningInfoPanel());
}else{
System.out.println("Trying to call inEpsilonChange on non-epsilon policy");
}
}
@Override
public void onDelayChange(int delay) {
learning.setDelay(delay);
SwingUtilities.invokeLater(() -> {
view.updateLearningInfoPanel();
});
}
public RLController<A> setMethod(Method method){