org.joone.engine.learning
Class AbstractTeacherSynapse

java.lang.Object
  extended by org.joone.engine.Synapse
      extended by org.joone.engine.learning.AbstractTeacherSynapse
All Implemented Interfaces:
java.io.Serializable, InputPatternListener, Learnable, LearnableSynapse, NeuralElement, OutputPatternListener, Inspectable
Direct Known Subclasses:
TeacherSynapse

public abstract class AbstractTeacherSynapse
extends Synapse

This class provides a framework to extend in order to implement various teachers, just by overriding or implementing certain functions different functionality can easily implemented.

Author:
Boris Jansen
See Also:
Serialized Form

Field Summary
protected  int currEpoch
           
protected  StreamInputSynapse desired
          The stream from where to read the desired input.
protected  Fifo error
          Into this FIFO (first-in-first-out) object, the calculated error (e.g.
protected  boolean lastErrorPatternReady
          True if an error pattern is available
protected static ILogger log
          Logger
protected  NeuralNet net
           
 
Fields inherited from class org.joone.engine.Synapse
array, b_pattern, bitems, bouts, count, enabled, fwdLock, inps, items, learnable, m_batch, m_pattern, myLearner, outs, revLock
 
Constructor Summary
AbstractTeacherSynapse()
          Creates a new instance of AbstractTeacherSynapse
AbstractTeacherSynapse(NeuralNet net)
           
 
Method Summary
protected  void backward(double[] pattern)
          Funzione di TRAIN dell'elemento.
abstract  double calculateError(double aDesired, double anOutput, int anIndex)
          Calculates the error to be backpropaged for a single output neuron.
abstract  double calculateGlobalError()
          This method is called after an epoch finished and the global error should be calculated.
 java.util.TreeSet check()
          Base for check messages.
protected  void constructErrorPattern(double[] aDesired, double[] anOutput)
          Constructs the error pattern that will be back-propagated.
protected  void epochFinished()
          This method is called to signal that an epoch has finished.
protected  void forward(double[] pattern)
          Recall function
 Pattern fwdGet()
          Here, it forwards (returns) the pushed error (in FIFO order).
 void fwdPut(Pattern pattern)
          Method to put a pattern forward to the next layer
 StreamInputSynapse getDesired()
          Gets the stream to read the desired output.
 double[] getLastErrorPattern()
          Return the most recently seen error pattern
protected  int getSeenPatterns()
          Get the value of the number of patterns seen during the current epoch.
protected  void incSeenPatterns()
          Increases the number of seen patterns by one.
 void init()
          Synapse's initialization.
protected  boolean isFirstTime()
          Checks whether it is the first time data is passed to this teacher or not.
 boolean isLastErrorPatternReady()
          See if we have an error pattern available
 void netStoppedError()
           
protected  void pushError(double error, int count)
          Pushes the calculated array in the FIFO queue at the end of a epoch, that is after all patterns have been seen.
protected  java.lang.Object readResolve()
           
 void reset()
          Reset the input and desired synapses
 void resetInput()
           
 Pattern revGet()
          Returns the error pattern coming from the next layer during the training phase
 void revPut(Pattern pattern)
          Method to put an error pattern backward to the previous layer
protected  void setArrays(int rows, int cols)
          Insert the method's description here.
 boolean setDesired(StreamInputSynapse newDesired)
          Set the input data stream containing desired training data.
protected  void setDimensions(int rows, int cols)
          Dimensiona l'elemento
protected  void setFirstTime(boolean aValue)
          Sets the first time flag (is it the first time data is forwarded to this teacher).
 void setInputDimension(int newInputDimension)
          Sets the input dimension of the synapse
 void setMonitor(Monitor newMonitor)
          Sets the Monitor object of the Teacher Synapse.
protected  void setSeenPatterns(int aValue)
          Set the value of the number of patterns seen during the current epoch.
protected  void stopTheNet()
           
 
Methods inherited from class org.joone.engine.Synapse
addNoise, canCountSteps, fwdPattern_consume, fwdPattern_produce, getCount, getFwdLock, getIgnoreBefore, getInputDimension, getLearner, getLearningRate, getMomentum, getMonitor, getName, getOutputDimension, getRevLock, getSynapseNameSafely, getWeights, initLearner, InspectableTitle, Inspections, isEnabled, isInputFull, isLoopBack, isOutputFull, randomize, revPattern_consume, revPattern_produce, setEnabled, setIgnoreBefore, setInputFull, setLearningRate, setLoopBack, setMomentum, setName, setOutputDimension, setOutputFull, setWeights, warnLogger, warnLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final ILogger log
Logger


desired

protected StreamInputSynapse desired
The stream from where to read the desired input.


error

protected transient Fifo error
Into this FIFO (first-in-first-out) object, the calculated error (e.g. RMSE) after an epoch will be pushed. This way an (external) application/component is able to read the errors at any moment, providing a loose-coupling mechanism.


currEpoch

protected transient int currEpoch

net

protected NeuralNet net

lastErrorPatternReady

protected boolean lastErrorPatternReady
True if an error pattern is available

Constructor Detail

AbstractTeacherSynapse

public AbstractTeacherSynapse(NeuralNet net)

AbstractTeacherSynapse

public AbstractTeacherSynapse()
Creates a new instance of AbstractTeacherSynapse

Method Detail

setFirstTime

protected void setFirstTime(boolean aValue)
Sets the first time flag (is it the first time data is forwarded to this teacher).

Parameters:
aValue - value for the first time flag.

isFirstTime

protected boolean isFirstTime()
Checks whether it is the first time data is passed to this teacher or not.

Returns:
true if it is the first time data is passed to this teacher, false otherwise.

backward

protected void backward(double[] pattern)
Description copied from class: Synapse
Funzione di TRAIN dell'elemento.

Specified by:
backward in class Synapse
Parameters:
pattern - double[] - pattern di input sul quale applicare la funzione di trasferimento

pushError

protected void pushError(double error,
                         int count)
Pushes the calculated array in the FIFO queue at the end of a epoch, that is after all patterns have been seen.

Parameters:
error, - the calculated error.
count, - the cycle of the calculated error.

stopTheNet

protected void stopTheNet()

getSeenPatterns

protected int getSeenPatterns()
Get the value of the number of patterns seen during the current epoch.

Returns:
the patterns seen during the current epoch.

setSeenPatterns

protected void setSeenPatterns(int aValue)
Set the value of the number of patterns seen during the current epoch.

Parameters:
aValue - the new value for the number of patterns seen during the current epoch.

incSeenPatterns

protected void incSeenPatterns()
Increases the number of seen patterns by one.


fwdGet

public Pattern fwdGet()
Here, it forwards (returns) the pushed error (in FIFO order).

Specified by:
fwdGet in interface InputPatternListener
Overrides:
fwdGet in class Synapse
Returns:
the pattern holding the error of the network. {@link Synapse#fwdGet()

getDesired

public StreamInputSynapse getDesired()
Gets the stream to read the desired output.

Returns:
the desired output stream.

setDesired

public boolean setDesired(StreamInputSynapse newDesired)
Set the input data stream containing desired training data.

Parameters:
newDesired - the stream from where to read the desired output.

readResolve

protected java.lang.Object readResolve()
Overrides:
readResolve in class Synapse

setArrays

protected void setArrays(int rows,
                         int cols)
Description copied from class: Synapse
Insert the method's description here. Creation date: (23/09/2000 12.52.58)

Specified by:
setArrays in class Synapse

setDimensions

protected void setDimensions(int rows,
                             int cols)
Description copied from class: Synapse
Dimensiona l'elemento

Specified by:
setDimensions in class Synapse

setInputDimension

public void setInputDimension(int newInputDimension)
Description copied from class: Synapse
Sets the input dimension of the synapse

Specified by:
setInputDimension in interface OutputPatternListener
Overrides:
setInputDimension in class Synapse
Parameters:
newInputDimension - int

reset

public void reset()
Reset the input and desired synapses

Specified by:
reset in interface InputPatternListener
Overrides:
reset in class Synapse

resetInput

public void resetInput()

setMonitor

public void setMonitor(Monitor newMonitor)
Sets the Monitor object of the Teacher Synapse.

Specified by:
setMonitor in interface NeuralElement
Overrides:
setMonitor in class Synapse
Parameters:
newMonitor - neural.engine.Monitor

netStoppedError

public void netStoppedError()

init

public void init()
Description copied from class: Synapse
Synapse's initialization. It needs to be invoked at the starting of the neural network It's called within the Layer.init() method

Specified by:
init in interface NeuralElement
Overrides:
init in class Synapse

check

public java.util.TreeSet check()
Description copied from class: Synapse
Base for check messages. Subclasses should call this method from thier own check method.

Specified by:
check in interface NeuralElement
Overrides:
check in class Synapse
Returns:
validation errors.
See Also:
InputPaternListener, OutputPaternListener

revPut

public void revPut(Pattern pattern)
Description copied from interface: InputPatternListener
Method to put an error pattern backward to the previous layer

Specified by:
revPut in interface InputPatternListener
Overrides:
revPut in class Synapse
Parameters:
pattern - neural.engine.Pattern

revGet

public Pattern revGet()
Description copied from interface: OutputPatternListener
Returns the error pattern coming from the next layer during the training phase

Specified by:
revGet in interface OutputPatternListener
Overrides:
revGet in class Synapse
Returns:
neural.engine.Pattern

fwdPut

public void fwdPut(Pattern pattern)
Description copied from interface: OutputPatternListener
Method to put a pattern forward to the next layer

Specified by:
fwdPut in interface OutputPatternListener
Overrides:
fwdPut in class Synapse
Parameters:
pattern - neural.engine.Pattern

forward

protected void forward(double[] pattern)
Description copied from class: Synapse
Recall function

Specified by:
forward in class Synapse
Parameters:
pattern - double[] - input pattern. THIS PATTERN CANNOT BE CHANGED

constructErrorPattern

protected void constructErrorPattern(double[] aDesired,
                                     double[] anOutput)
Constructs the error pattern that will be back-propagated.

Parameters:
aDesired - the desired pattern
anOutput - the actual output pattern

calculateError

public abstract double calculateError(double aDesired,
                                      double anOutput,
                                      int anIndex)
Calculates the error to be backpropaged for a single output neuron. (The function should also update the global error internally).

Parameters:
aDesired - the desired output
anOutput - the actual output of a single neuron
anIndex - the index of the output neuron
Returns:
the error to be back propagated

calculateGlobalError

public abstract double calculateGlobalError()
This method is called after an epoch finished and the global error should be calculated.

Returns:
the global error (at the end of an epoch).

epochFinished

protected void epochFinished()
This method is called to signal that an epoch has finished. Better to say is that a new epoch has started, because this method is called when the first pattern of a new epoch arrives at the teacher. New implementations of teachers can overwrite this method for their own use. (Please do call super.epochFinished()).


getLastErrorPattern

public double[] getLastErrorPattern()
Return the most recently seen error pattern


isLastErrorPatternReady

public boolean isLastErrorPatternReady()
See if we have an error pattern available



Submit Feedback to pmarrone@users.sourceforge.net