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
@@ -1,6 +1,8 @@
package core.policy;
import core.RNG;
import lombok.Getter;
import lombok.Setter;
import java.util.Map;
@@ -12,7 +14,9 @@ import java.util.Map;
*
* @param <A> Discrete Action Enum
*/
public class EpsilonGreedyPolicy<A extends Enum> implements Policy<A>{
public class EpsilonGreedyPolicy<A extends Enum> implements EpsilonPolicy<A>{
@Setter
@Getter
private float epsilon;
private RandomPolicy<A> randomPolicy;
private GreedyPolicy<A> greedyPolicy;
@@ -22,8 +26,10 @@ public class EpsilonGreedyPolicy<A extends Enum> implements Policy<A>{
randomPolicy = new RandomPolicy<>();
greedyPolicy = new GreedyPolicy<>();
}
@Override
public A chooseAction(Map<A, Double> actionValues) {
System.out.println("current epsilon " + epsilon);
if(RNG.getRandom().nextFloat() < epsilon){
// Take random action
return randomPolicy.chooseAction(actionValues);
@@ -0,0 +1,6 @@
package core.policy;
public interface EpsilonPolicy<A extends Enum> extends Policy<A> {
float getEpsilon();
void setEpsilon(float epsilon);
}
+1 -3
View File
@@ -1,7 +1,5 @@
package core.policy;
import core.RNG;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -13,7 +11,7 @@ public class GreedyPolicy<A extends Enum> implements Policy<A> {
public A chooseAction(Map<A, Double> actionValues) {
if(actionValues.size() == 0) throw new RuntimeException("Empty actionActionValues set");
Double highestValueAction = null;
Double highestValueAction = null;
List<A> equalHigh = new ArrayList<>();
@@ -7,6 +7,7 @@ public class RandomPolicy<A extends Enum> implements Policy<A>{
@Override
public A chooseAction(Map<A, Double> actionValues) {
int idx = RNG.getRandom().nextInt(actionValues.size());
System.out.println("selected action " + idx);
int i = 0;
for(A action : actionValues.keySet()){
if(i++ == idx) return action;