ca.nengo.model.impl
Class AbstractEnsemble

java.lang.Object
  extended by ca.nengo.model.impl.AbstractEnsemble
All Implemented Interfaces:
Ensemble, Node, Probeable, Resettable, SimulationMode.ModeConfigurable, VisiblyMutable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
EnsembleImpl

public abstract class AbstractEnsemble
extends java.lang.Object
implements Ensemble, Probeable, VisiblyMutable

Abstract class that can be used as a basis for Ensemble implementations.

Author:
Bryan Tripp
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.nengo.util.VisiblyMutable
VisiblyMutable.Event, VisiblyMutable.Listener, VisiblyMutable.NameChangeEvent, VisiblyMutable.NodeRemovedEvent
 
Field Summary
protected  Node[] myNodes
           
protected  java.util.Map<java.lang.String,EnsembleTermination> myTerminations
           
 
Constructor Summary
AbstractEnsemble(java.lang.String name, Node[] nodes)
          Note that setMode(SimulationMode.DEFAULT) is called at construction time.
 
Method Summary
 void addChangeListener(VisiblyMutable.Listener listener)
           
 Ensemble clone()
           
 void collectSpikes(boolean collect)
           
static java.util.List<java.lang.String> findCommon1DOrigins(Node[] nodes)
           
protected  void fireVisibleChangeEvent()
          Called by subclasses when properties have changed in such a way that the display of the ensemble may need updating.
 int getCollectSpikesRatio()
           
 java.lang.String getDocumentation()
           
 TimeSeries getHistory(java.lang.String stateName)
          Note that the units of TimeSeries' for a given state do not change over time (ie at different time steps).
 SimulationMode getMode()
          Note that this reflects the latest mode requested of the Ensemble, and that individual Neurons may run in different modes (see setMode).
 java.lang.String getName()
           
 Node[] getNodes()
           
 Origin getOrigin(java.lang.String name)
           
 Origin[] getOrigins()
           
 SpikePattern getSpikePattern()
          This method provides a means of efficiently storing the output of an Ensemble if the component Nodes have Origins that produce SpikeOutput.
 Termination getTermination(java.lang.String name)
           
 Termination[] getTerminations()
           
 boolean isCollectingSpikes()
           
 java.util.Properties listStates()
           
 void redefineNodes(Node[] nodes)
          Replaces the set of nodes inside the Ensemble
 void removeChangeListener(VisiblyMutable.Listener listener)
           
 void reset(boolean randomize)
          Resets each Node in this Ensemble.
 void run(float startTime, float endTime)
          Runs each neuron in the Ensemble.
 void setCollectSpikesRatio(int n)
           
 void setDocumentation(java.lang.String text)
           
 void setMode(SimulationMode mode)
          When this method is called, setMode(...) is called on each Node in the Ensemble.
 void setName(java.lang.String name)
           
 void setSpikePattern(float[] spikes, float endTime)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myNodes

protected Node[] myNodes

myTerminations

protected java.util.Map<java.lang.String,EnsembleTermination> myTerminations
Constructor Detail

AbstractEnsemble

public AbstractEnsemble(java.lang.String name,
                        Node[] nodes)
Note that setMode(SimulationMode.DEFAULT) is called at construction time.

Parameters:
name - Unique name of Ensemble
nodes - Nodes that Ensemble contains
Method Detail

redefineNodes

public void redefineNodes(Node[] nodes)
Replaces the set of nodes inside the Ensemble

Specified by:
redefineNodes in interface Ensemble

getName

public java.lang.String getName()
Specified by:
getName in interface Node
Returns:
Name of Node (must be unique in a Network)
See Also:
Node.getName()

setName

public void setName(java.lang.String name)
             throws StructuralException
Specified by:
setName in interface Node
Parameters:
name - The new name
Throws:
StructuralException

getNodes

public Node[] getNodes()
Specified by:
getNodes in interface Ensemble
Returns:
Nodes that make up the Ensemble
See Also:
Ensemble.getNodes()

setMode

public void setMode(SimulationMode mode)
When this method is called, setMode(...) is called on each Node in the Ensemble. Each Node will then run in the mode that is closest to the requested mode (this could be different for different Node). Note that at Ensemble construction time, setMode(SimulationMode.DEFAULT) is called.

Specified by:
setMode in interface SimulationMode.ModeConfigurable
Parameters:
mode - SimulationMode in which it is desired that the object runs.
See Also:
SimulationMode.ModeConfigurable.setMode(ca.nengo.model.SimulationMode)

getMode

public SimulationMode getMode()
Note that this reflects the latest mode requested of the Ensemble, and that individual Neurons may run in different modes (see setMode).

Specified by:
getMode in interface SimulationMode.ModeConfigurable
Returns:
The SimulationMode in which the object is running
See Also:
SimulationMode.ModeConfigurable.getMode()

run

public void run(float startTime,
                float endTime)
         throws SimulationException
Runs each neuron in the Ensemble.

Specified by:
run in interface Node
Parameters:
startTime - simulation time at which running starts (s)
endTime - simulation time at which running ends (s)
Throws:
SimulationException - if a problem is encountered while trying to run
See Also:
Node.run(float, float)

reset

public void reset(boolean randomize)
Resets each Node in this Ensemble.

