Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.joone.engine
Class Layer  view Layer download Layer.java

java.lang.Object
  extended byorg.joone.engine.Layer
All Implemented Interfaces:
java.util.EventListener, org.joone.inspection.Inspectable, Learnable, LearnableLayer, NeuralLayer, NeuralNetListener, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
MemoryLayer, RbfLayer, SimpleLayer

public abstract class Layer
extends java.lang.Object
implements NeuralLayer, java.lang.Runnable, java.io.Serializable, org.joone.inspection.Inspectable, LearnableLayer, NeuralNetListener

The Layer object is the basic element forming the neural net. Primarily it consists of a number of neurons that apply a transfer function to the sum of a number of input patterns and convey the result to the output pattern. The input patterns are received from connected input listeners and the transformed results are passed to connected output listeners. The component also handles learning by accepting patterns of error gradients from output listeners, applying a reverse (inverse) transfer function and passing the result to the input listeners. Layers execute their own Threads to perform the perform the pattern conveyance, so that a network of Layers can operate in a multi-threaded manner. The execution and termination of the Thread is controlled by a Monitor object.


Field Summary
protected  Matrix bias
          Holds the bias of neurons of the layer
protected  double[] gradientInps
          Set of input error gradient values passed to this layer from connected OutputListenrs during the learning phase.
protected  double[] gradientOuts
          Set of output error gradient values passed from this layer to connected InputListenrs during the learning phase.
protected  double[] inps
          Set of input values passed to this layer from connected InputListeners during the recall phase.
protected  java.util.Vector inputPatternListeners
          Contains the list of input connected listeners (InputPatternListener)
private  java.lang.String LayerName
          The name of the layer
protected  boolean learnable
          Contains true if for the Layer must be used a Learner instead of a built-in learning algorithm.
protected  boolean learning
          The Net's phase: false == recall; true == learning
private static org.joone.log.ILogger log
          Logger for this class
protected  int m_batch
          Not used but maintained for backward serialization compatability.
protected  Monitor monitor
          The monitor of the layer.
protected  Learner myLearner
          The Learner for this layer.
private  java.lang.Thread myThread
          The execution Thread for this layer.
private  java.lang.Object myThreadMonitor
          The monitor used to control read/write access to myThread
protected  java.util.Vector outputPatternListeners
          Contains the list of output connected listeners (OutputPatternListener)
protected  double[] outs
          Set of output values passed from this layer to connected OutputListeners durng the recall phase.
private  int rows
          The number of neurons in the layer
protected  boolean running
          Whether the layer is running
private static long serialVersionUID
          Serial version ID for this class
protected  int step
          The step number of the network run.
static int STOP_FLAG
          Stop flag.
 
Constructor Summary
Layer()
          The empty constructor
Layer(java.lang.String ElemName)
          Creates a named layer
 
Method Summary
 boolean addInputSynapse(InputPatternListener newListener)
          Adds a new input synapse to the layer
 void addNoise(double amplitude)
          Adds a noise componentto the biases of the layer and to all the input connected synapses.
 boolean addOutputSynapse(OutputPatternListener newListener)
          Adds a new output synapse to the layer
protected  void adjustSizeToFwdPattern(double[] aPattern)
          Adjusts the size of a layer if the size of the forward pattern differs.
protected  void adjustSizeToRevPattern(double[] aPattern)
          Adjusts the size of a layer if the size of the reverse pattern differs.
protected abstract  void backward(double[] pattern)
          Reverse transfer function of the component.
 java.util.TreeSet check()
          Get check messages from listeners.
protected  boolean checkInputEnabled()
          Checks if at least one input synapse is enabled
protected  boolean checkInputs(java.util.Vector inputListeners)
          Determine whether ther are any stream input synapses attached.
protected  boolean checkOutputs(java.util.Vector outputListeners)
          Determine whether ther are any stream output or teach synapses attached.
 void cicleTerminated(NeuralNetEvent e)
          Not implemented.
 NeuralLayer copyInto(NeuralLayer newLayer)
          Copies one layer into another, to obtain a type-transformation from one kind of Layer to another.
 void errorChanged(NeuralNetEvent e)
          Not implemented.
 void finalize()
          Method to help remove disused references quickly when the layer goes out of scope.
