public class MultiAgentPerformancePlotter extends javax.swing.JFrame implements WorldObserver
PerformanceMetric
enumerator. A plot showing the most recent
"trial" of the agents 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 first the constructor should be called, then the startGUI()
method. At the start of each trial, the startNewTrial()
method should be called
(although it is unncessary to call this method if it is the *first* trial since that will automatically be created.) A world object should then be created
with this object attached to it. The world should then be run for as many episodes as desired until the next trial when things repeat. After all trials
are complete, the startNewTrial()
method should be called.
To ensure proper use of this class, it is highly recommended that the MultiAgentExperimenter
class is used, because it will perform all the necessary steps for you.
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 |
MultiAgentPerformancePlotter.AgentDatasets
A datastructure for maintain the plot series data in the current agent
|
protected class |
MultiAgentPerformancePlotter.DatasetsAndTrials
A class for storing the tiral data and series datasets for a given agent.
|
protected class |
MultiAgentPerformancePlotter.MutableBoolean
A class for a mutable boolean
|
protected class |
MultiAgentPerformancePlotter.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,MultiAgentPerformancePlotter.DatasetsAndTrials> |
agentWiseData
Datastructure for maintaining data for each agent playing in the game.
|
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 int |
curEpisode
the current episode that was recorded
|
protected int |
curTimeStep
the current time step that was recorded
|
int |
debugCode
The debug code used for debug printing.
|
protected int |
delay
the delay in milliseconds between which the charts are updated automatically
|
protected boolean |
freshStart
Indicates whether this observer has observed any outcomes yet.
|
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 TerminalFunction |
tf
Terminal funciton for determining when episodes have ended.
|
protected TrialMode |
trialMode
specifies whether the most recent trial, average of all trials, or both plots will be displayed
|
protected MultiAgentPerformancePlotter.MutableBoolean |
trialUpdateComplete
Synchronization object to ensure proper threaded plot updating
|
protected World |
world |
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 |
---|
MultiAgentPerformancePlotter(TerminalFunction tf,
int chartWidth,
int chartHeight,
int columns,
int maxWindowHeight,
TrialMode trialMode,
PerformanceMetric... metrics)
Initializes
|
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 |
endAllTrials()
Specifies that all trials are complete and that the average trial results and error bars should be plotted.
|
protected void |
endAllTrialsForAgent(java.lang.String agentName)
Ends all the trials, plotting the average trial data for the agent with the given name
|
protected void |
endAllTrialsHelper()
The end all trial methods helper called at the end of a swing update.
|
protected void |
endTrial()
Ends the current trial data and updates the plots accordingly.
|
void |
gameEnding(State s)
This method is called whenever a game in a world ends.
|
void |
gameStarting(State s)
This method is called whenever a new game in a world is starting.
|
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<MultiAgentPerformancePlotter.Trial> trials)
Returns the minimum steps and episodes across all trials
|
void |
observe(State s,
JointAction ja,
double[] reward,
State sp)
This method is called whenever an interaction in the world occurs.
|
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 |
setWorld(World world) |
void |
startGUI()
Launches the GUI and automatic refresh thread.
|
void |
startNewTrial()
Initializes the datastructures for a new trial.
|
void |
toggleDataCollection(boolean collectData)
Toggle whether performance data collected from the action observation is recorded or not
|
protected void |
updateAERSeris(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
Updates the average reward by episode series.
|
protected void |
updateCERSeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
Updates the cumulative reward by episode series.
|
protected void |
updateCSESeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
Updates the cumulative steps by episode series.
|
protected void |
updateCSRSeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
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(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
Updates the median reward by episode series.
|
protected void |
updateMostRecentSeriesHelper()
Updates the series data for the most recent trial plots.
|
protected void |
updateSESeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
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 TerminalFunction tf
protected java.util.Map<java.lang.String,MultiAgentPerformancePlotter.DatasetsAndTrials> agentWiseData
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 boolean freshStart
protected MultiAgentPerformancePlotter.MutableBoolean trialUpdateComplete
public int debugCode
protected World world
public MultiAgentPerformancePlotter(TerminalFunction tf, int chartWidth, int chartHeight, int columns, int maxWindowHeight, TrialMode trialMode, PerformanceMetric... metrics)
tf
- the terminal function that will be used for detecting the end of episdoeschartWidth
- the width of a cartchartHeight
- the height of a chartcolumns
- the number of columns of chartsmaxWindowHeight
- the maximum window height until a scroll bar will be addedtrialMode
- the kinds of trail data that will be displayedmetrics
- which metrics will be plotted.public void setWorld(World world)
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 containerpublic void startGUI()
protected void launchThread()
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 gameStarting(State s)
WorldObserver
gameStarting
in interface WorldObserver
s
- the state in which the world is starting.public void observe(State s, JointAction ja, double[] reward, State sp)
WorldObserver
observe
in interface WorldObserver
s
- the previous state of the worldja
- the joint action taken in the worldreward
- the joint reward received by the agentssp
- the next state of the worldpublic void gameEnding(State s)
WorldObserver
gameEnding
in interface WorldObserver
s
- the final state of the world when it ends.public void startNewTrial()
public void writeStepAndEpisodeDataToCSV(java.lang.String pathAndBaseNameToUse)
pathAndBaseNameToUse
- the base path and file name for the episode-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 endTrial()
public void endAllTrials()
protected void endAllTrialsHelper()
protected void endAllTrialsForAgent(java.lang.String agentName)
agentName
- the name of the agent whose trial data will be completed and plottedprotected void updateTimeSeries()
protected void updateMostRecentSeriesHelper()
protected int[] minStepAndEpisodes(java.util.List<MultiAgentPerformancePlotter.Trial> trials)
trials
- the trials to perform the min overprotected 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 appendpublic 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 requiredprotected void updateCSRSeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
agentData
- the agent datasetprotected void updateCERSeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
agentData
- the agent datasetprotected void updateAERSeris(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
agentData
- the agent datasetprotected void updateMERSeris(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
agentData
- the agent datasetprotected void updateCSESeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
agentData
- the agent datasetprotected void updateSESeries(MultiAgentPerformancePlotter.DatasetsAndTrials agentData)
agentData
- the agent dataset