org.simnet.interfaces
Class Network

java.lang.Object
  extended by org.simnet.interfaces.Network
All Implemented Interfaces:
EventListener, WorldListener
Direct Known Subclasses:
Backprop, Competitive, Hopfield, LMSNetwork, StandardNetwork, WinnerTakeAll

public abstract class Network
extends Object
implements WorldListener

Network provides core neural network functionality and is the the main API for external calls. Network objects are sets of neurons and weights connecting them. Much of the actual update and learning logic occurs (currently) in the individual nodes.


Field Summary
static int CONTINUOUS
          If this is a continuous-time network.
static int DISCRETE
          If this is a discrete-time network.
 
Constructor Summary
Network()
          Used to create an instance of network (Default constructor).
 
Method Summary
 void addNetwork(Network n)
          Adds a new network.
 void addNetworkList(ArrayList networks)
          Add an array of networks and set their parents to this.
 void addNetworkListener(NetworkListener l)
          Add the specified network listener.
 void addNeuron(Neuron neuron)
          Adds a new neuron.
protected  void addNeuron(Neuron neuron, boolean notify)
          Adds a new neuron.
 void addNeuronList(ArrayList neurons)
          Add an array of neurons and set their parents to this.
 void addWeight(Synapse weight)
          Adds a weight to the neuron network, where that weight already has designated source and target neurons.
protected  void addWeight(Synapse weight, boolean notify)
          Adds a weight to the neuron network, where that weight already has designated source and target neurons.
 void changeNeuron(Neuron oldNeuron, Neuron newNeuron)
          Replace one neuron with another.
 void changeSynapse(Synapse oldSynapse, Synapse newSynapse)
          Change synapse type / replace one synapse with another.
 void checkAllBounds()
          Calls Neuron.checkBounds() for each neuron, which makes sure the neuron has not exceeded its upper bound or gone below its lower bound.
 void clearActivations()
          Set the activation level of all neurons to zero.
 void clearInputs()
          Clears out input values of network nodes, which otherwise linger and cause problems.
 void close()
          Notify any objects observing this network that it has closed.
 void deleteNetwork(Network toDelete)
          Delete network.
 void deleteNeuron(Neuron toDelete)
          Deletes a neuron from the network.
protected  void deleteNeuron(Neuron toDelete, boolean notify)
          Deletes a neuron from the network.
 void deleteWeight(Synapse toDelete)
          Delete a specified weight.
protected  void deleteWeight(Synapse toDelete, boolean notify)
          Delete a specified weight.
 void fireClampChanged()
          Fire a clamp changed event to all registered model listeners.
 void fireCouplingChanged(Neuron n)
          Fire a coupling changed event to all registered model listeners.
 void fireNetworkChanged()
          Fire a network changed event to all registered model listeners.
 void fireNeuronAdded(Neuron added)
          Fire a neuron added event to all registered model listeners.
 void fireNeuronChanged(Neuron old, Neuron changed)
          Fire a neuron changed event to all registered model listeners.
 void fireNeuronDeleted(Neuron deleted)
          Fire a neuron deleted event to all registered model listeners.
 void fireSubnetAdded(Network added)
          Fire a subnetwork added event to all registered model listeners.
 void fireSubnetDeleted(Network deleted)
          Fire a subnetwork deleted event to all registered model listeners.
 void fireSynapseAdded(Synapse added)
          Fire a neuron added event to all registered model listeners.
 void fireSynapseChanged(Synapse old, Synapse changed)
          Fire a neuron deleted event to all registered model listeners.
 void fireSynapseDeleted(Synapse deleted)
          Fire a neuron deleted event to all registered model listeners.
 boolean getClampNeurons()
           
 boolean getClampWeights()
           
 ArrayList getCouplingList()
          Returns a list of all couplings associated with neurons in this network.
 int getDepth()
           
 ArrayList getFlatNetworkList()
          Create "flat" list of all subnetworks.
 ArrayList getFlatNeuronList()
          Create "flat" list of neurons, which includes the top-level neurons plus all subnet neurons.
 ArrayList getFlatSynapseList()
          Create "flat" list of synapses, which includes the top-level synapses plus all subnet synapses.
 String getId()
          Return the id of this neuron.
 String getIndents()
           
 Collection getInputNeurons()
          Returns all Input Neurons.
 InteractionMode getInteractionMode()
          Return the current interaction mode for this network panel.
 HashSet getListenerList()
          Return the top level listener list.
 Network getNetwork(int i)
           
 ArrayList getNetworkList()
           
 Network getNetworkParent()
           
 NetworkThread getNetworkThread()
           
 Neuron getNeuron(int index)
           
 Neuron getNeuron(String id)
          Find a neuron with a given string id.
 int getNeuronCount()
           
 ArrayList getNeuronList()
           
 Collection getOutputNeurons()
          Returns all Output Neurons.
 int getPrecision()
           
 Network getRoot()
          Returns the top-level network in the hierarchy.
 boolean getRoundingOff()
           
 double[] getState()
          Returns the "state" of the network--the activation level of its neurons.
 Synapse getSynapse(String id)
          Find a synapse with a given string id.
 double getTime()
          Returns the current time.
 String getTimeLabel()
           
 double getTimeStep()
           
 int getTimeType()
           
 String getType()
           
