public class DefaultNeuralModule extends SyncedUnit implements NeuralModule
VisiblyMutable.Event, VisiblyMutable.Listener, VisiblyMutable.NameChangeEvent, VisiblyMutable.NodeRemovedEvent
Modifier and Type | Field and Description |
---|---|
protected ModemContainer |
mc |
static java.lang.String |
me |
protected java.lang.String |
myDocumentation |
protected java.util.Map<java.lang.String,Encoder> |
myEncoders |
protected SimulationMode |
myMode |
protected java.lang.String |
myName |
protected int |
myNumGPU |
protected int |
myNumJavaThreads |
protected java.util.Map<java.lang.String,Origin> |
myOrigins |
protected java.util.Properties |
myProperties |
protected java.util.Map<java.lang.String,Termination> |
myTerminations |
protected float |
myTime |
protected boolean |
myUseGPU |
protected java.util.LinkedList<Encoder> |
orderedEncoders |
protected java.util.LinkedList<Origin> |
orderedOrigins |
protected java.util.LinkedList<Termination> |
orderedTerminations |
synchronous
Constructor and Description |
---|
DefaultNeuralModule(java.lang.String name,
NodeGroup group)
The NeuralModule which features BasicEncoders (with BasicMultiTerminations),
BasicDecoders (which are synchronous by default, that means they wait for
ROS message to be received), which is synchronous by default.
|
DefaultNeuralModule(java.lang.String name,
NodeGroup group,
boolean synchronous)
The NeuralModule which features BasicEncoders (with BasicMultiTerminations),
BasicDecoders (which are synchronous by default, that means they wait for
ROS message to be received), which is synchronous by default.
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(VisiblyMutable.Listener listener) |
protected void |
addEncoder(Encoder e) |
void |
addOrigin(Origin o)
This is used by Decoders to add their origin to the NeuralModule,
should not be used from any other place.
|
void |
addTermination(Termination t)
This is used by Encoders to add their termination to the NeuralModule,
should not be used from any other place.
|
DefaultNeuralModule |
clone() |
void |
createDecoder(java.lang.String topicName,
java.lang.String dataType) |
void |
createDecoder(java.lang.String topicName,
java.lang.String dataType,
boolean synchronous)
Decoder with number of primitive data types given by the ROS message type.
|
void |
createDecoder(java.lang.String topicName,
java.lang.String dataType,
int dimensionSize) |
void |
createDecoder(java.lang.String topicName,
java.lang.String dataType,
int[] dimensionSizes)
Add the Decoder to the Module, that is:
Subscribe to given ROS topic with expected type of data and expected dimensionality.
Add Decoder to Node in the Nengo with corresponding dimensionality.
|
void |
createDecoder(java.lang.String topicName,
java.lang.String dataType,
int[] dimensionSizes,
boolean synchronous)
This method should add decoder (that is Nengo origin to this NeuralModule).
|
void |
createDecoder(java.lang.String topicName,
java.lang.String dataType,
int dimensionSize,
boolean synchronous) |
void |
createEncoder(java.lang.String topicName,
java.lang.String dataType)
Create encoder where the dimensionality of message data is determined by data type (e.g.
|
void |
createEncoder(java.lang.String topicName,
java.lang.String dataType,
int dimensionSize) |
void |
createEncoder(java.lang.String topicName,
java.lang.String dataType,
int[] dimensionSizes)
This method adds encoder, that is owner of one or multiple Terminations to this NeuralModule.
|
Node[] |
getChildren() |
java.lang.String |
getDocumentation() |
TimeSeries |
getHistory(java.lang.String key)
this is made for Probeable and enables GUI to add a probe (and collect data)
I made every (RealValued) Termination and Origin probeable
|
SimulationMode |
getMode() |
MultiTermination |
getMultiTermination(java.lang.String name)
This NeuralModule supports connecting multiple "inputs" to one Encoder.
|
java.lang.String |
getName() |
Origin |
getOrigin(java.lang.String name) |
Origin[] |
getOrigins() |
Termination |
getTermination(java.lang.String name) |
Termination[] |
getTerminations() |
protected void |
init(java.lang.String name,
NodeGroup group) |
java.util.Properties |
listStates()
also for Probeable..
|
Termination |
newTerminationFor(java.lang.String name)
In order to simplify connecting new inputs to the Encoder (MultiTermination in general),
this method can be use to create new Terminations.
|
Termination |
newTerminationFor(java.lang.String name,
float weight)
The same as the
NeuralModule.newTerminationFor(String) ,
but here the weight can be specified. |
Termination |
newTerminationFor(java.lang.String name,
java.lang.Float[] weights)
The same as the
NeuralModule.newTerminationFor(String) ,
but here the weight for each dimension can be specified. |
void |
notifyAboutDeletion()
This method tells the Node (network) that is being deleted from Nengo,
Node can inform its children (child Nodes) that are being deleted,
these nodes can e.g.
|
void |
printOriginNames() |
void |
printTerminationNames() |
void |
removeChangeListener(VisiblyMutable.Listener 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 |
setDocumentation(java.lang.String text) |
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).
|
void |
setName(java.lang.String name) |
void |
setSynchronous(boolean synchronous)
Turn synchronous communication on/off.
|
java.lang.String |
toScript(java.util.HashMap<java.lang.String,java.lang.Object> scriptData) |
addChild, discardChildsReady, isReady, removeChild, setReady
public static final java.lang.String me
protected float myTime
protected java.util.Properties myProperties
protected java.util.Map<java.lang.String,Origin> myOrigins
protected java.util.LinkedList<Origin> orderedOrigins
protected java.util.Map<java.lang.String,Termination> myTerminations
protected java.util.LinkedList<Termination> orderedTerminations
protected java.util.Map<java.lang.String,Encoder> myEncoders
protected java.util.LinkedList<Encoder> orderedEncoders
protected java.lang.String myDocumentation
protected java.lang.String myName
protected int myNumGPU
protected int myNumJavaThreads
protected boolean myUseGPU
protected SimulationMode myMode
protected ModemContainer mc
public DefaultNeuralModule(java.lang.String name, NodeGroup group) throws ConnectionException
The NeuralModule which features BasicEncoders (with BasicMultiTerminations), BasicDecoders (which are synchronous by default, that means they wait for ROS message to be received), which is synchronous by default.
The simulator waits for all synchronous components at each sim. step
name
- name of the Modulegroup
- NodeGroup which belongs to this Module (group can have one
or multiple ROS nodes and one Modem for translating communication between
ROS and Nengo)ConnectionException
- group of running ROS nodes should already contain
the Modem, if no Modem is found, ROS communication will not be availableModem
,
SyncedUnit
,
BasicDecoder
,
BasicEncoder
public DefaultNeuralModule(java.lang.String name, NodeGroup group, boolean synchronous) throws ConnectionException
The NeuralModule which features BasicEncoders (with BasicMultiTerminations), BasicDecoders (which are synchronous by default, that means they wait for ROS message to be received), which is synchronous by default.
The simulator waits for all synchronous components at each sim. step
name
- name of the Modulegroup
- NodeGroup which belongs to this Module (group can have one
or multiple ROS nodes and one Modem for translating communication between
ROS and Nengo)synchronous
- the Nengo simulator waits each time step for all
synchronous ModulesConnectionException
- group of running ROS nodes should already contain
the Modem, if no Modem is found, ROS communication will not be availableModem
,
SyncedUnit
,
BasicDecoder
,
BasicEncoder
protected void init(java.lang.String name, NodeGroup group) throws ConnectionException
ConnectionException
public void setSynchronous(boolean synchronous)
NeuralModule
Turn synchronous communication on/off. Node is synchronous by default. If the synchronous communication is turned on, the Nengo simulator waits for messages from all synchronous Decoders of the Module each simulation step.
If the Module is set to asynchronous mode: the simulation does not wait for any of its childs. In the synchronous mode, only synchronous Decoders can block the simulation
.setSynchronous
in interface NeuralModule
setSynchronous
in interface SyncedUnitInterface
setSynchronous
in class SyncedUnit
public void createDecoder(java.lang.String topicName, java.lang.String dataType, int[] dimensionSizes, boolean synchronous)
createDecoder
in interface NeuralModule
topicName
- name of the origin and ROS topicdimensionSizes
- dimensions of decoded datasynchronous
- whether the decoder will be synchronous (see above)dataType
- type of datapublic void createDecoder(java.lang.String topicName, java.lang.String dataType, int dimensionSize, boolean synchronous)
createDecoder
in interface NeuralModule
public void createDecoder(java.lang.String topicName, java.lang.String dataType, boolean synchronous)
createDecoder
in interface NeuralModule
public void createDecoder(java.lang.String topicName, java.lang.String dataType, int[] dimensionSizes)
NeuralModule
createDecoder
in interface NeuralModule
topicName
- name of the ROS topicdataType
- type of datadimensionSizes
- list of dimension sizes (best support only for 1D vectors)public void createDecoder(java.lang.String topicName, java.lang.String dataType, int dimensionSize)
createDecoder
in interface NeuralModule
public void createDecoder(java.lang.String topicName, java.lang.String dataType)
createDecoder
in interface NeuralModule
public void createEncoder(java.lang.String topicName, java.lang.String dataType, int[] dimensionSizes)
createEncoder
in interface NeuralModule
topicName
- name of termination and the corresponding ROS topicdimension
- public void createEncoder(java.lang.String topicName, java.lang.String dataType, int dimensionSize)
createEncoder
in interface NeuralModule
public void createEncoder(java.lang.String topicName, java.lang.String dataType)
createEncoder
in interface NeuralModule
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 runpublic 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.public void setMode(SimulationMode mode)
SimulationMode.ModeConfigurable
setMode
in interface SimulationMode.ModeConfigurable
mode
- SimulationMode in which it is desired that the object runs.public SimulationMode getMode()
getMode
in interface SimulationMode.ModeConfigurable
public void addChangeListener(VisiblyMutable.Listener listener)
addChangeListener
in interface VisiblyMutable
listener
- Listener to addpublic void removeChangeListener(VisiblyMutable.Listener listener)
removeChangeListener
in interface VisiblyMutable
listener
- Listener to removepublic TimeSeries getHistory(java.lang.String key) throws SimulationException
getHistory
in interface Probeable
key
- A state variable nameSimulationException
- if the Probeable does not have the requested statepublic java.util.Properties listStates()
listStates
in interface Probeable
public java.lang.String getName()
getName
in interface Node
getName
in interface SyncedUnitInterface
getName
in class SyncedUnit
public void setName(java.lang.String name) throws StructuralException
setName
in interface Node
setName
in interface SyncedUnitInterface
setName
in class SyncedUnit
name
- The new nameStructuralException
- if name already exists?public Origin[] getOrigins()
getOrigins
in interface Node
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 existpublic Termination[] getTerminations()
getTerminations
in interface Node
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 existpublic java.lang.String getDocumentation()
getDocumentation
in interface Node
public void setDocumentation(java.lang.String text)
setDocumentation
in interface Node
text
- New user-specified documentation for the Nodepublic DefaultNeuralModule clone()
public void notifyAboutDeletion()
Node
notifyAboutDeletion
in interface Node
public Node[] getChildren()
getChildren
in interface Node
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 void addOrigin(Origin o) throws StructuralException
PeripheralsRegisteringNode
addOrigin
in interface PeripheralsRegisteringNode
o
- Origin to be addedStructuralException
- is thrown if there already is orig. with this namepublic void addTermination(Termination t) throws StructuralException
PeripheralsRegisteringNode
addTermination
in interface PeripheralsRegisteringNode
t
- Termination to be added to the parentStructuralException
- is thrown if there already is term. with this namepublic MultiTermination getMultiTermination(java.lang.String name) throws StructuralException
NeuralModule
This NeuralModule supports connecting multiple "inputs" to one Encoder. It is accomplished by the fact that each Encoder has MultiTermination, where the MultiTermination can have several own Terminations, whose values are combined into one value.
The user is allowed to create new Terminations for Encoder. In order to do this, the Encoders MultiTermination has to be available. The MultiTermination is generated with identical name as the Encoder. This method provides access to the Encoders MultiTermination by its name.
getMultiTermination
in interface NeuralModule
name
- name of the Encoder==MultiTerminationStructuralException
- if no Encoder of such name foundprotected void addEncoder(Encoder e) throws StructuralException
StructuralException
public void printTerminationNames()
printTerminationNames
in interface PeripheralsRegisteringNode
public void printOriginNames()
printOriginNames
in interface PeripheralsRegisteringNode
public Termination newTerminationFor(java.lang.String name) throws StructuralException
NeuralModule
In order to simplify connecting new inputs to the Encoder (MultiTermination in general), this method can be use to create new Terminations. It receives name of the Encoded ROS topic (name of MultiTermination), crates new Termination with default weight (1), registers it to own MultiTermination and this NauralModule.
The MultiTermination in DefaultNeuralModule computes weighted sum of all its Terminations. The resulting value is then encoded and sent as a ROS message on the topic which corresponds to the Encoders name.
newTerminationFor
in interface NeuralModule
name
- name of MultiTermination to connect newly created Termination (this equals
to the name of ROS topic used by Encoder)StructuralException
- if the Termination could not be created (e.g. Encoder not found,
name is used etc.)
Encoder.getMultiTermination()
MultiTermination.addTermination()
public Termination newTerminationFor(java.lang.String name, float weight) throws StructuralException
NeuralModule
NeuralModule.newTerminationFor(String)
,
but here the weight can be specified.newTerminationFor
in interface NeuralModule
name
- name of the ROS topic == name of the Encoder == name of the parent MultiTerminationweight
- terminations input is weightedStructuralException
- if the Termination could not be created{@link ctu.nengoros.comm.rosBackend.encoders.multiTermination.MultiTermination#addTermination(float)}
public Termination newTerminationFor(java.lang.String name, java.lang.Float[] weights) throws StructuralException
NeuralModule
NeuralModule.newTerminationFor(String)
,
but here the weight for each dimension can be specified.newTerminationFor
in interface NeuralModule
name
- name of the Encoderweights
- array of weights, for each dimension one weightStructuralException
- exception if the Termination could not be created (e.g. dimension
of weight array provided is incorrect){@link ctu.nengoros.comm.rosBackend.encoders.multiTermination.MultiTermination#addTermination(Float[])}