public class PerformancePlotter extends javax.swing.JFrame implements EnvironmentObserver
PerformanceMetric
enumerator. A plot showing the most recent
"trial" of an agent can be displayed, the average of the metric over all trials with confidence intervals, or both may be displayed; which plots are shown is specfied by the
TrialMode
enumerator.
Any subset of these metrics
may be displayed in any order specified by the user and plots are displayed in a matrix format with a maximum number of columns that are filled out first.
If the number of plots would cause a window height larger than a maximimum specified, then the plots are placed in a scroll view.
The way this class should be used is the constructor is first called. Then the startGUI()
method. A trial indicates a single evaluation of
a learning algorithm for some number of steps or episodes. Multiple trials are used to produce the average trial plots. Each trial should reinitialize
the learning algorithm so that it learns from scratch. At the start of each trial the startNewTrial()
method should be called. At the end
of each episode in a trial, the endEpisode()
method should be called. At the end of a trial the endTrial()
method should be called. When
all trials for the current agent are complete and a new agent is to tested to be compared, the startNewAgent(String)
method should be called,
providing the name of the new agent to be tested. Since the constructor takes the name of the first agent, this method does not have to be called for
the first agent. When all testing for all agents is complete, a call to the endTrialsForCurrentAgent()
method should be made.
To ensure proper use of this class, it is highly reccomended that the LearningAlgorithmExperimenter
class is used, since it handles all of these
method calls behind the scenes.
When testing is done, you may optionally request all data to be printed to CSV files. One CSV file will produce the step-wise performance metric (cumulaitve reward by step) for all agents and trials. Another will produce all the episode-wise performance metric data. This data can be produced regardless of which metrics you requested to be plotted.
Note that the plots that are created have a number of interactive options. Try right-clicking on them to see the list of things you can modfiy in the GUI.
Modifier and Type | Class and Description |
---|---|
protected class |
PerformancePlotter.AgentDatasets
A datastructure for maintain the plot series data in the current agent
|
protected class |
PerformancePlotter.MutableBoolean
A class for a mutable boolean
|
protected class |
PerformancePlotter.Trial
A datastructure for maintaining all the metric stats for a single trial.
|
javax.swing.JFrame.AccessibleJFrame
java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.util.List<PerformancePlotter.Trial>> |
agentTrials
contains all trial data for each agent
|
protected org.jfree.data.xy.XYSeriesCollection |
colAER
All agent plot series for the the most recetent trial's average reward per episode
|
protected org.jfree.data.xy.YIntervalSeriesCollection |
colAERAvg
All agent plot series for the average of all trial's average reward per episode
|
protected org.jfree.data.xy.XYSeriesCollection |
colCER
All agent plot series for the the most recetent trial's cumulative reward per episode
|
protected org.jfree.data.xy.YIntervalSeriesCollection |
colCERAvg
All agent plot series for the average of all trial's cumulative reward per episode
|
protected org.jfree.data.xy.XYSeriesCollection |
colCSE
All agent plot series for the the most recetent trial's cumulative step per episode
|
protected org.jfree.data.xy.YIntervalSeriesCollection |
colCSEAvg
All agent plot series for the average of all trial's cumulative steps per episode
|
protected org.jfree.data.xy.XYSeriesCollection |
colCSR
All agent plot series for the the most recetent trial's cumulative reward per step
|
protected org.jfree.data.xy.YIntervalSeriesCollection |
colCSRAvg
All agent plot series for the average of all trial's cumulative reward per step
|
protected boolean |
collectData
Whether the data from action observations received should be recoreded or not.
|
protected org.jfree.data.xy.XYSeriesCollection |
colMER
All agent plot series for the the most recetent trial's median reward per episode
|
protected org.jfree.data.xy.YIntervalSeriesCollection |
colMERAvg
All agent plot series for the average of all trial's median reward per episode
|
protected org.jfree.data.xy.XYSeriesCollection |
colSE
All agent plot series for the most recetent trial's steps per episode
|
protected org.jfree.data.xy.YIntervalSeriesCollection |
colSEAvg
All agent plot series for the average of all trial's steps per episode
|
protected PerformancePlotter.AgentDatasets |
curAgentDatasets
contains the plot series data that will be displayed for the current agent
|
protected java.lang.String |
curAgentName
The name of the current agent being tested
|
protected int |
curEpisode
the current episode that was recorded
|
protected int |
curTimeStep
the current time step that was recorded
|
protected PerformancePlotter.Trial |
curTrial
Contains all the current trial performance data
|
protected int |
delay
the delay in milliseconds between which the charts are updated automatically
|
protected int |
lastEpisode
The last episode at which the plot's series data was updated
|
protected int |
lastTimeStepUpdate
The last time step at which the plots' series data was updated
|
protected java.util.Set<PerformanceMetric> |
metricsSet
A set specifying the performance metrics that will be plotted
|
protected boolean |
needsClearing
Whether the current plots need their series data cleared for a new trial
|
protected double |
significance
the significance level used for confidence intervals.
|
protected TrialMode |
trialMode
specifies whether the most recent trial, average of all trials, or both plots will be displayed
|
protected PerformancePlotter.MutableBoolean |
trialUpdateComplete
Synchronization object to ensure proper threaded plot updating
|
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
PerformancePlotter(java.lang.String firstAgentName,
int chartWidth,
int chartHeight,
int columns,
int maxWindowHeight,
TrialMode trialMode,
PerformanceMetric... metrics)
Initializes a performance plotter.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
accumulate(java.util.List<java.lang.Double> list,
double v)
Computes the sum of the last entry in list and the value v and adds it to the end of list.
|
protected org.jfree.chart.renderer.xy.DeviationRenderer |
createDeviationRenderer()
Creates a DeviationRenderer to use for the trial average plots
|
void |
endAllAgents()
Informs the plotter that all data for all agents has been collected.
|
void |
endEpisode()
Informs the plotter that all data for the last episode has been collected.
|
void |
endTrial()
Informs the plotter that all data for the current trial as been collected.
|
protected void |
endTrialsForCurrentAgent()
Informs the plotter that all trials for the current agent have been collected and causes the average plots to be set and displayed.
|
static double[] |
getCI(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics stats,
double significanceLevel)
Returns the confidence interval for the specified significance level
|
protected void |
insertChart(java.awt.Container plotContainer,
java.awt.GridBagConstraints c,
int columns,
int chartWidth,
int chartHeight,
java.lang.String title,
java.lang.String xlab,
java.lang.String ylab,
org.jfree.data.xy.XYSeriesCollection mostRecentCollection,
org.jfree.data.xy.YIntervalSeriesCollection averageCollection)
Adds the most recent trial (if enabled) chart and trial average (if enabled) chart into the provided container.
|
protected void |
launchThread()
Launches the automatic plot refresh thread.
|
protected int[] |
minStepAndEpisodes(java.util.List<PerformancePlotter.Trial> trials)
Returns the minimum steps and episodes across all trials
|
void |
observeEnvironmentActionInitiation(State o,
Action action)
This method is called when an
Environment receives an action to execute, but before the
Environment has completed execution. |
void |
observeEnvironmentInteraction(EnvironmentOutcome eo)
This method is called every time an
Environment is interacted with. |
void |
observeEnvironmentReset(Environment resetEnvironment)
This method is called every time an
Environment is reset (has the Environment.resetEnvironment() method called). |
void |
setRefreshDelay(int delayInMS)
sets the delay in milliseconds between automatic refreshes of the plots
|
void |
setSignificanceForCI(double signifcance)
Sets the significance used for confidence intervals.
|
void |
startGUI()
Launches the GUI and automatic refresh thread.
|
void |
startNewAgent(java.lang.String agentName)
Informs the plotter that data collecton for a new agent should begin.
|
void |
startNewTrial()
Informs the plotter that a new trial of the current agent is beginning.
|
void |
toggleDataCollection(boolean collectData)
Toggle whether performance data collected from the action observation is recorded or not
|
protected void |
updateAERSeris()
Updates the average reward by episode series.
|
protected void |
updateCERSeries()
Updates the cumulative reward by episode series.
|
protected void |
updateCSESeries()
Updates the cumulative steps by episode series.
|
protected void |
updateCSRSeries()
Updates the cumulative reward by step series.
|
protected void |
updateGBConstraint(java.awt.GridBagConstraints c,
int maxCol)
Increments the x-y position of a constraint to the next position.
|
protected void |
updateMERSeris()
Updates the median reward by episode series.
|
protected void |
updateSESeries()
Updates the steps by episode series.
|
protected void |
updateTimeSeries()
Updates all the most recent trial time series with the latest data
|
void |
writeEpisodeDataToCSV(java.lang.String filePath)
Writes the episode-wise data to a csv file.
|
void |
writeStepAndEpisodeDataToCSV(java.lang.String pathAndBaseNameToUse)
Writes the step-wise and episode-wise data to CSV files.
|
void |
writeStepDataToCSV(java.lang.String filePath)
Writes the step-wise data to a csv file.
|
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected PerformancePlotter.Trial curTrial
protected PerformancePlotter.AgentDatasets curAgentDatasets
protected java.util.Map<java.lang.String,java.util.List<PerformancePlotter.Trial>> agentTrials
protected java.lang.String curAgentName
protected org.jfree.data.xy.XYSeriesCollection colCSR
protected org.jfree.data.xy.XYSeriesCollection colCER
protected org.jfree.data.xy.XYSeriesCollection colAER
protected org.jfree.data.xy.XYSeriesCollection colMER
protected org.jfree.data.xy.XYSeriesCollection colCSE
protected org.jfree.data.xy.XYSeriesCollection colSE
protected org.jfree.data.xy.YIntervalSeriesCollection colCSRAvg
protected org.jfree.data.xy.YIntervalSeriesCollection colCERAvg
protected org.jfree.data.xy.YIntervalSeriesCollection colAERAvg
protected org.jfree.data.xy.YIntervalSeriesCollection colMERAvg
protected org.jfree.data.xy.YIntervalSeriesCollection colCSEAvg
protected org.jfree.data.xy.YIntervalSeriesCollection colSEAvg
protected java.util.Set<PerformanceMetric> metricsSet
protected TrialMode trialMode
protected boolean collectData
protected int lastTimeStepUpdate
protected int lastEpisode
protected int curTimeStep
protected int curEpisode
protected int delay
protected double significance
protected boolean needsClearing
protected PerformancePlotter.MutableBoolean trialUpdateComplete
public PerformancePlotter(java.lang.String firstAgentName, int chartWidth, int chartHeight, int columns, int maxWindowHeight, TrialMode trialMode, PerformanceMetric... metrics)
firstAgentName
- the name of the first agent whose performance will be measured.chartWidth
- the width of each chart/plotchartHeight
- the height of each chart//plotcolumns
- the number of columns of the plots displayed. Plots are filled in columns first, then move down the next row.maxWindowHeight
- the maximum window height allowed before a scroll view is used.trialMode
- which plots to use; most recent trial, average over all trials, or both. If both, the most recent plot will be inserted into the window first, then the average.metrics
- the metrics that should be plotted. The metrics will appear in the window in the order that they are specified (columns first)public void setRefreshDelay(int delayInMS)
delayInMS
- the refresh delay in millisecondspublic void setSignificanceForCI(double signifcance)
signifcance
- the significance used for confidence intervals.public void toggleDataCollection(boolean collectData)
collectData
- true if data collected should be plotted; false if not.public void startGUI()
public void observeEnvironmentActionInitiation(State o, Action action)
EnvironmentObserver
Environment
receives an action to execute, but before the
Environment
has completed execution.observeEnvironmentActionInitiation
in interface EnvironmentObserver
o
- the current Environment
observation in which the the action begins execution.action
- the Action
which will be executed in the Environment
.public void observeEnvironmentInteraction(EnvironmentOutcome eo)
EnvironmentObserver
Environment
is interacted with.observeEnvironmentInteraction
in interface EnvironmentObserver
eo
- the resulting EnvironmentOutcome
public void observeEnvironmentReset(Environment resetEnvironment)
EnvironmentObserver
Environment
is reset (has the Environment.resetEnvironment()
method called).observeEnvironmentReset
in interface EnvironmentObserver
resetEnvironment
- the Environment
that was reset.public void endEpisode()
public void startNewTrial()
public void endTrial()
public void startNewAgent(java.lang.String agentName)
agentName
- the name of the agentpublic void endAllAgents()
public void writeStepAndEpisodeDataToCSV(java.lang.String pathAndBaseNameToUse)
pathAndBaseNameToUse
- the base path and file name for the epsidoe-wise and step-wise csv files.public void writeStepDataToCSV(java.lang.String filePath)
filePath
- the path to the csv file to write to.public void writeEpisodeDataToCSV(java.lang.String filePath)
filePath
- the path to the csv file to write to.protected void insertChart(java.awt.Container plotContainer, java.awt.GridBagConstraints c, int columns, int chartWidth, int chartHeight, java.lang.String title, java.lang.String xlab, java.lang.String ylab, org.jfree.data.xy.XYSeriesCollection mostRecentCollection, org.jfree.data.xy.YIntervalSeriesCollection averageCollection)
plotContainer
- the contain in which to insert the plot(s).c
- the current grid bag contraint locaiton in which the plots should be inserted.columns
- the number of columns to fill in the plot containerchartWidth
- the width of any single plotchartHeight
- the height of any single plottitle
- the title to label thep plot; if average trial plots are enabled the word "Average" will be prepended to the title for the average plot.xlab
- the xlab axis of the plotylab
- the y lab axis of the plotmostRecentCollection
- the XYSeriesCollection dataset with which the most recent trial plot is associatedaverageCollection
- the YIntervalSeriesCollection dataset with which the trial average plot is associatedprotected org.jfree.chart.renderer.xy.DeviationRenderer createDeviationRenderer()
protected void updateGBConstraint(java.awt.GridBagConstraints c, int maxCol)
c
- the constraint to incrementmaxCol
- the maximum columns allowable in a containerprotected void launchThread()
protected void updateTimeSeries()
protected void endTrialsForCurrentAgent()
protected void updateCSRSeries()
protected void updateCERSeries()
protected void updateAERSeris()
protected void updateMERSeris()
protected void updateCSESeries()
protected void updateSESeries()
protected static void accumulate(java.util.List<java.lang.Double> list, double v)
list
- the list to add and append to.v
- the value to add to the last value of list and appendprotected int[] minStepAndEpisodes(java.util.List<PerformancePlotter.Trial> trials)
trials
- the trials to perform the min overpublic static double[] getCI(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics stats, double significanceLevel)
stats
- the summary including the array of data for which the confidence interval is to be returnedsignificanceLevel
- the significance level required