static String[] getUnits()
           
 Synapse getWeight(int index)
           
 Synapse getWeight(int i, int j)
          Gets the weight at particular point.
static Synapse getWeight(Neuron src, Neuron tar)
          Returns a reference to the synapse connecting two neurons, or null if there is none.
 int getWeightCount()
           
 ArrayList getWeightList()
           
 Workspace getWorkspace()
           
 void init()
          Initialize the network.
 void initNeurons()
          Inits neurons.
 void initParents()
          Initializes parent networks.
 void initWeights()
          Updates weights with fan-in.
 boolean isRoot()
          True if this is the top level network, false if it is a subnetwork.
 boolean isRoundOffActivationValues()
           
 boolean isUpdateCompleted()
          Used by Network thread to ensure that an update cycle is complete before updating again.
 void randomizeNeurons()
          Randomizes all neurons.
 void randomizeWeights()
          Randomizes all weights.
 void removeNetworkListener(NetworkListener l)
          Remove the specified network listener.
static double round(double value, int decimalPlace)
          Round a value off to indicated number of decimal places.
 void roundAll()
          Round activations of to intergers; for testing.
 void setClampNeurons(boolean clampNeurons)
          Sets neurons to clamped values.
 void setClampWeights(boolean clampWeights)
          Sets weights to clamped values.
 void setId(String id)
          The id of this neuron; used in persistence.
 void setInteractionMode(InteractionMode interactionMode)
          Set the current interaction mode for this network panel to interactionMode.
 void setLowerBounds(double l)
          Sets the lower bounds.
 void setNetworkList(ArrayList networkList)
           
 void setNetworkParent(Network parentNet)
           
 void setNetworkThread(NetworkThread networkThread)
           
 void setNeuronList(ArrayList neuronList)
           
 void setPrecision(int i)
          Sets the degree to which to round off values.
 void setRoundingOff(boolean b)
          Whether to round off neuron values.
 void setRoundOffActivationValues(boolean roundOffActivationValues)
           
 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 setUpperBounds(double u)
          Sets the upper bounds.
 void setWeightList(ArrayList weightList)
           
 void setWeightsToZero()
          Sets all weight values to zero, effectively eliminating them.
 void setWorkspace(Workspace workspace)
           
 String toString()
           
abstract  void update()
          Update the network.
 void updateAllNetworks()
          Updates all networks.
 void updateAllNeurons()
          Calls Neuron.update() for each neuron.
 void updateAllWeights()
          Calls Synapse.update() for each weight.
 void updateIds()
          Update all ids.
 void updateInputs()
          Update input nodes of the network based on the state of the world.
 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.
 void updateTopLevel()
          Externally called update function which coordiantes input and output neurons and connections with worlds and gauges.
 void updateWorldListeners(World toCheck)
          Check if any input or output neurons are coupled to a given world, and stop listening to that world if none are.
 void updateWorlds()
          Go through each output node and send the associated output value to the world component.
 void worldChanged()
          Respond to worldChanged event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DISCRETE

public static final int DISCRETE
If this is a discrete-time network.

See Also:
Constant Field Values

CONTINUOUS

public static final int CONTINUOUS
If this is a continuous-time network.

See Also:
Constant Field Values
Constructor Detail

Network

public Network()
Used to create an instance of network (Default constructor).

Method Detail

update

public abstract void update()
Update the network.


updateTopLevel

public void updateTopLevel()
Externally called update function which coordiantes input and output neurons and connections with worlds and gauges.


updateAllNetworks

public void updateAllNetworks()
Updates all networks.


worldChanged

public void worldChanged()
Respond to worldChanged event.

Specified by:
worldChanged in interface WorldListener

clearInputs

public void clearInputs()
Clears out input values of network nodes, which otherwise linger and cause problems.


