ca.nengo.model.impl
Class NetworkImpl

java.lang.Object
  extended by ca.nengo.model.impl.NetworkImpl
All Implemented Interfaces:
Network, Node, Probeable, Resettable, SimulationMode.ModeConfigurable, VisiblyMutable, VisiblyMutable.Listener, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
PyramidalNetwork

public class NetworkImpl
extends java.lang.Object
implements Network, VisiblyMutable, VisiblyMutable.Listener

Default implementation of Network.

Author:
Bryan Tripp
See Also:
Serialized Form

Nested Class Summary
 class NetworkImpl.OriginWrapper
          Wraps an Origin with a new name (for exposing outside Network).
 class NetworkImpl.TerminationWrapper
          Wraps a Termination with a new name (for exposing outside Network).
 
Nested classes/interfaces inherited from interface ca.nengo.util.VisiblyMutable
VisiblyMutable.Event, VisiblyMutable.Listener, VisiblyMutable.NameChangeEvent, VisiblyMutable.NodeRemovedEvent
 
Field Summary
static java.lang.String DEFAULT_NAME
           
 
Constructor Summary
NetworkImpl()
           
 
Method Summary
 void addChangeListener(VisiblyMutable.Listener listener)
           
 void addNode(Node node)
           
 Projection addProjection(Origin origin, Termination termination)
          Connects an Origin to a Termination.
 void changed(VisiblyMutable.Event e)
          Handles any changes/errors that may arise from objects within the network changing.
 Network clone()
           
 void exposeOrigin(Origin origin, java.lang.String name)
          Declares the given Origin as available for connection outside the Network via getOrigins().
 void exposeState(Probeable probeable, java.lang.String stateName, java.lang.String name)
          Declares the given Probeable state as being available for Probing from outside this Network.
 void exposeTermination(Termination termination, java.lang.String name)
          Declares the given Termination as available for connection from outside the Network via getTerminations().
 void fixMode()
           
 java.lang.String getDocumentation()
           
 java.lang.String getExposedOriginName(Origin insideOrigin)
          Returns the name of the exposed origin given the inner origin.
 java.lang.String getExposedTerminationName(Termination insideTermination)
          Returns the name of the exposed termination given the inner termination.
 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).
 java.lang.Object getMetaData(java.lang.String key)
          Metadata is non-critical information about the Network (eg UI layout) that the user doesn't access directly.
 SimulationMode getMode()
           
 java.lang.String getName()
           
 Node getNode(java.lang.String name)
           
 java.util.ArrayList<Origin> getNodeOrigins()
          Gathers all the origins of nodes contained in this network.
 Node[] getNodes()
           
 java.util.ArrayList<Termination> getNodeTerminations()
          Gathers all the terminations of nodes contained in this network.
 Origin getOrigin(java.lang.String name)
           
 Origin[] getOrigins()
           
 Projection[] getProjections()
           
 Simulator getSimulator()
           
 float getStepSize()
           
 Termination getTermination(java.lang.String name)
           
 Termination[] getTerminations()
           
 void hideOrigin(java.lang.String name)
          Undoes exposeOrigin(x, x, name).
 void hideState(java.lang.String name)
          Undoes exposeState(x, x, name).
 void hideTermination(java.lang.String name)
          Undoes exposeTermination(x, x, name).
 void killNeurons(float killrate)
          Kills a certain percentage of neurons in the network (recursively including subnetworks).
 void killNeurons(float killrate, boolean saveRelays)
          Kills a certain percentage of neurons in the network (recursively including subnetworks).
 java.util.Properties listStates()
           
 void removeChangeListener(VisiblyMutable.Listener listener)
           
 void removeNode(java.lang.String name)
           
 void removeProjection(Termination termination)
           
 void reset(boolean randomize)
           
 void run(float startTime, float endTime)
          Runs the Node (including all its components), updating internal state and outputs as needed.
 void run(float startTime, float endTime, boolean topLevel)
          Runs the model with the optional parameter topLevel.
 void setDocumentation(java.lang.String text)
           
 void setMetaData(java.lang.String key, java.lang.Object value)
           
 void setMode(SimulationMode mode)
          Sets the object to run in either the given mode or the closest mode that it supports (all ModeConfigurables must support SimulationMode.DEFAULT, and must default to this mode).
protected  void setMyMode(SimulationMode mode)
           
 void setName(java.lang.String name)
           
 void setSimulator(Simulator simulator)
           
 void setStepSize(float stepSize)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAME

public static final java.lang.String DEFAULT_NAME
See Also:
Constant Field Values
Constructor Detail

NetworkImpl

