Class Mean

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, ProvidesResize, RequiresResize, AbstractGraph.Shifter, AbstractGraph.Zoomer, ChangeListener, LifecycleListener, RunListener, SampleListener

public class Mean extends AbstractView<LineGraph> implements AbstractGraph.Shifter, AbstractGraph.Zoomer
A view that displays time-series plots of mean trait values or mean fitness for the current EvoLudo model using one or more LineGraph panels.

Responsibilities

  • Create and manage the set of LineGraph panels appropriate for the current model configuration (one panel per discrete species, or one panel per continuous trait when the model is continuous).
  • Configure visual style for each graph (labels, y-range, colors, markers) depending on whether the data represents TRAIT or FITNESS and whether the underlying model is continuous or discrete.
  • Collect mean values from the model and push them to the graphs on updates; supports both mean +/- standard deviation (continuous) and per-trait frequencies/mean payoffs (discrete).
  • Manage zooming and shifting of displayed window of time series data.
  • Handle layout, sizing and resetting of graphs when model settings change.

Exports

Supports exporting graphs as SVG and PNG as well as exporting the mean time series data as CSV).
Author:
Christoph Hauert
See Also:
  • Field Details

    • state

      double[] state
      The state of the model at the current time.
  • Constructor Details

    • Mean

      public Mean(EvoLudoGWT engine, Data type)
      Construct a new view to display the time series data of the current EvoLudo model.
      Parameters:
      engine - the pacemaker for running the model
      type - the type of data to display
  • Method Details

    • getName

      public String getName()
      Description copied from class: AbstractView
      Get the name of this view. This is used to dynamically build the view selector.
      Specified by:
      getName in class AbstractView<LineGraph>
      Returns:
      the name of this view
    • allocateGraphs

      protected boolean allocateGraphs()
      Description copied from class: AbstractView
      Allocate all graphs managed by this view. This is called when loading the view. Once all views are attached to the browser DOM a call to the graph's calcBounds(int, int) is triggered through setBounds(int, int) to properly calculate the layout.
      Specified by:
      allocateGraphs in class AbstractView<LineGraph>
      Returns:
      true if graphs were (re)allocated
      See Also:
    • addLineGraph

      private void addLineGraph(Module<?> module)
      Create and register the LineGraph(s) for a single module: one graph for the module, and additional graphs for extra traits when the model is continuous.
      Parameters:
      module - module for which graphs should be created
    • reset

      public void reset(boolean hard)
      Description copied from class: AbstractView
      Called when a module has been reset. All graphs are reset and updated if needed, unless hard is true.
      Overrides:
      reset in class AbstractView<LineGraph>
      Parameters:
      hard - the flag to indicate whether to do a hard reset
    • setupDTraitGraph

      private void setupDTraitGraph(LineGraph graph)
      Configure a graph style and colors for a discrete module (multiple traits).
      Parameters:
      graph - the graph to configure
    • setupCTraitGraph

      private void setupCTraitGraph(LineGraph graph, int idx)
      Configure a graph style and colors for a single continuous trait.
      Parameters:
      graph - the graph to configure
      idx - the index of the trait
    • setFitRange

      private boolean setFitRange(LineGraph graph)
      Set the y-range for fitness graphs; returns true if the range changed.
      Parameters:
      graph - the graph to configure
      Returns:
      true if the y-range changed
    • setupDFitGraph

      private void setupDFitGraph(LineGraph graph)
      Configure a graph style and colors for fitness in discrete models.
      Parameters:
      graph - the graph to configure
    • setupCFitGraph

      private void setupCFitGraph(LineGraph graph)
      Configure a graph style and colors for fitness in continuous models.
      Parameters:
      graph - the graph to configure
    • finishGraphSetup

      private void finishGraphSetup(LineGraph graph, boolean hard)
      Finalize the setup of a graph (x-label, x-range, module label).
      Parameters:
      graph - the graph to configure
      hard - if true, forces a hard reset of the graph
    • modelSettings

      public void modelSettings()
      Description copied from interface: RunListener
      Called when the settings of the EvoLudo model changed but no reset was necessary.
      Specified by:
      modelSettings in interface RunListener
    • modelDidInit

      public void modelDidInit()
      Description copied from interface: RunListener
      Called after the EvoLudo model got re-initialized.
      Specified by:
      modelDidInit in interface RunListener
      Overrides:
      modelDidInit in class AbstractView<LineGraph>
    • update

      public void update(boolean force)
      Description copied from class: AbstractView
      Called when the view needs updating. This gets called when the selected view changed or new data is available from the model. Views may ignore updating requests unless force is true.
      Specified by:
      update in class AbstractView<LineGraph>
      Parameters:
      force - true to force the update
    • updateGraph

      private int updateGraph(LineGraph graph, Module<?> module, int idx, double newtime)
      Pull updated mean data for the supplied graph and append it to the data buffer.
      Parameters:
      graph - graph to update
      module - module currently being processed
      idx - index offset used when processing multiple traits
      newtime - latest simulation time
      Returns:
      updated index offset for subsequent graphs
    • updateDTraitGraph

      private double[] updateDTraitGraph(int nState)
      Build the data array for a discrete-trait graph.
      Parameters:
      nState - number of traits
      Returns:
      data array (time slot left unassigned)
    • updateCTraitGraph

      private double[] updateCTraitGraph(int nState, int idx)
      Build the data array for a continuous-trait graph (mean +/- stddev).
      Parameters:
      nState - number of traits
      idx - state offset of the current trait
      Returns:
      data array (time slot left unassigned)
    • updateDFitGraph

      private double[] updateDFitGraph(int nState)
      Build the data array for discrete fitness graphs.
      Parameters:
      nState - number of traits
      Returns:
      data array (time slot left unassigned)
    • updateCFitGraph

      private double[] updateCFitGraph()
      Build the data array for continuous fitness graphs (mean +/- stddev).
      Returns:
      data array (time slot left unassigned)
    • exportTypes

      protected AbstractView.ExportType[] exportTypes()
      Description copied from class: AbstractView
      Return the list of export types that are acceptable for _all_ graphs in this view.
      Overrides:
      exportTypes in class AbstractView<LineGraph>
      Returns:
      the list of viable export types