updateWorlds

public void updateWorlds()
Go through each output node and send the associated output value to the world component.


updateInputs

public void updateInputs()
Update input nodes of the network based on the state of the world.


init

public void init()
Initialize the network.


initWeights

public void initWeights()
Updates weights with fan-in. Used when weights have been added.


initNeurons

public void initNeurons()
Inits neurons.


getType

public String getType()
Returns:
the name of the class of this network

getDepth

public int getDepth()
Returns:
how many subnetworks down this is

getIndents

public String getIndents()
Returns:
a string of tabs for use in indenting debug info accroding to the depth of a subnet

getNeuronList

public ArrayList getNeuronList()
Returns:
List of neurons in network.

getWeightList

public ArrayList getWeightList()
Returns:
List of weights in network.

getNeuronCount

public int getNeuronCount()
Returns:
Number of neurons in network.

getNeuron

public Neuron getNeuron(int index)
Parameters:
index - Number of neuron in array list.
Returns:
Neuron at the point of the index

getNeuron

public Neuron getNeuron(String id)
Find a neuron with a given string id.

Parameters:
id - id to search for.
Returns:
neuron with that id, null otherwise

getSynapse

public Synapse getSynapse(String id)
Find a synapse with a given string id.

Parameters:
id - id to search for.
Returns:
synapse with that id, null otherwise

addNeuron

protected void addNeuron(Neuron neuron,
                         boolean notify)
Adds a new neuron.

Parameters:
neuron - Type of neuron to add
notify - whether to notify listeners that this neuron has been added

addNeuron

public void addNeuron(Neuron neuron)
Adds a new neuron.

Parameters:
neuron - Type of neuron to add

getWeightCount

public int getWeightCount()
Returns:
Number of weights in network

getWeight

public Synapse getWeight(int index)
Parameters:
index - Number of weight in array list.
Returns:
Weight at the point of the indesx

getTime

public double getTime()
Returns the current time.

Returns:
the current time

setTime

public void setTime(double i)
Set the current time.

Parameters:
i - the current time

getTimeLabel

public String getTimeLabel()
Returns:
String string version of time, with units.

getTimeType

public int getTimeType()
Returns:
integer representation of time type.

addWeight

protected void addWeight(Synapse weight,
                         boolean notify)
Adds a weight to the neuron network, where that weight already has designated source and target neurons.

Parameters:
weight - the weight object to add
notify - whether to notify listeners that a weight has been added.

addWeight

public void addWeight(Synapse weight)
Adds a weight to the neuron network, where that weight already has designated source and target neurons.

Parameters:
weight - the weight object to add

updateAllNeurons

public void updateAllNeurons()
Calls Neuron.update() for each neuron.


updateAllWeights

public void updateAllWeights()
Calls Synapse.update() for each weight.


checkAllBounds

public void checkAllBounds()
Calls Neuron.checkBounds() for each neuron, which makes sure the neuron has not exceeded its upper bound or gone below its lower bound. TODO: Add or replace with normalization within bounds?


roundAll

public void roundAll()
Round activations of to intergers; for testing.


deleteNeuron

protected void deleteNeuron(Neuron toDelete,
                            boolean notify)
Deletes a neuron from the network.

Parameters:
toDelete - neuron to delete
notify - notify listeners that this neuron has been deleted

deleteNeuron

public void deleteNeuron(Neuron toDelete)
Deletes a neuron from the network.

Parameters:
toDelete - neuron to delete

deleteWeight

protected void deleteWeight(Synapse toDelete,
                            boolean notify)
Delete a specified weight.

Parameters:
toDelete - the weight to delete
notify - whether to fire a synapse deleted event

deleteWeight

public void deleteWeight(Synapse toDelete)
Delete a specified weight.

Parameters:
toDelete - the weight to delete

clearActivations

public void clearActivations()
Set the activation level of all neurons to zero.


getState

public double[] getState()
Returns the "state" of the network--the activation level of its neurons. Used by the gauge component

Returns:
an array representing the activation levels of all the neurons in this network

setWeightsToZero

public void setWeightsToZero()
Sets all weight values to zero, effectively eliminating them.


randomizeNeurons

public void randomizeNeurons()
Randomizes all neurons.


randomizeWeights

public void randomizeWeights()
Randomizes all weights.


round

public static double round(double value,
                           int decimalPlace)
Round a value off to indicated number of decimal places.

Parameters:
value - value to round off
decimalPlace - degree of precision
Returns:
rounded number

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object

getPrecision

