public class NetworkImpl extends java.lang.Object implements Network, VisiblyMutable, VisiblyMutable.Listener, TaskSpawner
Modifier and Type | Class and Description |
---|---|
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).
|
VisiblyMutable.Event, VisiblyMutable.Listener, VisiblyMutable.NameChangeEvent, VisiblyMutable.NodeRemovedEvent
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_NAME
Default name for a Network
|
protected int |
myNumGPU |
protected int |
myNumJavaThreads |
protected boolean |
myUseGPU |
Constructor and Description |
---|
NetworkImpl()
Sets up a network's data structures
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(VisiblyMutable.Listener listener) |
void |
addNode(Node node) |
Projection |
addProjection(Origin origin,
Termination termination)
Connects an Origin to a Termination.
|
void |
addStepListener(StepListener listener) |
void |
addTasks(ThreadTask[] tasks) |
void |
changed(VisiblyMutable.Event e)
Handles any changes/errors that may arise from objects within the network changing.
|
Network |
clone() |
int |
countNeurons()
Counts how many neurons are contained within this network.
|
void |
dumpToScript() |
void |
dumpToScript(java.lang.String filepath) |
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 |
fireStepListeners(float time) |
void |
fixMode()
Fix the simulation mode to the current mode.
|
void |
fixMode(SimulationMode[] modes)
Set the allowed simulation modes.
|
Node[] |
getChildren() |
java.lang.String |
getDocumentation() |
java.lang.String |
getExposedOriginName(Origin insideOrigin) |
java.lang.String |
getExposedTerminationName(Termination insideTermination) |
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) |
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() |
int |
getNeuronCount() |
Node |
getNode(java.lang.String name) |
int |
getNodeCount() |
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() |
java.util.Map<Termination,Projection> |
getProjectionMap() |
Projection[] |
getProjections() |
Simulator |
getSimulator() |
float |
getStepSize() |
ThreadTask[] |
getTasks() |
Termination |
getTermination(java.lang.String name) |
Termination[] |
getTerminations() |
boolean |
getUseGPU() |
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 |
notifyAboutDeletion()
Recursively inform all sub-Nodes that they will be deleted soon.
|
void |
removeChangeListener(VisiblyMutable.Listener listener) |
void |
removeNode(java.lang.String name) |
void |
removeProjection(Termination termination) |
void |
removeStepListener(StepListener listener) |
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 |
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)
Used to just change the mode of this network (without recursively
changing the mode of nodes in the network)
|
void |
setName(java.lang.String name) |
void |
setSimulator(Simulator simulator) |
void |
setStepSize(float stepSize) |
void |
setTasks(ThreadTask[] tasks) |
void |
setTime(float time) |
void |
setUseGPU(boolean use) |
java.lang.String |
toPostScript(java.util.HashMap<java.lang.String,java.lang.Object> scriptData) |
java.lang.String |
toScript(java.util.HashMap<java.lang.String,java.lang.Object> scriptData) |
public static final java.lang.String DEFAULT_NAME
protected int myNumGPU
protected int myNumJavaThreads
protected boolean myUseGPU
public void notifyAboutDeletion()
notifyAboutDeletion
in interface Node
public void setSimulator(Simulator simulator)
setSimulator
in interface Network
simulator
- Simulator with which to run this Networkpublic Simulator getSimulator()
getSimulator
in interface Network
public void setStepSize(float stepSize)
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.public float getStepSize()
public void setTime(float time)
time
- The current simulation time. Sets the current time on the Network's subnodes.
(Mainly for NEFEnsembles).public void addNode(Node node) throws StructuralException
addNode
in interface Network
node
- Node to add to the NetworkStructuralException
- if the Network already contains a Node of the same nameNetwork.addNode(ca.nengo.model.Node)
public int countNeurons()
public void killNeurons(float killrate)
killrate
- the percentage (0.0 to 1.0) of neurons to killpublic void killNeurons(float killrate, boolean saveRelays)
killrate
- the percentage (0.0 to 1.0) of neurons to killsaveRelays
- if true, exempt populations with only one node from the slaughterpublic void changed(VisiblyMutable.Event e) throws StructuralException
changed
in interface VisiblyMutable.Listener
e
- An object that has changed in some way (all properties
that influence the display of the object should be checked)StructuralException
VisiblyMutable.Listener.changed(ca.nengo.util.VisiblyMutable.Event)
public java.util.ArrayList<Termination> getNodeTerminations()
public java.util.ArrayList<Origin> getNodeOrigins()
public Node[] getNodes()
getNodes
in interface Network
Network.getNodes()
public Node getNode(java.lang.String name) throws StructuralException
getNode
in interface Network
name
- Name of Node to removeStructuralException
- if named Node does not exist in networkNetwork.getNode(java.lang.String)
public int getNodeCount()
public int getNeuronCount()
public void removeNode(java.lang.String name) throws StructuralException
removeNode
in interface Network
name
- Name of Node to removeStructuralException
- if named Node does not exist in networkNetwork.removeNode(java.lang.String)
public Projection addProjection(Origin origin, Termination termination) throws StructuralException
Network
addProjection
in interface Network
origin
- Origin (data source) of Projection.termination
- Termination (data destination) of Projection.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).Network.addProjection(ca.nengo.model.Origin, ca.nengo.model.Termination)
public Projection[] getProjections()
getProjections
in interface Network
Network.getProjections()
public java.util.Map<Termination,Projection> getProjectionMap()
public void removeProjection(Termination termination) throws StructuralException
removeProjection
in interface Network
termination
- Termination of Projection to removeStructuralException
- if there exists no Projection between the specified
Origin and TerminationNetwork.removeProjection(ca.nengo.model.Termination)
public java.lang.String getName()
getName
in interface Node
Node.getName()
public void setName(java.lang.String name) throws StructuralException
setName
in interface Node
name
- New name of Network (must be unique within any networks of which this one
will be a part)StructuralException
- if name already exists?public void setMode(SimulationMode mode)
SimulationMode.ModeConfigurable
setMode
in interface SimulationMode.ModeConfigurable
mode
- SimulationMode in which it is desired that the object runs.SimulationMode.ModeConfigurable.setMode(ca.nengo.model.SimulationMode)
protected void setMyMode(SimulationMode mode)
public void fixMode()
public void fixMode(SimulationMode[] modes)
public SimulationMode getMode()
getMode
in interface SimulationMode.ModeConfigurable
SimulationMode.ModeConfigurable.getMode()
public void run(float startTime, float endTime) throws SimulationException
Node
run
in interface Node
startTime
- simulation time at which running starts (s)endTime
- simulation time at which running ends (s)SimulationException
- if a problem is encountered while trying to runNode.run(float, float)
public void run(float startTime, float endTime, boolean topLevel) throws SimulationException
startTime
- simulation time at which running starts (s)endTime
- simulation time at which running ends (s)topLevel
- true if the network being run is the top level network, false if it is a subnetworkSimulationException
- if there's an error in the simulationpublic void reset(boolean randomize)
reset
in interface Resettable
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.Resettable.reset(boolean)
public void setUseGPU(boolean use)
use
- Use GPU?public boolean getUseGPU()
public TimeSeries getHistory(java.lang.String stateName) throws SimulationException
Probeable
getHistory
in interface Probeable
stateName
- A state variable nameSimulationException
- if the Probeable does not have the requested stateProbeable.getHistory(java.lang.String)
public java.util.Properties listStates()
listStates
in interface Probeable
Probeable.listStates()
public void exposeOrigin(Origin origin, java.lang.String name)
Network
exposeOrigin
in interface Network
origin
- An Origin within this Network that is to connect to something
outside this Networkname
- Name of the Origin as it will appear outside this NetworkNetwork.exposeOrigin(ca.nengo.model.Origin,
java.lang.String)
public void hideOrigin(java.lang.String name) throws StructuralException
Network
hideOrigin
in interface Network
name
- Name of Origin to unexpose.StructuralException
- if Origin does not existNetwork.hideOrigin(java.lang.String)
public java.lang.String getExposedOriginName(Origin insideOrigin)
getExposedOriginName
in interface Network
insideOrigin
- Origin inside the networkNetwork.getExposedOriginName(ca.nengo.model.Origin)
public Origin getOrigin(java.lang.String name) throws StructuralException
getOrigin
in interface Node
name
- Name of an Origin on this NodeStructuralException
- if the named Origin does not existNode.getOrigin(java.lang.String)
public Origin[] getOrigins()
getOrigins
in interface Node
Node.getOrigins()
public void exposeTermination(Termination termination, java.lang.String name)
Network
exposeTermination
in interface Network
termination
- A Termination within this Network that is to connect to something
outside this Networkname
- Name of the Termination as it will appear outside this NetworkNetwork.exposeTermination(ca.nengo.model.Termination, java.lang.String)
public void hideTermination(java.lang.String name)
Network
hideTermination
in interface Network
name
- Name of Termination to unexpose.Network.hideTermination(java.lang.String)
public java.lang.String getExposedTerminationName(Termination insideTermination)
getExposedTerminationName
in interface Network
insideTermination
- Termination inside the networkNetwork.getExposedTerminationName(ca.nengo.model.Termination)
public Termination getTermination(java.lang.String name) throws StructuralException
getTermination
in interface Node
name
- Name of a Termination onto this NodeStructuralException
- if the named Termination does not existNode.getTermination(java.lang.String)
public Termination[] getTerminations()
getTerminations
in interface Node
Node.getTerminations()
public void exposeState(Probeable probeable, java.lang.String stateName, java.lang.String name) throws StructuralException
Network
exposeState
in interface Network
probeable
- A Probeable within this Network.stateName
- A state of the given Probeablename
- A new name with which to access this state via Network.getHistoryStructuralException
- if Probeable not in the NetworkNetwork.exposeState(ca.nengo.model.Probeable, java.lang.String, java.lang.String)
public void hideState(java.lang.String name)
Network
hideState
in interface Network
name
- Name of state to unexpose.Network.hideState(java.lang.String)
public ThreadTask[] getTasks()
getTasks
in interface TaskSpawner
ca.nengo.util.impl.TaskSpawner#getTasks()
public void setTasks(ThreadTask[] tasks)
setTasks
in interface TaskSpawner
tasks
- Sets the tasks of the spawner to thisca.nengo.util.impl.TaskSpawner#setTasks()
public void addTasks(ThreadTask[] tasks)
addTasks
in interface TaskSpawner
tasks
- Adds the this to the tasks of the spawnerca.nengo.util.impl.TaskSpawner#addTasks()
public void dumpToScript() throws java.io.FileNotFoundException
java.io.FileNotFoundException
public void dumpToScript(java.lang.String filepath) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public java.lang.String getDocumentation()
getDocumentation
in interface Node
Node.getDocumentation()
public void setDocumentation(java.lang.String text)
setDocumentation
in interface Node
text
- New user-specified documentation for the NodeNode.setDocumentation(java.lang.String)
public java.lang.Object getMetaData(java.lang.String key)
Network
getMetaData
in interface Network
key
- Name of a metadata itemNetwork.getMetaData(java.lang.String)
public void setMetaData(java.lang.String key, java.lang.Object value)
setMetaData
in interface Network
key
- Name of a metadata itemvalue
- Value of the named metadata itemNetwork.setMetaData(java.lang.String, java.lang.Object)
public void addChangeListener(VisiblyMutable.Listener listener)
addChangeListener
in interface VisiblyMutable
listener
- Listener to addVisiblyMutable.addChangeListener(ca.nengo.util.VisiblyMutable.Listener)
public void removeChangeListener(VisiblyMutable.Listener listener)
removeChangeListener
in interface VisiblyMutable
listener
- Listener to removeVisiblyMutable.removeChangeListener(ca.nengo.util.VisiblyMutable.Listener)
public java.lang.String toScript(java.util.HashMap<java.lang.String,java.lang.Object> scriptData) throws ScriptGenException
toScript
in interface Node
scriptData
- Map of class parent and prefix data for generating python scriptScriptGenException
- if the node cannot be generated in scriptpublic Network clone() throws java.lang.CloneNotSupportedException
public void addStepListener(StepListener listener)
addStepListener
in interface Network
public void removeStepListener(StepListener listener)
removeStepListener
in interface Network
public void fireStepListeners(float time)
fireStepListeners
in interface Network
public Node[] getChildren()
getChildren
in interface Node
public java.lang.String toPostScript(java.util.HashMap<java.lang.String,java.lang.Object> scriptData) throws ScriptGenException
toPostScript
in interface Network
scriptData
- Map of class parent and prefix data for generating python scriptScriptGenException
- if the node cannot be generated in scriptpublic java.lang.Object getMetadata(java.lang.String key)
public void setMetadata(java.lang.String key, java.lang.Object value)