add QTableFrame and clickable states that display a gui

- remove org.javaTuple in favour of org.apache.common for tuples and circleQueue
- remove ViewListener from non-GUI Controller
- stateActionTable saves the last 10 states that changed. They will get displayed in QTable Frame
in JTextAreas
This commit is contained in:
2020-01-01 23:54:18 +01:00
parent a8f8af1102
commit f4f1f7bd37
16 changed files with 334 additions and 136 deletions
+24 -17
View File
@@ -26,24 +26,25 @@ public class LearningInfoPanel extends JPanel {
private JCheckBox drawEnvironmentCheckbox;
private JTextField learnMoreEpisodesInput;
private JButton learnMoreEpisodesButton;
private JButton showQTableButton;
public LearningInfoPanel(Learning learning, ViewListener viewListener){
public LearningInfoPanel(Learning learning, ViewListener viewListener) {
this.learning = learning;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
policyLabel = new JLabel();
discountLabel = new JLabel();
delayLabel = new JLabel();
if(learning instanceof Episodic){
if(learning instanceof Episodic) {
episodeLabel = new JLabel();
add(episodeLabel);
}
delaySlider = new JSlider(0,1000, learning.getDelay());
delaySlider = new JSlider(0, 1000, learning.getDelay());
delaySlider.addChangeListener(e -> viewListener.onDelayChange(delaySlider.getValue()));
add(policyLabel);
add(discountLabel);
if(learning.getPolicy() instanceof EpsilonPolicy){
if(learning.getPolicy() instanceof EpsilonPolicy) {
epsilonLabel = new JLabel();
epsilonSlider = new JSlider(0, 100, (int)((EpsilonPolicy)learning.getPolicy()).getEpsilon() * 100);
epsilonSlider = new JSlider(0, 100, (int) ((EpsilonPolicy) learning.getPolicy()).getEpsilon() * 100);
epsilonSlider.addChangeListener(e -> viewListener.onEpsilonChange(epsilonSlider.getValue() / 100f));
add(epsilonLabel);
add(epsilonSlider);
@@ -51,7 +52,7 @@ public class LearningInfoPanel extends JPanel {
toggleFastLearningButton = new JButton("Enable fast-learn");
fastLearning = false;
toggleFastLearningButton.addActionListener(e->{
toggleFastLearningButton.addActionListener(e -> {
fastLearning = !fastLearning;
delaySlider.setEnabled(!fastLearning);
epsilonSlider.setEnabled(!fastLearning);
@@ -71,10 +72,10 @@ public class LearningInfoPanel extends JPanel {
if(learning instanceof EpisodicLearning) {
learnMoreEpisodesInput = new JTextField();
learnMoreEpisodesInput.setMaximumSize(new Dimension(200,20));
learnMoreEpisodesInput.setMaximumSize(new Dimension(200, 20));
learnMoreEpisodesButton = new JButton("Learn More Episodes");
learnMoreEpisodesButton.addActionListener(e -> {
if (Util.isNumeric(learnMoreEpisodesInput.getText())) {
if(Util.isNumeric(learnMoreEpisodesInput.getText())) {
viewListener.onLearnMoreEpisodes(Integer.parseInt(learnMoreEpisodesInput.getText()));
} else {
learnMoreEpisodesInput.setText("");
@@ -83,9 +84,14 @@ public class LearningInfoPanel extends JPanel {
add(learnMoreEpisodesInput);
add(learnMoreEpisodesButton);
}
showQTableButton = new JButton("Show Q-Table");
showQTableButton.addActionListener(e -> {
viewListener.onShowQTable();
});
add(drawEnvironmentCheckbox);
add(smoothGraphCheckbox);
add(last100Checkbox);
add(showQTableButton);
refreshLabels();
setVisible(true);
}
@@ -93,17 +99,17 @@ public class LearningInfoPanel extends JPanel {
public void refreshLabels() {
policyLabel.setText("Policy: " + learning.getPolicy().getClass());
discountLabel.setText("Discount factor: " + learning.getDiscountFactor());
if(learning instanceof Episodic){
episodeLabel.setText("Episode: " + ((Episodic)(learning)).getCurrentEpisode() +
"\t Episodes to go: " + ((Episodic)(learning)).getEpisodesToGo() +
"\t Eps/Sec: " + ((Episodic)(learning)).getEpisodesPerSecond());
if(learning instanceof Episodic) {
episodeLabel.setText("Episode: " + ((Episodic) (learning)).getCurrentEpisode() +
"\t Episodes to go: " + ((Episodic) (learning)).getEpisodesToGo() +
"\t Eps/Sec: " + ((Episodic) (learning)).getEpisodesPerSecond());
}
if (learning.getPolicy() instanceof EpsilonPolicy) {
if(learning.getPolicy() instanceof EpsilonPolicy) {
epsilonLabel.setText("Exploration (Epsilon): " + ((EpsilonPolicy) learning.getPolicy()).getEpsilon());
epsilonSlider.setValue((int)(((EpsilonPolicy) learning.getPolicy()).getEpsilon() * 100));
epsilonSlider.setValue((int) (((EpsilonPolicy) learning.getPolicy()).getEpsilon() * 100));
}
delayLabel.setText("Delay (ms): " + learning.getDelay());
if(delaySlider.isEnabled()){
if(delaySlider.isEnabled()) {
delaySlider.setValue(learning.getDelay());
}
toggleFastLearningButton.setText(fastLearning ? "Disable fast-learning" : "Enable fast-learning");
@@ -112,11 +118,12 @@ public class LearningInfoPanel extends JPanel {
protected boolean isSmoothenGraphSelected() {
return smoothGraphCheckbox.isSelected();
}
protected boolean isLast100Selected(){
protected boolean isLast100Selected() {
return last100Checkbox.isSelected();
}
protected boolean isDrawEnvironmentSelected(){
protected boolean isDrawEnvironmentSelected() {
return drawEnvironmentCheckbox.isSelected();
}
}