public int getPrecision()
Returns:
Degree to which to round off values.

getRoundingOff

public boolean getRoundingOff()
Returns:
Whether to round off neuron values.

setPrecision

public void setPrecision(int i)
Sets the degree to which to round off values.

Parameters:
i - Degeree to round off values

setRoundingOff

public void setRoundingOff(boolean b)
Whether to round off neuron values.

Parameters:
b - Round off

isRoundOffActivationValues

public boolean isRoundOffActivationValues()
Returns:
Returns the roundOffActivationValues.

setRoundOffActivationValues

public void setRoundOffActivationValues(boolean roundOffActivationValues)
Parameters:
roundOffActivationValues - The roundOffActivationValues to set.

setNeuronList

public void setNeuronList(ArrayList neuronList)
Parameters:
neuronList - The neuronList to set.

setWeightList

public void setWeightList(ArrayList weightList)
Parameters:
weightList - The weightList to set.

addNeuronList

public void addNeuronList(ArrayList neurons)
Add an array of neurons and set their parents to this.

Parameters:
neurons - list of neurons to add

setUpperBounds

public void setUpperBounds(double u)
Sets the upper bounds.

Parameters:
u - Upper bound

setLowerBounds

public void setLowerBounds(double l)
Sets the lower bounds.

Parameters:
l - Lower bound

getWeight

public static Synapse getWeight(Neuron src,
                                Neuron tar)
Returns a reference to the synapse connecting two neurons, or null if there is none.

Parameters:
src - source neuron
tar - target neuron
Returns:
synapse from source to target

changeNeuron

public void changeNeuron(Neuron oldNeuron,
                         Neuron newNeuron)
Replace one neuron with another.

Parameters:
oldNeuron - out with the old
newNeuron - in with the new...

changeSynapse

public void changeSynapse(Synapse oldSynapse,
                          Synapse newSynapse)
Change synapse type / replace one synapse with another.

Parameters:
oldSynapse - out with the old
newSynapse - in with the new...

initParents

public void initParents()
Initializes parent networks.


updateTimeType

public void updateTimeType()
If there is a single continuous neuron in the network, consider this a continuous network.


updateTime

public void updateTime()
Increment the time counter, using a different method depending on whether this is a continuous or discrete. network


getWeight

public Synapse getWeight(int i,
                         int j)
Gets the weight at particular point.

Parameters:
i - Neuorn number
j - Weight to get
Returns:
Weight at the points defined

getNetworkParent

public Network getNetworkParent()
Returns:
Returns the parentNet.

getRoot

public Network getRoot()
Returns the top-level network in the hierarchy.

Returns:
Returns the root networ

setNetworkParent

public void setNetworkParent(Network parentNet)
Parameters:
parentNet - The parentNet to set.

getTimeStep

public double getTimeStep()
Returns:
Returns the timeStep.

setTimeStep

public void setTimeStep(double timeStep)
Parameters:
timeStep - The timeStep to set.

getUnits

public static String[] getUnits()
Returns:
Units by which to count.

getId

public String getId()
Return the id of this neuron.

Returns:
this neuron's id

setId

public void setId(String id)
The id of this neuron; used in persistence.

Parameters:
id - the new id.

getClampWeights

public boolean getClampWeights()
Returns:
Clamped weights.

setClampWeights

public void setClampWeights(boolean clampWeights)
Sets weights to clamped values.

Parameters:
clampWeights - Weights to set

getClampNeurons

public boolean getClampNeurons()
Returns:
Clamped neurons.

setClampNeurons

public void setClampNeurons(boolean clampNeurons)
Sets neurons to clamped values.

Parameters:
clampNeurons - Neurons to set

fireNeuronDeleted

public void fireNeuronDeleted(Neuron deleted)
Fire a neuron deleted event to all registered model listeners.

Parameters:
deleted - neuron which has been deleted

fireCouplingChanged

public void fireCouplingChanged(Neuron n)
Fire a coupling changed event to all registered model listeners.

Parameters:
n - the Neuron whose coupling has changed.

fireNetworkChanged

public void fireNetworkChanged()
Fire a network changed event to all registered model listeners.


fireClampChanged

public void fireClampChanged()
Fire a clamp changed event to all registered model listeners.


fireNeuronAdded

public void fireNeuronAdded(Neuron added)
Fire a neuron added event to all registered model listeners.

Parameters:
added - neuron which was added

fireNeuronChanged

public void fireNeuronChanged(Neuron old,
                              Neuron changed)
Fire a neuron changed event to all registered model listeners.

