org.omegahat.Numerics.Optimizers
Class PlotListener

java.lang.Object
  |
  +--org.omegahat.Graphics.Primitives.GraphicalObject
        |
        +--org.omegahat.Graphics.Primitives.RGO
              |
              +--org.omegahat.Graphics.Primitives.GraphicalContainer
                    |
                    +--org.omegahat.Graphics.Plots.DynamicTimeSeriesStack
                          |
                          +--org.omegahat.Numerics.Optimizers.PlotListener
All Implemented Interfaces:
Addable, Copyable, java.util.EventListener, GraphicalComponentInt, GraphicalContainerInt, InformationListener, IterationListener, MathOperable, ScaledComponentInt, SimpleGraphicalContainerInt, Subsettable, Tree

public class PlotListener
extends DynamicTimeSeriesStack
implements InformationListener, IterationListener

Objects to set up and maintain dynamic time-series stack plots to follow optimization.

Should be added twice to the optimizer; once as an iteration listener for events, and once as an information listener for iteration. The initial event causes the listener to create and initilize its plot stack. The information event causes the current model point to be added to the plot.


Field Summary
protected  java.lang.String[] names
          The names to be used for the parameters.
protected  int nIterations
          The number of iterations to be plotted (i.e., the X scale for the plots).
protected  boolean[] on
          Turn the individual plots on or off.
protected  OptimizerIterator opt
           
protected  ScaleInt[] scales
          An array of ScaleInt references to scales for each of the plots.
 
Fields inherited from class org.omegahat.Graphics.Plots.DynamicTimeSeriesStack
numSeries
 
Fields inherited from class org.omegahat.Graphics.Primitives.GraphicalContainer
allocator, children, origin, parent, scaleX, scaleY
 
Fields inherited from class org.omegahat.Graphics.Primitives.RGO
region
 
Fields inherited from class org.omegahat.Graphics.Primitives.GraphicalObject
ACTIVE, fontSize, lastDevice, lastHeightCM, lastRegion, lastWidthCM, parents, status, VISIBLE
 
Fields inherited from interface org.omegahat.Environment.DataStructures.MathOperable
DIVIDE, MINUS, MULTIPLY, PLUS
 
Constructor Summary
PlotListener()
           
