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:
@@ -2,6 +2,7 @@ package core.gui;
|
||||
|
||||
import core.algo.Learning;
|
||||
import core.controller.ViewListener;
|
||||
import core.policy.EpsilonPolicy;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -11,6 +12,7 @@ public class LearningInfoPanel extends JPanel {
|
||||
private JLabel discountLabel;
|
||||
private JLabel epsilonLabel;
|
||||
private JSlider epsilonSlider;
|
||||
private JLabel delayLabel;
|
||||
private JSlider delaySlider;
|
||||
|
||||
public LearningInfoPanel(Learning learning, ViewListener viewListener){
|
||||
@@ -19,12 +21,19 @@ public class LearningInfoPanel extends JPanel {
|
||||
policyLabel = new JLabel();
|
||||
discountLabel = new JLabel();
|
||||
epsilonLabel = new JLabel();
|
||||
epsilonSlider = new JSlider(0, 100, (int)(learning.getEpsilon() * 100));
|
||||
epsilonSlider.addChangeListener(e -> viewListener.onEpsilonChange(epsilonSlider.getValue() / 100f));
|
||||
delayLabel = new JLabel();
|
||||
delaySlider = new JSlider(0,1000, learning.getDelay());
|
||||
delaySlider.addChangeListener(e -> viewListener.onDelayChange(delaySlider.getValue()));
|
||||
add(policyLabel);
|
||||
add(discountLabel);
|
||||
add(epsilonLabel);
|
||||
add(epsilonSlider);
|
||||
if(learning.getPolicy() instanceof EpsilonPolicy){
|
||||
epsilonSlider = new JSlider(0, 100, (int)((EpsilonPolicy)learning.getPolicy()).getEpsilon() * 100);
|
||||
epsilonSlider.addChangeListener(e -> viewListener.onEpsilonChange(epsilonSlider.getValue() / 100f));
|
||||
add(epsilonLabel);
|
||||
add(epsilonSlider);
|
||||
}
|
||||
add(delayLabel);
|
||||
add(delaySlider);
|
||||
refreshLabels();
|
||||
setVisible(true);
|
||||
}
|
||||
@@ -32,10 +41,9 @@ public class LearningInfoPanel extends JPanel {
|
||||
public void refreshLabels(){
|
||||
policyLabel.setText("Policy: " + learning.getPolicy().getClass());
|
||||
discountLabel.setText("Discount factor: " + learning.getDiscountFactor());
|
||||
epsilonLabel.setText("Exploration (Epsilon): " + learning.getEpsilon());
|
||||
}
|
||||
|
||||
protected JSlider getEpsilonSlider(){
|
||||
return epsilonSlider;
|
||||
if(learning.getPolicy() instanceof EpsilonPolicy){
|
||||
epsilonLabel.setText("Exploration (Epsilon): " + ((EpsilonPolicy)learning.getPolicy()).getEpsilon());
|
||||
}
|
||||
delayLabel.setText("Delay (ms): " + learning.getDelay());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,10 @@ public class View<A extends Enum> implements LearningListener {
|
||||
private JFrame mainFrame;
|
||||
private XChartPanel<XYChart> rewardChartPanel;
|
||||
private ViewListener viewListener;
|
||||
private List<Double> rewardHistory;
|
||||
|
||||
public View(Learning<A> learning, ViewListener viewListener){
|
||||
this.learning = learning;
|
||||
this.viewListener = viewListener;
|
||||
rewardHistory = new ArrayList<>();
|
||||
this.initMainFrame();
|
||||
}
|
||||
|
||||
@@ -78,8 +76,7 @@ public class View<A extends Enum> implements LearningListener {
|
||||
};
|
||||
}
|
||||
|
||||
public void updateRewardGraph(double recentReward){
|
||||
rewardHistory.add(recentReward);
|
||||
public void updateRewardGraph(List<Double> rewardHistory){
|
||||
chart.updateXYSeries("randomWalk", null, rewardHistory, null);
|
||||
rewardChartPanel.revalidate();
|
||||
rewardChartPanel.repaint();
|
||||
@@ -89,10 +86,11 @@ public class View<A extends Enum> implements LearningListener {
|
||||
this.learningInfoPanel.refreshLabels();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEpisodeEnd(double sumOfRewards) {
|
||||
SwingUtilities.invokeLater(()->updateRewardGraph(sumOfRewards));
|
||||
public void onEpisodeEnd(List<Double> rewardHistory) {
|
||||
SwingUtilities.invokeLater(()->{
|
||||
updateRewardGraph(rewardHistory);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user