Parameters:
old - the previous neuron, before the change
changed - the new, changed neuron

fireSynapseAdded

public void fireSynapseAdded(Synapse added)
Fire a neuron added event to all registered model listeners.

Parameters:
added - synapse which was added

fireSynapseDeleted

public void fireSynapseDeleted(Synapse deleted)
Fire a neuron deleted event to all registered model listeners.

Parameters:
deleted - synapse which was deleted

fireSynapseChanged

public void fireSynapseChanged(Synapse old,
                               Synapse changed)
Fire a neuron deleted event to all registered model listeners.

Parameters:
old - old synapse, before the change
changed - new, changed synapse

updateWorldListeners

public void updateWorldListeners(World toCheck)
Check if any input or output neurons are coupled to a given world, and stop listening to that world if none are.

Parameters:
toCheck - the world which should be checked for live couplings.

close

public void close()
Notify any objects observing this network that it has closed.


setInteractionMode

public void setInteractionMode(InteractionMode interactionMode)
Set the current interaction mode for this network panel to interactionMode.

This is a bound property.

Parameters:
interactionMode - interaction mode for this network panel, must not be null

getInteractionMode

public InteractionMode getInteractionMode()
Return the current interaction mode for this network panel.

Returns:
the current interaction mode for this network panel

isUpdateCompleted

public boolean isUpdateCompleted()
Used by Network thread to ensure that an update cycle is complete before updating again.

Returns:
whether the network has been updated or not

setUpdateCompleted

public void setUpdateCompleted(boolean b)
Used by Network thread to ensure that an update cycle is complete before updating again.

Parameters:
b - whether the network has been updated or not.

getNetworkThread

public NetworkThread getNetworkThread()
Returns:
Returns the networkThread.

setNetworkThread

public void setNetworkThread(NetworkThread networkThread)
Parameters:
networkThread - The networkThread to set.

getWorkspace

public Workspace getWorkspace()
Returns:
Returns the workspace.

setWorkspace

public void setWorkspace(Workspace workspace)
Parameters:
workspace - The workspace to set.

getCouplingList

public ArrayList getCouplingList()
Returns a list of all couplings associated with neurons in this network.

Returns:
couplings in this network.

isRoot

public boolean isRoot()
True if this is the top level network, false if it is a subnetwork.

Returns:
true if this is top level, false otherwise.

getListenerList

public HashSet getListenerList()
Return the top level listener list.

Returns:
the top level listener list

addNetwork

public void addNetwork(Network n)
Adds a new network.

Parameters:
n - Network type to add.

getNetwork

public Network getNetwork(int i)
Parameters:
i - Network number to get.
Returns:
network

deleteNetwork

public void deleteNetwork(Network toDelete)
Delete network.

Parameters:
toDelete - Network to be deleted

addNetworkList

public void addNetworkList(ArrayList networks)
Add an array of networks and set their parents to this.

Parameters:
networks - list of neurons to add

getNetworkList

public ArrayList getNetworkList()
Returns:
Returns the networkList.

setNetworkList

public void setNetworkList(ArrayList networkList)
Parameters:
networkList - The networkList to set.

getFlatNeuronList

public ArrayList getFlatNeuronList()
Create "flat" list of neurons, which includes the top-level neurons plus all subnet neurons.

Returns:
the flat list

getFlatSynapseList

public ArrayList getFlatSynapseList()
Create "flat" list of synapses, which includes the top-level synapses plus all subnet synapses.

Returns:
the flat list

getFlatNetworkList

public ArrayList getFlatNetworkList()
Create "flat" list of all subnetworks.

Returns:
the flat list

updateIds

public void updateIds()
Update all ids. Used in for persistences before writing net file.


getInputNeurons

public Collection getInputNeurons()
Returns all Input Neurons.

Returns:
list of input neurons;

getOutputNeurons

public Collection getOutputNeurons()
Returns all Output Neurons.

Returns:
list of output neurons;

fireSubnetAdded

public void fireSubnetAdded(Network added)
Fire a subnetwork added event to all registered model listeners.

Parameters:
added - synapse which was added

fireSubnetDeleted

public void fireSubnetDeleted(Network deleted)
Fire a subnetwork deleted event to all registered model listeners.

Parameters:
deleted - synapse which was deleted

addNetworkListener

public void addNetworkListener(NetworkListener l)
Add the specified network listener.

Parameters:
l - listener to add

removeNetworkListener

public void removeNetworkListener(NetworkListener l)
Remove the specified network listener.

Parameters:
l - listener to remove