public abstract class Layer extends java.lang.Object implements NeuralLayer, java.lang.Runnable, java.io.Serializable, Inspectable, LearnableLayer
Modifier and Type | Field and Description |
---|---|
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)
|
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
|
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.
|
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.
|
protected boolean |
running
Whether the layer is running
|
protected int |
step
The step number of the network run.
|
static int |
STOP_FLAG
Stop flag.
|
Constructor and Description |
---|
Layer()
The empty constructor
|
Layer(java.lang.String ElemName)
Creates a named layer
|
Modifier and Type | Method and Description |
---|---|
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.
|
NeuralLayer |
copyInto(NeuralLayer newLayer)
Copies one layer into another, to obtain a type-transformation
from one kind of Layer to another.
|
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
|
void |
fwdRun(Pattern pattIn)
Implementation code for the single-thread version of Joone.
|
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
|
abstract double |
getDefaultState()
Return the default state of a node in this layer, such as 0 for a tanh or 0.5 for a sigmoid layer
|
abstract double |
getDerivative(int i)
Return the derivative with respect to the function value at a given index.
|
int |
getDimension()
Returns the number of neurons contained in the layer
|
double[] |
getLastGradientInps()
Return the last input gradient
|
double[] |
getLastGradientOuts()
Return the last output gradient
|
double[] |
getLastInputs()
Return the last inputs
|
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
|
abstract double |
getMaximumState()
Return maximum value of a node in this layer
|
abstract double |
getMinimumState()
Return minimum value of a node in this layer
|
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 |
randomize(double amplitude)
Initialize the weights of the biases and of all the connected synapses
WARNING: amplitude parameter is ignored when elements are using WeightInitializer
other than RandomWeightInitializer
|
void |
randomizeBias(double amplitude)
Initialize the weights of the biases WARNING: amplitude parameter is
ignored when biases are using WeightInitializer other than
RandomWeightInitializer
|
void |
randomizeWeights(double amplitude)
Initialize the weights of all the connected synapses
WARNING: amplitude parameter is ignored when elements are using WeightInitializer
other than RandomWeightInitializer
|
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
|
protected void |
removeListener(NeuralNetListener listener) |
void |
removeOutputSynapse(OutputPatternListener newListener)
Remove an output listener from the layer
|
protected void |
resetInputListeners()
Reset all the input listeners
|
void |
revRun(Pattern pattIn)
This method serves to a single backward step
when the Layer is called from an external thread
|
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 |
setLastInputs(double[] inps)
Set the last inputs
|
void |
setLastOutputs(double[] outs)
Set the last outputs
|
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
|
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
|
public static final int STOP_FLAG
protected Matrix bias
protected Monitor monitor
protected int m_batch
protected boolean learning
protected boolean learnable
getLearner
protected java.util.Vector inputPatternListeners
protected java.util.Vector outputPatternListeners
protected transient double[] outs
protected transient double[] inps
protected transient double[] gradientInps
protected transient double[] gradientOuts
protected transient int step
protected transient volatile boolean running
protected transient Learner myLearner
public Layer()
public Layer(java.lang.String ElemName)
ElemName
- The name of the layerpublic void addNoise(double amplitude)
addNoise
in interface NeuralLayer
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.3public abstract double getDefaultState()
public abstract double getMinimumState()
public abstract double getMaximumState()
public void randomize(double amplitude)
amplitude
- the amplitude of uniformly generated random weightspublic void randomizeWeights(double amplitude)
amplitude
- the amplitude of uniformly generated random weightspublic void randomizeBias(double amplitude)
amplitude
- the amplitude of uniformly generated random weightsprotected abstract void backward(double[] pattern) throws JooneRuntimeException
pattern
- input pattern on which to apply the transfer functionJooneRuntimeException
public NeuralLayer copyInto(NeuralLayer newLayer)
copyInto
in interface NeuralLayer
newLayer
- the new layer with which to replace this oneprotected void fireFwdGet()
protected void fireFwdPut(Pattern pattern)
pattern
- the Pattern to pass to the output synapsesprotected void fireRevGet()
protected void fireRevPut(Pattern pattern)
pattern
- the Pattern to pass to the input listenersprotected void adjustSizeToFwdPattern(double[] aPattern)
aPattern
- the pattern holding a different size than the layer
(dimension of neurons is not in accordance with the dimension of the
pattern that is being forwarded).protected void adjustSizeToRevPattern(double[] aPattern)
aPattern
- the pattern holding a different size than the layer
(dimension of neurons is not in accordance with the dimension of the
pattern that is being reversed).protected abstract void forward(double[] pattern) throws JooneRuntimeException
pattern
- input pattern to which to apply the rtransfer functionJooneRuntimeException
public java.util.Vector getAllInputs()
getAllInputs
in interface NeuralLayer
public java.util.Vector getAllOutputs()
getAllOutputs
in interface NeuralLayer
public Matrix getBias()
getBias
in interface NeuralLayer
public int getDimension()
public java.lang.String getLayerName()
getLayerName
in interface NeuralLayer
public Monitor getMonitor()
getMonitor
in interface Learnable
getMonitor
in interface NeuralLayer
public int getRows()
getRows
in interface NeuralLayer
public void removeAllInputs()
removeAllInputs
in interface NeuralLayer
public void removeAllOutputs()
removeAllOutputs
in interface NeuralLayer
public void removeInputSynapse(InputPatternListener newListener)
removeInputSynapse
in interface NeuralLayer
newListener
- the input listener to removepublic void removeOutputSynapse(OutputPatternListener newListener)
removeOutputSynapse
in interface NeuralLayer
newListener
- the output listener to removeprotected void removeListener(NeuralNetListener listener)
public double[] getLastOutputs()
public double[] getLastInputs()
public void setLastInputs(double[] inps)
public void setLastOutputs(double[] outs)
public double[] getLastGradientInps()
public double[] getLastGradientOuts()
public void run() throws JooneRuntimeException
start()
run
in interface java.lang.Runnable
JooneRuntimeException
public void setAllInputs(java.util.Vector newInputPatternListeners)
setAllInputs
in interface NeuralLayer
newInputPatternListeners
- The vector containing the list of input synapsespublic void setInputSynapses(java.util.ArrayList newInputPatternListeners)
newInputPatternListeners
- The vector containing the list of input synapsespublic void setAllOutputs(java.util.Vector newOutputPatternListeners)
setAllOutputs
in interface NeuralLayer
newOutputPatternListeners
- The vector containing the list of output synapsespublic void setOutputSynapses(java.util.ArrayList newOutputPatternListeners)
newOutputPatternListeners
- The vector containing the list of output synapsespublic void setBias(Matrix newBias)
setBias
in interface NeuralLayer
newBias
- The Matrix object containing the biasesprotected abstract void setDimensions()
protected void setInputDimension(InputPatternListener syn)
syn
- the listener to be affectedpublic boolean addInputSynapse(InputPatternListener newListener)
addInputSynapse
in interface NeuralLayer
newListener
- The new input synapse to addpublic void setLayerName(java.lang.String newLayerName)
setLayerName
in interface NeuralLayer
newLayerName
- The namepublic void setMonitor(Monitor mon)
setMonitor
in interface NeuralLayer
mon
- The Monitorprotected void setOutputDimension(OutputPatternListener syn)
syn
- the OutputPatternListener to affectpublic boolean addOutputSynapse(OutputPatternListener newListener)
addOutputSynapse
in interface NeuralLayer
newListener
- The new output synapsepublic void setRows(int newRows)
setRows
in interface NeuralLayer
newRows
- The number of the neurons contained in the Layerpublic void start()
start
in interface NeuralLayer
public void init()
protected boolean checkInputEnabled()
public void stop()
protected void resetInputListeners()
protected void sumBackInput(double[] pattern)
pattern
- array of input valuesprotected void sumInput(double[] pattern)
pattern
- array of input valuesprotected void setConnDimensions()
public boolean isRunning()
isRunning
in interface NeuralLayer
public java.util.TreeSet check()
check
in interface NeuralLayer
NeuralLayer
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
Object.finalize()
public java.util.Collection Inspections()
Inspections
in interface Inspectable
org.joone.Inspection
public java.lang.String InspectableTitle()
InspectableTitle
in interface Inspectable
org.joone.InspectionFrame
public boolean hasStepCounter()
public boolean isInputLayer()
protected boolean checkInputs(java.util.Vector inputListeners)
inputListeners
- Vector to check.public boolean isOutputLayer()
protected boolean checkOutputs(java.util.Vector outputListeners)
outputListeners
- Vector to check.public Learner getLearner()
getLearner
in interface Learnable
Learnable.getLearner()
public void initLearner()
initLearner
in interface Learnable
Learnable.initLearner()
protected java.lang.Object getThreadMonitor()
public void join()
public void fwdRun(Pattern pattIn)
public void revRun(Pattern pattIn)
public abstract double getDerivative(int i)
Submit Feedback to pmarrone@users.sourceforge.net