org.joone.engine
Class Layer
- java.lang.Object
-
- org.joone.engine.Layer
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Runnable, Learnable, LearnableLayer, NeuralLayer, Inspectable
- Direct Known Subclasses:
- MemoryLayer, NestedNeuralLayer, RbfLayer, SimpleLayer
public abstract class Layer extends java.lang.Object implements NeuralLayer, java.lang.Runnable, java.io.Serializable, Inspectable, LearnableLayer
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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intSTOP_FLAGStop flag.
-
Constructor Summary
Constructors Constructor and Description Layer()The empty constructorLayer(java.lang.String ElemName)Creates a named layer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanaddInputSynapse(InputPatternListener newListener)Adds a new input synapse to the layervoidaddNoise(double amplitude)Adds a noise componentto the biases of the layer and to all the input connected synapses.booleanaddOutputSynapse(OutputPatternListener newListener)Adds a new output synapse to the layerjava.util.TreeSetcheck()Get check messages from listeners.NeuralLayercopyInto(NeuralLayer newLayer)Copies one layer into another, to obtain a type-transformation from one kind of Layer to another.voidfinalize()Method to help remove disused references quickly when the layer goes out of scope.voidfwdRun(Pattern pattIn)Implementation code for the single-thread version of Joone /********************************************************* /** This method serves to a single forward step when the Layer is called from an external threadjava.util.VectorgetAllInputs()Returns the vector of the input listenersjava.util.VectorgetAllOutputs()Returns the vector of the output listenersMatrixgetBias()Return the bias matrixintgetDimension()Returns the number of neurons contained in the layerdouble[]getLastOutputs()Gets the values lastly outputed by the neurons of this layer.java.lang.StringgetLayerName()Returns the name of the layerLearnergetLearner()Returns the appropriate Learner object for this class depending on the Monitor.learningMode property valueMonitorgetMonitor()Returns the monitor objectintgetRows()Returns the dimension (# of neurons) of the LayerbooleanhasStepCounter()Determine whether this layer has an input synapse attached that is a step counter.voidinit()voidinitLearner()Initialize the Learner object of this layerjava.lang.StringInspectableTitle()Get the title for the inspectable interfacejava.util.CollectionInspections()Method to get a collection of bias inspections for this layerbooleanisInputLayer()Determine whether this is an input layer.booleanisOutputLayer()Determine whether this is an output layer.booleanisRunning()Determine whether the execution thread is runningvoidjoin()Waits for the current layer's thread to stopvoidrandomize(double amplitude)Initialize the weights of the biases and of all the connected synapsesvoidremoveAllInputs()Remove all the input listeners of the layervoidremoveAllOutputs()Remove all the output listeners of the layervoidremoveInputSynapse(InputPatternListener newListener)Remove an input ListenervoidremoveOutputSynapse(OutputPatternListener newListener)Remove an output listener from the layervoidrevRun(Pattern pattIn)This method serves to a single backward step when the Layer is called from an external threadvoidrun()The core running engine of the layer.voidsetAllInputs(java.util.Vector newInputPatternListeners)Sets the Vector that contains all the input listeners.voidsetAllOutputs(java.util.Vector newOutputPatternListeners)Sets the Vector that contains all the output listeners.voidsetBias(Matrix newBias)Sets the matrix of biasesvoidsetInputSynapses(java.util.ArrayList newInputPatternListeners)Sets the Vector that contains all the input listeners.voidsetLayerName(java.lang.String newLayerName)Sets the name of the layervoidsetMonitor(Monitor mon)Sets the monitor objectvoidsetOutputSynapses(java.util.ArrayList newOutputPatternListeners)Sets the Vector that contains all the output listeners.voidsetRows(int newRows)Sets the dimension (# of neurons) of the Layervoidstart()Starts the Layervoidstop()Stops the Layerjava.lang.StringtoString()Produce a String representation of this layer
-
-
-
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
-
-
Constructor Detail
-
Layer
public Layer()
The empty constructor
-
Layer
public Layer(java.lang.String ElemName)
Creates a named layer- Parameters:
ElemName- The name of the 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:
addNoisein interfaceNeuralLayer- Parameters:
amplitude- the noise's amplitude in terms of distance from zero; e.g. a value equal 0.3 means a noise range from -0.3 to 0.3
-
randomize
public void randomize(double amplitude)
Initialize the weights of the biases and of all the connected synapses- Parameters:
amplitude- the amplitude of the applied noise
-
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:
copyIntoin interfaceNeuralLayer- Parameters:
newLayer- the new layer with which to replace this one- Returns:
- The new layer
-
getAllInputs
public java.util.Vector getAllInputs()
Returns the vector of the input listeners- Specified by:
getAllInputsin interfaceNeuralLayer- Returns:
- the connected input pattern listeners
-
getAllOutputs
public java.util.Vector getAllOutputs()
Returns the vector of the output listeners- Specified by:
getAllOutputsin interfaceNeuralLayer- Returns:
- the connected output pattern listeners
-
getBias
public Matrix getBias()
Return the bias matrix- Specified by:
getBiasin interfaceNeuralLayer- Returns:
- the layer biases
-
getDimension
public int getDimension()
Returns the number of neurons contained in the layer- Returns:
- the number of neurons in the layer.
-
getLayerName
public java.lang.String getLayerName()
Returns the name of the layer- Specified by:
getLayerNamein interfaceNeuralLayer- Returns:
- the name of the layer
-
getMonitor
public Monitor getMonitor()
Returns the monitor object- Specified by:
getMonitorin interfaceLearnable- Specified by:
getMonitorin interfaceNeuralLayer- Returns:
- the layer's Monitor object
-
getRows
public int getRows()
Returns the dimension (# of neurons) of the Layer- Specified by:
getRowsin interfaceNeuralLayer- Returns:
- the number of neurons in the layer
-
removeAllInputs
public void removeAllInputs()
Remove all the input listeners of the layer- Specified by:
removeAllInputsin interfaceNeuralLayer
-
removeAllOutputs
public void removeAllOutputs()
Remove all the output listeners of the layer- Specified by:
removeAllOutputsin interfaceNeuralLayer
-
removeInputSynapse
public void removeInputSynapse(InputPatternListener newListener)
Remove an input Listener- Specified by:
removeInputSynapsein interfaceNeuralLayer- Parameters:
newListener- the input listener to remove
-
removeOutputSynapse
public void removeOutputSynapse(OutputPatternListener newListener)
Remove an output listener from the layer- Specified by:
removeOutputSynapsein interfaceNeuralLayer- Parameters:
newListener- the output listener to remove
-
getLastOutputs
public double[] getLastOutputs()
Gets the values lastly outputed by the neurons of this layer.- Returns:
- the values lastly outputed.
-
run
public void run() throws JooneRuntimeExceptionThe core running engine of the layer. Called from the methodstart()- Specified by:
runin interfacejava.lang.Runnable- Throws:
JooneRuntimeException
-
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:
setAllInputsin interfaceNeuralLayer- Parameters:
newInputPatternListeners- The vector containing the list of input synapses
-
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- Parameters:
newInputPatternListeners- The vector containing the list of input synapses
-
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:
setAllOutputsin interfaceNeuralLayer- Parameters:
newOutputPatternListeners- The vector containing the list of output synapses
-
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- Parameters:
newOutputPatternListeners- The vector containing the list of output synapses
-
setBias
public void setBias(Matrix newBias)
Sets the matrix of biases- Specified by:
setBiasin interfaceNeuralLayer- Parameters:
newBias- The Matrix object containing the biases
-
addInputSynapse
public boolean addInputSynapse(InputPatternListener newListener)
Adds a new input synapse to the layer- Specified by:
addInputSynapsein interfaceNeuralLayer- Parameters:
newListener- The new input synapse to add- Returns:
- whether the listener was added
-
setLayerName
public void setLayerName(java.lang.String newLayerName)
Sets the name of the layer- Specified by:
setLayerNamein interfaceNeuralLayer- Parameters:
newLayerName- The name
-
setMonitor
public void setMonitor(Monitor mon)
Sets the monitor object- Specified by:
setMonitorin interfaceNeuralLayer- Parameters:
mon- The Monitor
-
addOutputSynapse
public boolean addOutputSynapse(OutputPatternListener newListener)
Adds a new output synapse to the layer- Specified by:
addOutputSynapsein interfaceNeuralLayer- Parameters:
newListener- The new output synapse- Returns:
- whether the listener was added
-
setRows
public void setRows(int newRows)
Sets the dimension (# of neurons) of the Layer- Specified by:
setRowsin interfaceNeuralLayer- Parameters:
newRows- The number of the neurons contained in the Layer
-
start
public void start()
Starts the Layer- Specified by:
startin interfaceNeuralLayer
-
init
public void init()
-
stop
public void stop()
Stops the Layer
-
isRunning
public boolean isRunning()
Determine whether the execution thread is running- Specified by:
isRunningin interfaceNeuralLayer- Returns:
- whether it is running
-
check
public java.util.TreeSet check()
Get check messages from listeners. Subclasses should call this method from thier own check method.- Specified by:
checkin interfaceNeuralLayer- Returns:
- validation errors.
- See Also:
NeuralLayer
-
toString
public java.lang.String toString()
Produce a String representation of this layer- Overrides:
toStringin classjava.lang.Object- Returns:
- string representation of the layer
- See Also:
Object.toString()
-
finalize
public void finalize() throws java.lang.ThrowableMethod to help remove disused references quickly when the layer goes out of scope.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable- See Also:
Object.finalize()
-
Inspections
public java.util.Collection Inspections()
Method to get a collection of bias inspections for this layer- Specified by:
Inspectionsin interfaceInspectable- Returns:
- See Also:
org.joone.Inspection
-
InspectableTitle
public java.lang.String InspectableTitle()
Get the title for the inspectable interface- Specified by:
InspectableTitlein interfaceInspectable- Returns:
- See Also:
org.joone.InspectionFrame
-
hasStepCounter
public boolean hasStepCounter()
Determine whether this layer has an input synapse attached that is a step counter.- Returns:
- whether it is a step counter.
-
isInputLayer
public boolean isInputLayer()
Determine whether this is an input layer.- Returns:
- whether this is an input layer
-
isOutputLayer
public boolean isOutputLayer()
Determine whether this is an output layer.- Returns:
- whether this is an output layer
-
getLearner
public Learner getLearner()
Returns the appropriate Learner object for this class depending on the Monitor.learningMode property value- Specified by:
getLearnerin interfaceLearnable- Returns:
- the Learner object if applicable, otherwise null
- See Also:
Learnable.getLearner()
-
initLearner
public void initLearner()
Initialize the Learner object of this layer- Specified by:
initLearnerin interfaceLearnable- See Also:
Learnable.initLearner()
-
join
public void join()
Waits for the current layer's thread to stop
-
fwdRun
public void fwdRun(Pattern pattIn)
Implementation code for the single-thread version of Joone /********************************************************* /** This method serves to a single forward step when the Layer is called from an external thread
-
revRun
public void revRun(Pattern pattIn)
This method serves to a single backward step when the Layer is called from an external thread
-
-
DataMelt 3.0 © DataMelt by jWork.ORG