public class Network
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
Network.PriorityComparator
Comparator for sorting neurons by update priority.
|
static class |
Network.TimeType
Two types of time used in simulations.
|
Constructor and Description |
---|
Network()
Used to create an instance of network (Default constructor).
|
Modifier and Type | Method and Description |
---|---|
void |
addGroup(Group group)
Add a group to the network.
|
void |
addGroupListener(GroupListener listener)
Register a group listener.
|
void |
addNetworkListener(NetworkListener listener)
Register a network listener.
|
void |
addNeuron(Neuron neuron)
Adds a new neuron.
|
protected void |
addNeuronList(java.util.ArrayList<Neuron> neurons)
Add an array of neurons and set their parents to this.
|
void |
addNeuronListener(NeuronListener listener)
Register a neuron listener.
|
void |
addObjects(java.util.List<?> toAdd)
Adds a list of network elements to this network.
|
void |
addSynapse(Synapse synapse)
Adds a weight to the neuron network, where that weight already has
designated source and target neurons.
|
void |
addSynapseListener(SynapseListener listener)
Register a synapse listener.
|
void |
addText(NetworkTextObject text)
Add a network text object.
|
void |
addTextListener(TextListener listener)
Register a text listener.
|
void |
addUpdateAction(NetworkUpdateAction action)
Add an update action to the network' action list (the sequence of actions
invoked on each iteration of the network).
|
void |
bufferedUpdateAllNeurons()
Calls
Neuron.update() for each neuron. |
void |
clearActivations()
Set the activation level of all neurons to zero.
|
void |
clearBiases()
Set biases on all neurons with a bias to 0.
|
void |
clearInputs()
Clears out input values of network nodes, which otherwise linger and
cause problems.
|
void |
connectNeuronGroups(NeuronGroup sng,
NeuronGroup tng,
ConnectNeurons connection)
Connect a source neuron group to a target neuron group using a connection
object.
|
void |
deleteText(NetworkTextObject text)
Delete a network text object.
|
void |
fireGroupAdded(Group added)
Fire a group added event to all registered model listeners.
|
void |
fireGroupChanged(Group old,
Group changed,
java.lang.String changeDescription)
Fire a group changed event to all registered model listeners.
|
void |
fireGroupChanged(Group group,
java.lang.String changeDescription) |
void |
fireGroupChanged(NetworkEvent<Group> event,
java.lang.String changeDescription)
This version of fireGroupChanged fires a pre-set event, which may have an
auxiliary object set.
|
void |
fireGroupParametersChanged(Group group)
Fire a group parameters changed event.
|
void |
fireGroupRemoved(Group deleted)
Fire a group deleted event to all registered model listeners.
|
void |
fireGroupUpdated(Group groups)
Fire a group update event event.
|
void |
fireNeuronAdded(Neuron added)
Fire a neuron added event to all registered model listeners.
|
void |
fireNeuronChanged(Neuron changed)
Fire a neuron changed event to all registered model listeners.
|
void |
fireNeuronLabelChanged(Neuron changed)
Fire a label changed event to all registered model listeners.
|
void |
fireNeuronMoved(Neuron moved)
Fire a network changed event to all registered model listeners.
|
void |
fireNeuronRemoved(Neuron deleted)
Fire a neuron deleted event to all registered model listeners.
|
void |
fireNeuronsUpdated()
Fire this event when the visible state of a neuron (e.g.
|
void |
fireNeuronsUpdated(java.util.Collection<Neuron> neurons)
Fire this event when the visible state of a specified list of neuron
(e.g.
|
void |
fireNeuronTypeChanged(NeuronUpdateRule old,
NeuronUpdateRule changed)
Fire a neuron type changed event to all registered model listeners.
|
void |
fireSynapseAdded(Synapse added)
Fire a synapse added event to all registered model listeners.
|
void |
fireSynapseChanged(Synapse changed)
Fire a synapse changed event to all registered model listeners.
|
void |
fireSynapseRemoved(Synapse deleted)
Fire a synapse deleted event to all registered model listeners.
|
void |
fireSynapsesUpdated()
Fire this event when the visible state of a synapse (e.g.
|
void |
fireSynapsesUpdated(java.util.Collection<Synapse> synapses)
Fire this event when the visible state of a specified list of synapses
(e.g.
|
void |
fireSynapseTypeChanged(SynapseUpdateRule oldRule,
SynapseUpdateRule learningRule)
Fire a synapse type changed event to all registered model listeners.
|
void |
fireTextAdded(NetworkTextObject added)
Fire a text added event to all registered model listeners.
|
void |
fireTextChanged(NetworkTextObject changed)
Fire a text changed event to all registered model listeners.
|
void |
fireTextRemoved(NetworkTextObject deleted)
Fire a text deleted event to all registered model listeners.
|
void |
freezeSynapses(boolean freeze)
Freeze or unfreeze all synapses in the network.
|
static double[] |
getActivationVector(java.util.List<Neuron> neuronList)
Get the activations associated with a list of neurons.
|
static double |
getEuclideanDist(Neuron n1,
Neuron n2)
Gets the Euclidean distance between two neurons' positions in coordinate
space.
|
java.util.List<Group> |
getFlatGroupList()
Create a "flat" list of groups, which includes the top-level groups plus
all subgroups.
|
java.util.List<NeuronGroup> |
getFlatNeuronGroupList()
Returns a list of all neuron groups.
|
java.util.List<Neuron> |
getFlatNeuronList()
Create "flat" list of neurons, which includes the top-level neurons plus
all group neurons.
|
java.util.List<Synapse> |
getFlatSynapseList()
Create "flat" list of synapses, which includes the top-level synapses
plus all subnet synapses.
|
Group |
getGroup(java.lang.String id)
Find a group with a given string id.
|
Group |
getGroupByLabel(java.lang.String label)
Find group with a given label, or null if none found.
|
SimpleId |
getGroupIdGenerator() |
java.util.List<? extends Group> |
getGroupList()
Returns the group list.
|
java.util.List<Group> |
getGroupsByLabel(java.lang.String label)
Find groups with a given label, or null if none found.
|
long |
getIterations()
Returns the current number of iterations.
|
Neuron |
getNeuron(int index) |
Neuron |
getNeuron(java.lang.String id)
Find a neuron with a given string id.
|
Neuron |
getNeuronByLabel(java.lang.String inputString)
Returns the first neuron in the array returned by getNeuronsByLabel.
|
int |
getNeuronCount() |
java.util.List<NeuronGroup> |
getNeuronGroups()
Convenience method to return a list of neuron groups in the network.
|
SimpleId |
getNeuronIdGenerator()
Return the generator for neuron ids.
|
java.util.List<? extends Neuron> |
getNeuronList()
Return the list of synapses.
|
java.util.List<Neuron> |
getNeuronsByLabel(java.lang.String inputString)
Search for a neuron by label.
|
java.util.List<Neuron> |
getPrioritySortedNeuronList()
TODO: Resolve priority update issue.
|
double[] |
getState()
Returns the "state" of the network--the activation level of its neurons.
|
static Synapse |
getSynapse(Neuron src,
Neuron tar)
Returns a reference to the synapse connecting two neurons, or null if
there is none.
|
Synapse |
getSynapse(java.lang.String id)
Find a synapse with a given string id.
|
int |
getSynapseCount() |
SynapseGroup |
getSynapseGroup(NeuronGroup src,
NeuronGroup targ)
Returns the synapse group between some source neuron group and some
target neuron group, if it exists.
|
java.util.List<SynapseGroup> |
getSynapseGroups()
Convenience method to return a list of synapse groups in the network.
|
SimpleId |
getSynapseIdGenerator()
Return the generator for synapse ids.
|
java.util.Collection<Synapse> |
getSynapseList()
Return the list of synapses.
|
static int |
getSynapseVisibilityThreshold() |
java.util.List<NetworkTextObject> |
getTextList() |
double |
getTime()
Returns the current time in ms based on the network
timeStep . |
java.lang.String |
getTimeLabel() |
double |
getTimeStep() |
Network.TimeType |
getTimeType() |
static java.lang.String[] |
getUnits() |
NetworkUpdateManager |
getUpdateManager() |
Synapse |
getWeight(int i,
int j)
Gets the synapse at particular point.
|
static com.thoughtworks.xstream.XStream |
getXStream()
Returns a properly initialized xstream object.
|
boolean |
isEmpty()
Returns true if all objects are gone from this network.
|
boolean |
isFireUpdates() |
boolean |
isUpdateCompleted()
Used by Network thread to ensure that an update cycle is complete before
updating again.
|
void |
postSaveReInit()
Returns synapse groups to a usable state after a save is performed.
|
void |
preSaveInit()
Perform operations required before saving a network.
|
void |
randomizeBiases(double lower,
double upper)
Randomize all biased neurons.
|
void |
randomizeNeurons()
Randomizes all neurons.
|
void |
randomizeWeights()
Randomizes all loose weights.
|
void |
removeGroup(Group toDelete)
Remove the specified group.
|
void |
removeGroupListener(GroupListener listener)
Remove a group listener.
|
void |
removeNetworkListener(NetworkListener networkListener)
Remove a network listener.
|
void |
removeNeuron(Neuron toDelete)
Deletes a neuron from the network.
|
void |
removeSynapse(Synapse toDelete)
Delete a specified weight.
|
void |
removeSynapseListener(SynapseListener synapseListener)
Remove a synapse listener.
|
(package private) void |
resortPriorities()
Resort the neurons according to their update priorities.
|
void |
setActivations(double value)
Sets all neurons to a specified value.
|
void |
setActivations(double[] activationArray)
Sets neuron activations using values in an array of doubles.
|
void |
setFireUpdates(boolean fireUpdates) |
static void |
setSynapseVisibilityThreshold(int svt) |
void |
setTime(double i)
Set the current time.
|
void |
setTimeStep(double timeStep) |
void |
setUpdateCompleted(boolean b)
Used by Network thread to ensure that an update cycle is complete before
updating again.
|
void |
setWeights(double value)
Sets all weights to a specified value.
|
void |
setWeightsToZero()
Sets all weight values to zero, effectively eliminating them.
|
java.lang.String |
toString() |
void |
transferNeuronsToGroup(java.util.List<Neuron> list,
NeuronGroup group)
Remove the given neurons from the neuron list (without firing an event)
and add them to the provided group.
|
void |
translate(double offsetX,
double offsetY)
Translate all neurons (the only objects with position information).
|
void |
update()
The core update function of the neural network.
|
void |
updateAllGroups()
Update all neuron groups and other groups.
|
void |
updateAllSynapses()
Calls
Synapse.update() for each weight. |
static void |
updateNeurons(java.util.List<Neuron> neuronList)
Convenience method for asynchronously updating a set of neurons, by
calling each neuron's update function (which sets a buffer), and then
setting each neuron's activation to the buffer state.
|
void |
updateNeuronsByPriority()
This function is used to update the neuron and sub-network activation
values if the user chooses to set different priority values for a subset
of neurons and sub-networks.
|
(package private) void |
updatePriorityList()
Update the priority list used for priority based update.
|
void |
updateTime()
Increment the time counter, using a different method depending on whether
this is a continuous or discrete.
|
void |
updateTimeType()
If there is a single continuous neuron in the network, consider this a
continuous network.
|
public Network()
public void update()
public void updateAllGroups()
void updatePriorityList()
void resortPriorities()
public void updateNeuronsByPriority()
public void bufferedUpdateAllNeurons()
Neuron.update()
for each neuron.public void clearInputs()
public java.util.List<? extends Neuron> getNeuronList()
getFlatNeuronList()
.public java.util.Collection<Synapse> getSynapseList()
getFlatSynapseList()
.public int getNeuronCount()
public int getSynapseCount()
public static double getEuclideanDist(Neuron n1, Neuron n2)
n1
- Neuron onen2
- Neuron twopublic Neuron getNeuron(int index)
index
- Number of neuron in array list.public Neuron getNeuron(java.lang.String id)
id
- id to search for.public Group getGroup(java.lang.String id)
id
- id to search for.public java.util.List<Group> getGroupsByLabel(java.lang.String label)
label
- label to search for.public Group getGroupByLabel(java.lang.String label)
label
- label to search for.public java.util.List<? extends Group> getGroupList()
public java.util.List<NeuronGroup> getFlatNeuronGroupList()
public SynapseGroup getSynapseGroup(NeuronGroup src, NeuronGroup targ)
src
- the source neuron grouptarg
- the target neuron grouppublic Synapse getSynapse(java.lang.String id)
id
- id to search for.public void addNeuron(Neuron neuron)
neuron
- Type of neuron to addpublic void addSynapse(Synapse synapse)
synapse
- the weight object to addpublic void updateAllSynapses()
Synapse.update()
for each weight.public void removeNeuron(Neuron toDelete)
toDelete
- neuron to deletepublic void removeSynapse(Synapse toDelete)
toDelete
- the weight to deletepublic void transferNeuronsToGroup(java.util.List<Neuron> list, NeuronGroup group)
list
- the list of neurons to transfergroup
- the group to transfer them topublic void clearActivations()
public void clearBiases()
public void setActivations(double value)
value
- value to setpublic void setActivations(double[] activationArray)
activationArray
- array of values to apply to networkpublic void setWeights(double value)
value
- value to setpublic double[] getState()
public void setWeightsToZero()
public void randomizeNeurons()
public void randomizeWeights()
public void randomizeBiases(double lower, double upper)
lower
- lower bound for randomization.upper
- upper bound for randomization.protected void addNeuronList(java.util.ArrayList<Neuron> neurons)
neurons
- list of neurons to addpublic static Synapse getSynapse(Neuron src, Neuron tar)
src
- source neurontar
- target neuronpublic Synapse getWeight(int i, int j)
i
- Neuron numberj
- Weight to getpublic void addGroup(Group group)
group
- group of network elementspublic void removeGroup(Group toDelete)
toDelete
- the group to delete.public boolean isEmpty()
public java.util.List<Neuron> getFlatNeuronList()
public java.util.List<Synapse> getFlatSynapseList()
public java.util.List<Group> getFlatGroupList()
public double getTimeStep()
public static void updateNeurons(java.util.List<Neuron> neuronList)
neuronList
- the list of neurons to be updatedpublic static double[] getActivationVector(java.util.List<Neuron> neuronList)
neuronList
- the neurons whose activations to get.public static com.thoughtworks.xstream.XStream getXStream()
public void preSaveInit()
readResolve()
.public void postSaveReInit()
public static java.lang.String[] getUnits()
public double getTime()
timeStep
.public long getIterations()
public void setTime(double i)
i
- the current timepublic java.lang.String getTimeLabel()
public Network.TimeType getTimeType()
public void updateTimeType()
public void updateTime()
public java.util.List<Neuron> getPrioritySortedNeuronList()
public void setTimeStep(double timeStep)
timeStep
- The timeStep to set.public void fireNeuronRemoved(Neuron deleted)
deleted
- neuron which has been deletedpublic void fireNeuronsUpdated()
public void fireNeuronsUpdated(java.util.Collection<Neuron> neurons)
neurons
- the neurons whose state has changedpublic void fireSynapsesUpdated()
public void fireSynapsesUpdated(java.util.Collection<Synapse> synapses)
synapses
- the synapses whose state has changedpublic void fireNeuronMoved(Neuron moved)
moved
- Neuron that has been movedpublic void fireNeuronAdded(Neuron added)
added
- neuron which was addedpublic void fireNeuronTypeChanged(NeuronUpdateRule old, NeuronUpdateRule changed)
old
- the old update rulechanged
- the new update rulepublic void fireNeuronChanged(Neuron changed)
changed
- neuronpublic void fireNeuronLabelChanged(Neuron changed)
changed
- neuronpublic void fireSynapseAdded(Synapse added)
added
- synapse which was addedpublic void fireSynapseRemoved(Synapse deleted)
deleted
- synapse which was deletedpublic void fireSynapseChanged(Synapse changed)
changed
- new, changed synapsepublic void fireSynapseTypeChanged(SynapseUpdateRule oldRule, SynapseUpdateRule learningRule)
oldRule
- old synapse, before the changelearningRule
- new, changed synapsepublic void fireTextAdded(NetworkTextObject added)
added
- text which was deletedpublic void fireTextRemoved(NetworkTextObject deleted)
deleted
- text which was deletedpublic void fireTextChanged(NetworkTextObject changed)
changed
- text which was changedpublic boolean isUpdateCompleted()
public void setUpdateCompleted(boolean b)
b
- whether the network has been updated or not.public void fireGroupAdded(Group added)
added
- Group that has been addedpublic void fireGroupRemoved(Group deleted)
deleted
- Group to be deletedpublic void fireGroupChanged(Group old, Group changed, java.lang.String changeDescription)
old
- Old groupchanged
- New changed groupchangeDescription
- A description of thepublic void fireGroupChanged(NetworkEvent<Group> event, java.lang.String changeDescription)
event
- the network changed event.changeDescription
- A description of thepublic void fireGroupChanged(Group group, java.lang.String changeDescription)
group
- reference to the group whose parameters are being changedchangeDescription
- A change of description for the grouppublic void fireGroupParametersChanged(Group group)
group
- reference to group whose parameters changedpublic void fireGroupUpdated(Group groups)
groups
- reference to group that has been updated.public java.lang.String toString()
toString
in class java.lang.Object
public SimpleId getNeuronIdGenerator()
public SimpleId getSynapseIdGenerator()
public void addNetworkListener(NetworkListener listener)
listener
- the observer to registerpublic void removeNetworkListener(NetworkListener networkListener)
networkListener
- the observer to removepublic void addNeuronListener(NeuronListener listener)
listener
- the observer to registerpublic void addSynapseListener(SynapseListener listener)
listener
- the observer to registerpublic void addTextListener(TextListener listener)
listener
- the observer to registerpublic void removeSynapseListener(SynapseListener synapseListener)
synapseListener
- the observer to removepublic void addGroupListener(GroupListener listener)
listener
- the observer to registerpublic void removeGroupListener(GroupListener listener)
listener
- the observer to removepublic java.util.List<Neuron> getNeuronsByLabel(java.lang.String inputString)
inputString
- label of neuron to search forpublic Neuron getNeuronByLabel(java.lang.String inputString)
inputString
- label of neuron to search forpublic SimpleId getGroupIdGenerator()
public void addText(NetworkTextObject text)
text
- text object to add.public void deleteText(NetworkTextObject text)
text
- text object to addpublic java.util.List<NetworkTextObject> getTextList()
public void addUpdateAction(NetworkUpdateAction action)
action
- new actionpublic NetworkUpdateManager getUpdateManager()
public void addObjects(java.util.List<?> toAdd)
toAdd
- list of objects to add.public void translate(double offsetX, double offsetY)
offsetX
- x offset for translation.offsetY
- y offset for translation.public void connectNeuronGroups(NeuronGroup sng, NeuronGroup tng, ConnectNeurons connection)
sng
- source neuron grouptng
- target neuron groupconnection
- conection objectpublic void freezeSynapses(boolean freeze)
freeze
- frozen if true; unfrozen if falsepublic java.util.List<SynapseGroup> getSynapseGroups()
public java.util.List<NeuronGroup> getNeuronGroups()
public static int getSynapseVisibilityThreshold()
public static void setSynapseVisibilityThreshold(int svt)
svt
- the synapseVisibilityThreshold to setpublic boolean isFireUpdates()
public void setFireUpdates(boolean fireUpdates)