public NetworkImpl()
Method Detail

setSimulator

public void setSimulator(Simulator simulator)
Specified by:
setSimulator in interface Network
Parameters:
simulator - Simulator with which to run this Network

getSimulator

public Simulator getSimulator()
Specified by:
getSimulator in interface Network
Returns:
Simulator used to run this Network (a LocalSimulator by default)

setStepSize

public void setStepSize(float stepSize)
Parameters:
stepSize - New timestep size at which to simulate Network (some components of the network may run with different step sizes, but information is exchanged between components with this step size). Defaults to 0.001s.

getStepSize

public float getStepSize()
Returns:
Timestep size at which Network is simulated.

addNode

public void addNode(Node node)
             throws StructuralException
Specified by:
addNode in interface Network
Parameters:
node - Node to add to the Network
Throws:
StructuralException - if the Network already contains a Node of the same name
See Also:
Network.addNode(ca.nengo.model.Node)

killNeurons

public void killNeurons(float killrate)
Kills a certain percentage of neurons in the network (recursively including subnetworks).

Parameters:
killrate - the percentage (0.0 to 1.0) of neurons to kill

killNeurons

public void killNeurons(float killrate,
                        boolean saveRelays)
Kills a certain percentage of neurons in the network (recursively including subnetworks).

Parameters:
killrate - the percentage (0.0 to 1.0) of neurons to kill
saveRelays - if true, exempt populations with only one node from the slaughter

changed

public void changed(VisiblyMutable.Event e)
             throws StructuralException
Handles any changes/errors that may arise from objects within the network changing.

Specified by:
changed in interface VisiblyMutable.Listener
Parameters:
e - An object that has changed in some way (all properties that influence the display of the object should be checked)
Throws:
StructuralException
See Also:
VisiblyMutable.Listener.changed(ca.nengo.util.VisiblyMutable.Event)

getNodeTerminations

public java.util.ArrayList<Termination> getNodeTerminations()
Gathers all the terminations of nodes contained in this network.

Returns:
arraylist of terminations

getNodeOrigins

public java.util.ArrayList<Origin> getNodeOrigins()
Gathers all the origins of nodes contained in this network.

Returns:
arraylist of origins

getNodes

public Node[] getNodes()
Specified by:
getNodes in interface Network
Returns:
All the Nodes in the Network
See Also:
Network.getNodes()

getNode

public Node getNode(java.lang.String name)
             throws StructuralException
Specified by:
getNode in interface Network
Parameters:
name - Name of Node to remove
Returns:
Named node
Throws:
StructuralException - if named Node does not exist in network
See Also:
Network.getNode(java.lang.String)

removeNode

public void removeNode(java.lang.String name)
                throws StructuralException
Specified by:
removeNode in interface Network
Parameters:
name - Name of Node to remove
Throws:
StructuralException - if named Node does not exist in network
See Also:
Network.removeNode(java.lang.String)

addProjection

public Projection addProjection(Origin origin,
                                Termination termination)
                         throws StructuralException
Description copied from interface: Network
Connects an Origin to a Termination. Origins and Terminations belong to Ensembles (or ExternalInputs). Both the Origin and Termination must be set up before calling this method. The way to do this will depend on the Ensemble.

Specified by:
addProjection in interface Network
Parameters:
origin - Origin (data source) of Projection.
termination - Termination (data destination) of Projection.
Throws:
StructuralException - if the given Origin and Termination have different dimensions, or if there is already an Origin connected to the given Termination (note that an Origin can project to multiple Terminations though).
See Also:
Network.addProjection(ca.nengo.model.Origin, ca.nengo.model.Termination)

getProjections

public Projection[] getProjections()
Specified by:
getProjections in interface Network
Returns:
All Projections in this Network
See Also:
Network.getProjections()

removeProjection

public void removeProjection(Termination termination)
                      throws StructuralException
Specified by:
removeProjection in interface Network
Parameters:
termination - Termination of Projection to remove
Throws:
StructuralException - if there exists no Projection between the specified Origin and Termination
See Also:
Network.removeProjection(ca.nengo.model.Termination)

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 - New name of Network (must be unique within any networks of which this one will be a part)
Throws:
StructuralException

setMode

public void setMode(SimulationMode mode)
Description copied from interface: SimulationMode.ModeConfigurable
Sets the object to run in either the given mode or the closest mode that it supports (all ModeConfigurables must support SimulationMode.DEFAULT, and must default to this mode).

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)

setMyMode

protected void setMyMode(SimulationMode mode)

fixMode

public void fixMode()

getMode

