mosaic.sim.neuron.netoutputs
Class OutputFilter

java.lang.Object
  |
  +--mosaic.sim.neuron.netoutputs.OutputFilter
All Implemented Interfaces:
MatrixOutputListener, VectorOutputListener

public class OutputFilter
extends java.lang.Object
implements VectorOutputListener, MatrixOutputListener

This class is a decorator for output listeners, enabling the filtering of output events: - first of all, it can pass only the first event and filter out all subsequent ones - secondly, events can be forwarded when the have reached an equilibrium, i.e. they do not change anymore within a given error range The constructor intializes the filter. When forwardMultipleEvents is true, then all events will be forwarded (depending on the value of waitForEquilibrium). If it is false, only the first event (also depending on waitForEquilibrium) will be forwarded. When waitForEquilibrium is true, then an event will forwarded only when the difference to the previously received event is within a certain, given margin. E.g. when waitForEquilibrium and forwardMultipleEvents are both true, then the filter discards all events that change too much and forwards the first one that has a small difference (as given by maxSquareError). After this forwarding, the filter resets and waits for the next equilibrium. The "error", i.e. the difference between two received events, is calculated as the squared difference between the vectors or matrices. When the error is below the given maxSquareError, then the state is regarded as being an equilibrium. Note that the error is divided by the number of elements in the vector or matrix for normalization.


Field Summary
protected  boolean forwardedFirstEvent
          True when an event has already been forwarded.
protected  boolean forwardMultipleEvents
          When true, then multiple events will be forwarded.
protected  double[][] lastMatrix
          The last matrix that has been received - used for determining if an equilibrium has been reached.
protected  double[] lastVector
          The last vector that has been received - used for determining if an equilibrium has been reached.
protected  double maxSquareError
          The maximum square error for determining if the received event is in an equilibrium state.
protected  MatrixOutputListener nextMatrixListener
          The object to which the filtered matrix events will be forwarded.
protected  VectorOutputListener nextVectorListener
          The object to which the filtered vector events will be forwarded.
protected  boolean waitForEquilibrium
          When true, then only those events will be forwarded that are only marginally different from the previous.
 
Constructor Summary
OutputFilter(VectorOutputListener nextVectorListener, MatrixOutputListener nextMatrixListener, boolean forwardMultipleEvents, boolean waitForEquilibrium, double maxSquareError)
          Constructs an OuptutFilter object and initializes the mamber variables according to the given parameters.
 
Method Summary
protected  double calcSquareError(double[][] lastMatrx, double[][] matrix)
          Calculates the normalized (divided by number of elements in the matrix length) square difference between the given matrices.
protected  double calcSquareError(double[] lastVector, double[] vector)
          Calculates the normalized (divided by the vector length) square difference between the given vectors.
 void outputEvent(double[] vector)
          Implementation of VectorOutputListener.outputEvent.
 void outputEvent(double[][] matrix)
          Implementation of MatrixOutputListener.outputEvent.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

nextVectorListener

protected VectorOutputListener nextVectorListener
The object to which the filtered vector events will be forwarded. If this is null, then the vector events will not be forwarded.

nextMatrixListener

protected MatrixOutputListener nextMatrixListener
The object to which the filtered matrix events will be forwarded. If this is null, then the matrix events will not be forwarded.

forwardMultipleEvents

protected boolean forwardMultipleEvents
When true, then multiple events will be forwarded. When false, only a single event will ever be forwarded. See the class description for details.

waitForEquilibrium

protected boolean waitForEquilibrium
When true, then only those events will be forwarded that are only marginally different from the previous. See the class description for details.

maxSquareError

protected double maxSquareError
The maximum square error for determining if the received event is in an equilibrium state. See the class description for details.

forwardedFirstEvent

protected boolean forwardedFirstEvent
True when an event has already been forwarded.

lastVector

protected double[] lastVector
The last vector that has been received - used for determining if an equilibrium has been reached.

lastMatrix

protected double[][] lastMatrix
The last matrix that has been received - used for determining if an equilibrium has been reached.
Constructor Detail

OutputFilter

public OutputFilter(VectorOutputListener nextVectorListener,
                    MatrixOutputListener nextMatrixListener,
                    boolean forwardMultipleEvents,
                    boolean waitForEquilibrium,
                    double maxSquareError)
Constructs an OuptutFilter object and initializes the mamber variables according to the given parameters.
Parameters:
nextVectorListener - See member variable nextVectorListener
nextMatrixListener - See member variable nextMatrixListener
forwardMultipleEvents - See member variable forwardMultipleEvents
waitForEquilibrium - See member variable waitForEquilibrium
maxSquareError - See member variable maxSquareError
Method Detail

calcSquareError

protected double calcSquareError(double[] lastVector,
                                 double[] vector)
Calculates the normalized (divided by the vector length) square difference between the given vectors.

calcSquareError

protected double calcSquareError(double[][] lastMatrx,
                                 double[][] matrix)
Calculates the normalized (divided by number of elements in the matrix length) square difference between the given matrices.

outputEvent

public void outputEvent(double[] vector)
Implementation of VectorOutputListener.outputEvent.
Specified by:
outputEvent in interface VectorOutputListener
Following copied from interface: mosaic.sim.neuron.netoutputs.VectorOutputListener
Parameters:
vector - The real numbered values corresponding to the spike series using the respective coding scheme implemented by the Spike decoder.

outputEvent

public void outputEvent(double[][] matrix)
Implementation of MatrixOutputListener.outputEvent.
Specified by:
outputEvent in interface MatrixOutputListener
Following copied from interface: mosaic.sim.neuron.netoutputs.MatrixOutputListener
Parameters:
matrix - The real numbered values corresponding to the spike series using the respective coding scheme implemented by the Spike decoder.