protected  void fireFwdGet()
          Calls all the fwdGet methods on the input synapses to get the input patterns
protected  void fireFwdPut(Pattern pattern)
          Calls all the fwdPut methods on the output synapses to pass them the calculated patterns
protected  void fireRevGet()
          Calls all the revGet methods on the output synapses to get the error gradients
protected  void fireRevPut(Pattern pattern)
          Calls all the revPut methods on the input synapses to get the input patterns and pass them the resulting calculated gradients
protected abstract  void forward(double[] pattern)
          Transfer function to recall a result on a trained net
 java.util.Vector getAllInputs()
          Returns the vector of the input listeners
 java.util.Vector getAllOutputs()
          Returns the vector of the output listeners
 Matrix getBias()
          Return the bias matrix
 int getDimension()
          Returns the number of neurons contained in the layer
 double[] getLastOutputs()
          Gets the values lastly outputed by the neurons of this layer.
 java.lang.String getLayerName()
          Returns the name of the layer
 Learner getLearner()
          Returns the appropriate Learner object for this class depending on the Monitor.learningMode property value
 Monitor getMonitor()
          Returns the monitor object
 int getRows()
          Returns the dimension (# of neurons) of the Layer
protected  java.lang.Object getThreadMonitor()
          Getter for property myThreadMonitor.
 boolean hasStepCounter()
          Determine whether this layer has an input synapse attached that is a step counter.
 void init()
           
 void initLearner()
          Initialize the Learner object of this layer
 java.lang.String InspectableTitle()
          Get the title for the inspectable interface
 java.util.Collection Inspections()
          Method to get a collection of bias inspections for this layer
 boolean isInputLayer()
          Determine whether this is an input layer.
 boolean isOutputLayer()
          Determine whether this is an output layer.
 boolean isRunning()
          Determine whether the execution thread is running
 void join()
          Waits for the current layer's thread to stop
 void netStarted(NeuralNetEvent e)
          Not implemented.
 void netStopped(NeuralNetEvent e)
          Not implemented.
 void netStoppedError(NeuralNetEvent e, java.lang.String error)
          Stops the execution thread and resets this layer in the event of an crtitical network error.
 void randomize(double amplitude)
          Initialize the weights of the biases and of all the connected synapses
private  void readObject(java.io.ObjectInputStream in)
          Read in a serialised version of this layer
private  java.util.Vector readVector(java.io.ObjectInputStream in)
          Create a Vector from a serialized version
 void removeAllInputs()
          Remove all the input listeners of the layer
 void removeAllOutputs()
          Remove all the output listeners of the layer
 void removeInputSynapse(InputPatternListener newListener)
          Remove an input Listener
 void removeOutputSynapse(OutputPatternListener newListener)
          Remove an output listener from the layer
protected  void resetInputListeners()
          Reset all the input listeners
 void run()
          The core running engine of the layer.
 void setAllInputs(java.util.Vector newInputPatternListeners)
          Sets the Vector that contains all the input listeners.
 void setAllOutputs(java.util.Vector newOutputPatternListeners)
          Sets the Vector that contains all the output listeners.
 void setBias(Matrix newBias)
          Sets the matrix of biases
protected  void setConnDimensions()
          Sets the input and output synapses' dimensions
protected abstract  void setDimensions()
          Sets the dimension of the layer.
protected  void setInputDimension(InputPatternListener syn)
          Sets the dimension of the listener passed as parameter.
 void setInputSynapses(java.util.ArrayList newInputPatternListeners)
          Sets the Vector that contains all the input listeners.
 void setLayerName(java.lang.String newLayerName)
          Sets the name of the layer
 void setMonitor(Monitor mon)
          Sets the monitor object
protected  void setOutputDimension(OutputPatternListener syn)
          Sets the dimension of the listener passed as parameter.
 void setOutputSynapses(java.util.ArrayList newOutputPatternListeners)
          Sets the Vector that contains all the output listeners.
 void setRows(int newRows)
          Sets the dimension (# of neurons) of the Layer
private  void setVectMonitor(java.util.Vector vect, Monitor mon)
          Set the monitor object for all pattern listeners in a Vector
 void start()
          Starts the Layer
 void stop()
          Stops the Layer
protected  void sumBackInput(double[] pattern)
          Calculates the net input of the error gradents during the learning phase
protected  void sumInput(double[] pattern)
          Calculates the net input of the values in the recall phase
 java.lang.String toString()
          Produce a String representation of this layer
private  void writeObject(java.io.ObjectOutputStream out)
          Write a serialized version of this layer
private  void writeVector(java.io.ObjectOutputStream out, java.util.Vector vect)
          This method is useful to serialize only the vector's elements that don't implement the Serialize interface, only when the Monitor.isExporting returns the value TRUE.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STOP_FLAG

public static final int STOP_FLAG
Stop flag. If the step has this value, the execution thread terminates.

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
Serial version ID for this class

See Also:
Constant Field Values

LayerName

private java.lang.String LayerName
The name of the layer


rows

private int rows
The number of neurons in the layer


bias

protected Matrix bias
Holds the bias of neurons of the layer


monitor

protected Monitor monitor
The monitor of the layer. Contains all parameters needed to the learning phase


m_batch

protected int m_batch
Not used but maintained for backward serialization compatability.


learning

protected boolean learning
The Net's phase: false == recall; true == learning


learnable

protected boolean learnable
Contains true if for the Layer must be used a Learner instead of a built-in learning algorithm. Set it in the constructor of any inherited class. Used by the getLearner method.

See Also:
getLearner

inputPatternListeners

protected java.util.Vector inputPatternListeners
Contains the list of input connected listeners (InputPatternListener)


outputPatternListeners

protected java.util.Vector outputPatternListeners
Contains the list of output connected listeners (OutputPatternListener)


myThread

private transient java.lang.Thread myThread
The execution Thread for this layer.


myThreadMonitor

private transient java.lang.Object myThreadMonitor
The monitor used to control read/write access to myThread


outs

protected transient double[] outs
Set of output values passed from this layer to connected OutputListeners durng the recall phase.


inps

protected transient double[] inps
Set of input values passed to this layer from connected InputListeners during the recall phase.


gradientInps

protected transient double[] gradientInps
Set of input error gradient values passed to this layer from connected OutputListenrs during the learning phase.


gradientOuts

protected transient double[] gradientOuts
Set of output error gradient values passed from this layer to connected InputListenrs during the learning phase.


step

protected transient int step
The step number of the network run.


running

protected transient boolean running
Whether the layer is running


myLearner

protected transient Learner myLearner
The Learner for this layer.


log

private static final org.joone.log.ILogger log
Logger for this class

Constructor Detail

Layer

public Layer()
The empty constructor


Layer

public Layer(java.lang.String ElemName)
Creates a named layer

Method Detail

addNoise

public void addNoise(double amplitude)
Adds a noise componentto the biases of the layer and to all the input connected synapses.

Specified by:
addNoise in interface NeuralLayer

randomize

public void randomize(double amplitude)
Initialize the weights of the biases and of all the connected synapses


backward

protected abstract void backward(double[] pattern)
                          throws org.joone.exception.JooneRuntimeException
Reverse transfer function of the component.


copyInto

public NeuralLayer copyInto(NeuralLayer newLayer)
Copies one layer into another, to obtain a type-transformation from one kind of Layer to another. The old Layer is disconnected from the net, and the new Layer takes its place.

Specified by:
copyInto in interface NeuralLayer

fireFwdGet

protected void fireFwdGet()
Calls all the fwdGet methods on the input synapses to get the input patterns


fireFwdPut

protected void fireFwdPut(Pattern pattern)
Calls all the fwdPut methods on the output synapses to pass them the calculated patterns


fireRevGet

protected void fireRevGet()
Calls all the revGet methods on the output synapses to get the error gradients


fireRevPut

protected void fireRevPut(Pattern pattern)
Calls all the revPut methods on the input synapses to get the input patterns and pass them the resulting calculated gradients


adjustSizeToFwdPattern

protected void adjustSizeToFwdPattern(double[] aPattern)
Adjusts the size of a layer if the size of the forward pattern differs.


adjustSizeToRevPattern

protected void adjustSizeToRevPattern(double[] aPattern)
Adjusts the size of a layer if the size of the reverse pattern differs.


forward

protected abstract void forward(double[] pattern)
                         throws org.joone.exception.JooneRuntimeException
Transfer function to recall a result on a trained net


getAllInputs

public java.util.Vector getAllInputs()
Returns the vector of the input listeners

Specified by:
getAllInputs in interface NeuralLayer

getAllOutputs

public java.util.Vector getAllOutputs()
Returns the vector of the output listeners

Specified by:
getAllOutputs in interface NeuralLayer

getBias

public Matrix getBias()
Return the bias matrix

Specified by:
getBias in interface NeuralLayer

getDimension

public int getDimension()
Returns the number of neurons contained in the layer


getLayerName

public java.lang.String getLayerName()
Returns the name of the layer

Specified by:
getLayerName in interface NeuralLayer

getMonitor

public Monitor getMonitor()
Returns the monitor object

Specified by:
getMonitor in interface NeuralLayer

getRows

public int getRows()
Returns the dimension (# of neurons) of the Layer

Specified by:
getRows in interface NeuralLayer

removeAllInputs

public void removeAllInputs()
Remove all the input listeners of the layer

Specified by:
removeAllInputs in interface NeuralLayer

removeAllOutputs

public void removeAllOutputs()
Remove all the output listeners of the layer

Specified by:
removeAllOutputs in interface NeuralLayer

removeInputSynapse

public void removeInputSynapse(InputPatternListener newListener)
Remove an input Listener

Specified by:
removeInputSynapse in interface NeuralLayer

removeOutputSynapse

public void removeOutputSynapse(OutputPatternListener newListener)
Remove an output listener from the layer

Specified by:
removeOutputSynapse in interface NeuralLayer

getLastOutputs

public double[] getLastOutputs()
Gets the values lastly outputed by the neurons of this layer.


run

public void run()
         throws org.joone.exception.JooneRuntimeException
The core running engine of the layer. Called from the method start()

Specified by:
run in interface java.lang.Runnable

setAllInputs

public void setAllInputs(java.util.Vector newInputPatternListeners)
Sets the Vector that contains all the input listeners. Can be useful to set the input synapses taken from another Layer

Specified by:
setAllInputs in interface NeuralLayer

setInputSynapses

public void setInputSynapses(java.util.ArrayList newInputPatternListeners)
Sets the Vector that contains all the input listeners. It accepts an ArrayList as parameter. Added for Spring Can be useful to set the input synapses taken from another Layer


setAllOutputs

public void setAllOutputs(java.util.Vector newOutputPatternListeners)
Sets the Vector that contains all the output listeners. Can be useful to set the output synapses taken from another Layer

Specified by:
setAllOutputs in interface NeuralLayer

setOutputSynapses

public void setOutputSynapses(java.util.ArrayList newOutputPatternListeners)
Sets the Vector that contains all the output listeners. It accepts an ArrayList as parameter. Added for Spring Can be useful to set the output synapses taken from another Layer


setBias

public void setBias(Matrix newBias)
Sets the matrix of biases

Specified by:
setBias in interface NeuralLayer

setDimensions

protected abstract void setDimensions()
Sets the dimension of the layer. Override to define how the internal buffers must be sized.


setInputDimension

protected void setInputDimension(InputPatternListener syn)
Sets the dimension of the listener passed as parameter. Called after a new input listener is added.


addInputSynapse

public boolean addInputSynapse(InputPatternListener newListener)
Adds a new input synapse to the layer

Specified by:
addInputSynapse in interface NeuralLayer

setLayerName

public void setLayerName(java.lang.String newLayerName)
Sets the name of the layer

Specified by:
setLayerName in interface NeuralLayer

setMonitor

public void setMonitor(Monitor mon)
Sets the monitor object

Specified by:
setMonitor in interface NeuralLayer

setVectMonitor

private void setVectMonitor(java.util.Vector vect,
                            Monitor mon)
Set the monitor object for all pattern listeners in a Vector


setOutputDimension

protected void setOutputDimension(OutputPatternListener syn)
Sets the dimension of the listener passed as parameter. Called after a new output listener is added.


addOutputSynapse

public boolean addOutputSynapse(OutputPatternListener newListener)
Adds a new output synapse to the layer

Specified by:
addOutputSynapse in interface NeuralLayer

setRows

public void setRows(int newRows)
Sets the dimension (# of neurons) of the Layer

Specified by:
setRows in interface NeuralLayer

start

public void start()
Starts the Layer

Specified by:
start in interface NeuralLayer

init

public void init()

checkInputEnabled

protected boolean checkInputEnabled()
Checks if at least one input synapse is enabled


stop

public void stop()
Stops the Layer


resetInputListeners

protected void resetInputListeners()
Reset all the input listeners


sumBackInput

protected void sumBackInput(double[] pattern)
Calculates the net input of the error gradents during the learning phase


sumInput

protected void sumInput(double[] pattern)
Calculates the net input of the values in the recall phase


readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Read in a serialised version of this layer


writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException
Write a serialized version of this layer


writeVector

private void writeVector(java.io.ObjectOutputStream out,
                         java.util.Vector vect)
                  throws java.io.IOException
This method is useful to serialize only the vector's elements that don't implement the Serialize interface, only when the Monitor.isExporting returns the value TRUE.


readVector

private java.util.Vector readVector(java.io.ObjectInputStream in)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
Create a Vector from a serialized version


setConnDimensions

protected void setConnDimensions()
Sets the input and output synapses' dimensions


isRunning

public boolean isRunning()
Determine whether the execution thread is running

Specified by:
isRunning in interface NeuralLayer

check

public java.util.TreeSet check()
Get check messages from listeners. Subclasses should call this method from thier own check method.

Specified by:
check in interface NeuralLayer

toString

public java.lang.String toString()
Produce a String representation of this layer


finalize

public void finalize()
              throws java.lang.Throwable
Method to help remove disused references quickly when the layer goes out of scope.


Inspections

public java.util.Collection Inspections()
Method to get a collection of bias inspections for this layer

Specified by:
Inspections in interface org.joone.inspection.Inspectable

InspectableTitle

public java.lang.String InspectableTitle()
Get the title for the inspectable interface

Specified by:
InspectableTitle in interface org.joone.inspection.Inspectable

hasStepCounter

public boolean hasStepCounter()
Determine whether this layer has an input synapse attached that is a step counter.


isInputLayer

public boolean isInputLayer()
Determine whether this is an input layer.


checkInputs

protected boolean checkInputs(java.util.Vector inputListeners)
Determine whether ther are any stream input synapses attached.


isOutputLayer

public boolean isOutputLayer()
Determine whether this is an output layer.


checkOutputs

protected boolean checkOutputs(java.util.Vector outputListeners)
Determine whether ther are any stream output or teach synapses attached. Also checks the attached listeners of OutputSwitchSynapses. Also checks for loopback condition. All connected synapses must be of this type.


netStarted

public void netStarted(NeuralNetEvent e)
Not implemented.

Specified by:
netStarted in interface NeuralNetListener

cicleTerminated

public void cicleTerminated(NeuralNetEvent e)
Not implemented.

Specified by:
cicleTerminated in interface NeuralNetListener

netStopped

public void netStopped(NeuralNetEvent e)
Not implemented.

Specified by:
netStopped in interface NeuralNetListener

errorChanged

public void errorChanged(NeuralNetEvent e)
Not implemented.

Specified by:
errorChanged in interface NeuralNetListener

netStoppedError

public void netStoppedError(NeuralNetEvent e,
                            java.lang.String error)
Stops the execution thread and resets this layer in the event of an crtitical network error.

Specified by:
netStoppedError in interface NeuralNetListener

getLearner

public Learner getLearner()
Returns the appropriate Learner object for this class depending on the Monitor.learningMode property value

Specified by:
getLearner in interface Learnable

initLearner

public void initLearner()
Initialize the Learner object of this layer

Specified by:
initLearner in interface Learnable

getThreadMonitor

protected java.lang.Object getThreadMonitor()
Getter for property myThreadMonitor.


join

public void join()
Waits for the current layer's thread to stop