Specified by:
reset in interface Resettable
Parameters:
randomize - True indicates that the object should be reset to a randomly selected initial state (the object must be aware of the distribution from which to draw from). False indicates that the object should be reset to a fixed initial state (which it must also know). Some objects may not support randomization of the initial state, in which case a fixed state will be used in either case.
See Also:
Resettable.reset(boolean)

getOrigin

public Origin getOrigin(java.lang.String name)
                 throws StructuralException
Specified by:
getOrigin in interface Node
Parameters:
name - Name of an Origin on this Node
Returns:
The named Origin if it exists
Throws:
StructuralException - if the named Origin does not exist
See Also:
Node.getOrigin(java.lang.String)

getTermination

public Termination getTermination(java.lang.String name)
                           throws StructuralException
Specified by:
getTermination in interface Node
Parameters:
name - Name of a Termination onto this Node
Returns:
The named Termination if it exists
Throws:
StructuralException - if the named Termination does not exist
See Also:
Node.getTermination(java.lang.String)

getOrigins

public Origin[] getOrigins()
Specified by:
getOrigins in interface Node
Returns:
Sets of ouput channels (eg spiking outputs, gap junctional outputs, etc.)
See Also:
Node.getOrigins()

getTerminations

public Termination[] getTerminations()
Specified by:
getTerminations in interface Node
Returns:
Sets of input channels (these have the same dimension as corresponding Origins to which they are connected).
See Also:
Node.getTerminations()

collectSpikes

public void collectSpikes(boolean collect)
Specified by:
collectSpikes in interface Ensemble
Parameters:
collect - If true, the spike pattern is recorded in subsequent runs and is available through getSpikePattern() (defaults to false)
See Also:
Ensemble.collectSpikes(boolean)

isCollectingSpikes

public boolean isCollectingSpikes()
Specified by:
isCollectingSpikes in interface Ensemble
Returns:
true if the spike pattern will be recorded in subsequent runs
See Also:
Ensemble.isCollectingSpikes()

getCollectSpikesRatio

public int getCollectSpikesRatio()
Returns:
Inverse of the proportion of nodes from which to collect spikes

setCollectSpikesRatio

public void setCollectSpikesRatio(int n)
Parameters:
n - Inverse of the proportion of nodes from which to collect spikes

getSpikePattern

public SpikePattern getSpikePattern()
Description copied from interface: Ensemble
This method provides a means of efficiently storing the output of an Ensemble if the component Nodes have Origins that produce SpikeOutput.

Specified by:
getSpikePattern in interface Ensemble
Returns:
A SpikePattern containing a record of spikes, provided collectSpikes(boolean) has been set to true
See Also:
Ensemble.getSpikePattern()

setSpikePattern

public void setSpikePattern(float[] spikes,
                            float endTime)

getHistory

public TimeSeries getHistory(java.lang.String stateName)
                      throws SimulationException
Description copied from interface: Probeable
Note that the units of TimeSeries' for a given state do not change over time (ie at different time steps). CAUTION: The TimeSeries should not contain a reference to any arrays that you are going to change later. The caller owns what you return.

Specified by:
getHistory in interface Probeable
Parameters:
stateName - A state variable name
Returns:
Composite of Node states by given name. States of different nodes may be defined at different times, so only the states at the end of the most recent step are given. Only the first dimension of each Node state is included in the composite.
Throws:
SimulationException - if the Probeable does not have the requested state
See Also:
Probeable.getHistory(java.lang.String)

listStates

public java.util.Properties listStates()
Specified by:
listStates in interface Probeable
Returns:
List of state variable names, eg "V", and associated descriptions eg "membrane potential (mV)"
See Also:
Probeable.listStates()

findCommon1DOrigins

public static java.util.List<java.lang.String> findCommon1DOrigins(Node[] nodes)
Parameters:
nodes - A list of Nodes
Returns:
Names of one-dimensional origins that are shared by all the nodes

getDocumentation

public java.lang.String getDocumentation()
Specified by:
getDocumentation in interface Node
Returns:
User-specified documentation for the Node, if any
See Also:
Node.getDocumentation()

setDocumentation

public void setDocumentation(java.lang.String text)
Specified by:
setDocumentation in interface Node
Parameters:
text - New user-specified documentation for the Node
See Also:
Node.setDocumentation(java.lang.String)

addChangeListener

public void addChangeListener(VisiblyMutable.Listener listener)
Specified by:
addChangeListener in interface VisiblyMutable
Parameters:
listener - Listener to add
See Also:
VisiblyMutable.addChangeListener(ca.nengo.util.VisiblyMutable.Listener)

removeChangeListener

public void removeChangeListener(VisiblyMutable.Listener listener)
Specified by:
removeChangeListener in interface VisiblyMutable
Parameters:
listener - Listener to remove
See Also:
VisiblyMutable.removeChangeListener(ca.nengo.util.VisiblyMutable.Listener)

fireVisibleChangeEvent

protected void fireVisibleChangeEvent()
Called by subclasses when properties have changed in such a way that the display of the ensemble may need updating.


clone

public Ensemble clone()
               throws java.lang.CloneNotSupportedException
Specified by:
clone in interface Node
Overrides:
clone in class java.lang.Object
Returns:
An independent copy of the Node
Throws:
java.lang.CloneNotSupportedException