PlotListener(ModelPointNumericInt xp, OptimizerIterator opt)
           
 
Method Summary
 boolean continueIteration(IterationEvent ev)
          The action called when the plot listener is registered as an iteration listener (for initialization only.
 ScaleInt defaultScale(double value)
          The default scaling, given only the single value.
 ScaleInt defaultScale(int which, ModelPointNumericInt model)
          Compute the default scale for plot which from the model point.
 DynamicTimeSeries findPlot(int i)
          Find the time-series plot, if any, for this index (as usual, 0 for the plot of values, etc.).
 java.lang.String[] getNames()
          Accessor for names field
 int getNIterations()
          Accessor for nIterations field
 boolean[] getOn()
          Accessor for on field
 OptimizerIterator getOpt()
          Accessor for opt field
 ScaleInt[] getScales()
          Accessor for scales field
 void iterationPerformed(IterationEvent ev)
          Method called on each iteration of the optimizer.
 void make(ModelPointNumericInt model, OptimizerIterator opt)
          The actual work of constructing the plot requires information about the model and, optionally, about the scales and which plots are desired.
 void makePlots(ModelPointNumericInt model, int nIterations)
          Fill in the DynamicTimeSeriesStack plotting object, given the scales.
 ScaleInt[] makeScales(ModelPointNumericInt model, boolean initialize)
          Construct scales and optionally initialize them to default (and very arbitrary) values.
 int nPlots(ModelPointNumericInt model)
          The number of plots allocated for in the scales (1 + 2 * N, where N is the number of parameters).
 java.lang.String[] setNames(java.lang.String[] value)
          Accessor for setting names field
 int setNIterations(int value)
          Accessor for setting nIterations field
 boolean[] setOn(boolean[] value)
          Accessor for setting on field
 OptimizerIterator setOpt(OptimizerIterator value)
          Accessor for setting opt field
 ScaleInt setScale(int which, double min, double max)
          Set an individual range.
 ScaleInt[] setScales(ScaleInt[] value)
          Accessor for setting scales field
 
Methods inherited from class org.omegahat.Graphics.Plots.DynamicTimeSeriesStack
addValue, addValues, editXScale, editYScale, getNumSeries, getTimeSeries, make
 
Methods inherited from class org.omegahat.Graphics.Primitives.GraphicalContainer
add, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addGraphicalObject, addValue, copy, copy, draw, drawChildren, get, getChild, getChildCount, getChildren, getDevice, getOrigin, getRegionAllocator, getXScale, getYScale, parent, parent, remove, removeGraphicalObject, removeGraphicalObject, setOrigin, setRegionAllocator, setXScale, setYScale, subset, subset, transform, transform
 
Methods inherited from class org.omegahat.Graphics.Primitives.RGO
center, centre, createRegionDescription, createRegionDescription, getRegion, height, height, setHJust, setRegion, setVJust, width, width, x, x, y, y
 
Methods inherited from class org.omegahat.Graphics.Primitives.GraphicalObject
cacheSize, getFontSize, getFontSize, getParameters, getParents, getStatus, isActive, isVisible, lastHeightCM, lastRegion, lastWidthCM, parents, setActive, setParameters, setParents, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.omegahat.Graphics.Primitives.GraphicalComponentInt
getParameters, getRegion, isActive, isVisible, parents, setActive, setParameters, setRegion, setVisible
 

Field Detail

opt

protected OptimizerIterator opt

nIterations

protected int nIterations
The number of iterations to be plotted (i.e., the X scale for the plots).

This defaults arbitrarily to half the maximum number of iterations when make is called.


on

protected boolean[] on
Turn the individual plots on or off. The first plot is for the value of the objective function, next one plot for each of the parameters, then one for each element of the gradient (the first two sets on by default, the last set off).

names

protected java.lang.String[] names
The names to be used for the parameters.

May be specified; if not, will be inferred from the model if possible.


scales

protected ScaleInt[] scales
An array of ScaleInt references to scales for each of the plots. The individual scales refer to particular plots by a fixed mapping: 0 for the value, 1 to N, the number of parameters, for parameter plots, then N more for gradient plots.

This mapping implies nothing about whether all these plots are to be produced; the individual scales will be null if a particular plot is not wanted.

Constructor Detail

PlotListener

public PlotListener()

PlotListener

public PlotListener(ModelPointNumericInt xp,
                    OptimizerIterator opt)
Method Detail

make

public void make(ModelPointNumericInt model,
                 OptimizerIterator opt)
The actual work of constructing the plot requires information about the model and, optionally, about the scales and which plots are desired. Given that information, make constructs the plot.

Since the plot scales will only be reconstructed if its current definition is unset or inconsistent with the model, make can be called directly, followed by settings for any of the details, before fitting starts. If it is not, default settings will be chosen.


getOpt

public OptimizerIterator getOpt()
Accessor for opt field

setOpt

public OptimizerIterator setOpt(OptimizerIterator value)
Accessor for setting opt field

getNIterations

public int getNIterations()
Accessor for nIterations field

setNIterations

public int setNIterations(int value)
Accessor for setting nIterations field

getOn

public boolean[] getOn()
Accessor for on field

setOn

public boolean[] setOn(boolean[] value)
Accessor for setting on field

getNames

public java.lang.String[] getNames()
Accessor for names field

setNames

public java.lang.String[] setNames(java.lang.String[] value)
Accessor for setting names field

getScales

public ScaleInt[] getScales()
Accessor for scales field

setScales

public ScaleInt[] setScales(ScaleInt[] value)
Accessor for setting scales field

iterationPerformed

public void iterationPerformed(IterationEvent ev)
Description copied from interface: InformationListener
Method called on each iteration of the optimizer.

Note that by definition, this includes the initial state of the iteration, corresponding to the initial values.

Specified by:
iterationPerformed in interface InformationListener

continueIteration

public boolean continueIteration(IterationEvent ev)
The action called when the plot listener is registered as an iteration listener (for initialization only.

Specified by:
continueIteration in interface IterationListener

makeScales

public ScaleInt[] makeScales(ModelPointNumericInt model,
                             boolean initialize)
Construct scales and optionally initialize them to default (and very arbitrary) values.

To construct the scales before the fitting starts, call the method with a null optimizer, and then set individual scales sensibly. Set the initialize argument to false if you plan to set all scales directly.


defaultScale

public ScaleInt defaultScale(double value)
The default scaling, given only the single value.

We can't do much, so we set the scale to -3*value, +3*value and to an arbitrary -100., 100. for 0. values.


defaultScale

public ScaleInt defaultScale(int which,
                             ModelPointNumericInt model)
Compute the default scale for plot which from the model point.


nPlots

public int nPlots(ModelPointNumericInt model)
The number of plots allocated for in the scales (1 + 2 * N, where N is the number of parameters). The default method for making the plots only sets up the first (1+N) of these, omitting the N gradient plots.

setScale

public ScaleInt setScale(int which,
                         double min,
                         double max)
Set an individual range.

The plots are indexed 0 for the value, 1 - N for the individual parameters, N+1 to 2*N for the elements of the gradient. Setting a scale does not alter whether the corresponding plot is currently on (use the elements of the on property for that).


findPlot

public DynamicTimeSeries findPlot(int i)
Find the time-series plot, if any, for this index (as usual, 0 for the plot of values, etc.). If this plot is not turned on, or if the plots have not been made, returns null.

makePlots

public void makePlots(ModelPointNumericInt model,
                      int nIterations)
Fill in the DynamicTimeSeriesStack plotting object, given the scales.