public SimulationMode getMode()
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
Description copied from interface: Node
Runs the Node (including all its components), updating internal state and outputs as needed. Runs should be short (eg 1ms), because inputs can not be changed during a run, and outputs will only be communicated to other Nodes after a run.

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)

run

public void run(float startTime,
                float endTime,
                boolean topLevel)
         throws SimulationException
Runs the model with the optional parameter topLevel.

Parameters:
topLevel - true if the network being run is the top level network, false if it is a subnetwork
Throws:
SimulationException

reset

public void reset(boolean randomize)
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)

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:
History of values for the named state variable. The history must cover the most recent network time step, and no more. There should be no overlap in the time points returned for different steps.
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()

exposeOrigin

public void exposeOrigin(Origin origin,
                         java.lang.String name)
Description copied from interface: Network
Declares the given Origin as available for connection outside the Network via getOrigins(). This Origin should not be connected within this Network.

Specified by:
exposeOrigin in interface Network
Parameters:
origin - An Origin within this Network that is to connect to something outside this Network
name - Name of the Origin as it will appear outside this Network
See Also:
Network.exposeOrigin(ca.nengo.model.Origin, java.lang.String)

hideOrigin

public void hideOrigin(java.lang.String name)
                throws StructuralException
Description copied from interface: Network
Undoes exposeOrigin(x, x, name).

Specified by:
hideOrigin in interface Network
Parameters:
name - Name of Origin to unexpose.
Throws:
StructuralException
See Also:
Network.hideOrigin(java.lang.String)

getExposedOriginName

public java.lang.String getExposedOriginName(Origin insideOrigin)
Description copied from interface: Network
Returns the name of the exposed origin given the inner origin. Returns null if no such origin is exposed.

Specified by:
getExposedOriginName in interface Network
Parameters:
insideOrigin - Origin inside the network
See Also:
Network.getExposedOriginName(ca.nengo.model.Origin)

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)

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()

exposeTermination

public void exposeTermination(Termination termination,
                              java.lang.String name)
Description copied from interface: Network
Declares the given Termination as available for connection from outside the Network via getTerminations(). This Termination should not be connected within this Network.

Specified by:
exposeTermination in interface Network
Parameters:
termination - A Termination within this Network that is to connect to something outside this Network
name - Name of the Termination as it will appear outside this Network
See Also:
Network.exposeTermination(ca.nengo.model.Termination, java.lang.String)

hideTermination

public void hideTermination(java.lang.String name)
Description copied from interface: Network
Undoes exposeTermination(x, x, name).

Specified by:
hideTermination in interface Network
Parameters:
name - Name of Termination to unexpose.
See Also:
Network.hideTermination(java.lang.String)

getExposedTerminationName

public java.lang.String getExposedTerminationName(Termination insideTermination)
Description copied from interface: Network
Returns the name of the exposed termination given the inner termination. Returns null if no such termination is exposed.

Specified by:
getExposedTerminationName in interface Network
Parameters:
insideTermination - Termination inside the network
See Also:
Network.getExposedTerminationName(ca.nengo.model.Termination)

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)

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()

exposeState

public void exposeState(Probeable probeable,
                        java.lang.String stateName,
                        java.lang.String name)
                 throws StructuralException
Description copied from interface: Network
Declares the given Probeable state as being available for Probing from outside this Network.

Specified by:
exposeState in interface Network
Parameters:
probeable - A Probeable within this Network.
stateName - A state of the given Probeable
name - A new name with which to access this state via Network.getHistory
Throws:
StructuralException
See Also:
Network.exposeState(ca.nengo.model.Probeable, java.lang.String, java.lang.String)

hideState

public void hideState(java.lang.String name)
Description copied from interface: Network
Undoes exposeState(x, x, name).

Specified by:
hideState in interface Network
Parameters:
name - Name of state to unexpose.
See Also:
Network.hideState(java.lang.String)

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)

getMetaData

public java.lang.Object getMetaData(java.lang.String key)
Description copied from interface: Network
Metadata is non-critical information about the Network (eg UI layout) that the user doesn't access directly. (Note: if there is a need for user-accessible metadata, Network could extend Configurable, but this doesn't seem to be necessary.)

Specified by:
getMetaData in interface Network
Parameters:
key - Name of a metadata item
Returns:
Value of a metadata item
See Also:
Network.getMetaData(java.lang.String)

setMetaData

public void setMetaData(java.lang.String key,
                        java.lang.Object value)
Specified by:
setMetaData in interface Network
Parameters:
key - Name of a metadata item
value - Value of the named metadata item
See Also:
Network.setMetaData(java.lang.String, java.lang.Object)

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)

clone

public Network 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