lnsc.pmvf
Class FastSingleLayerNeuralNetwork

java.lang.Object
  |
  +--lnsc.pmvf.AbstractFunctionalUnit2
        |
        +--lnsc.pmvf.FastSingleLayerNeuralNetwork
All Implemented Interfaces:
java.lang.Cloneable, FunctionalUnit, FunctionalUnit2, java.io.Serializable

public final class FastSingleLayerNeuralNetwork
extends AbstractFunctionalUnit2

Implements a single layer feed forward network. It computes a weighted sum of each inputs for each output units. Output units are simple units (i.e. units with a single input and output) and markovienne (i.e. their output does not depend on anything else then their input). A bias can be added internally to the weighted sum if needed. Internal bias is added by expanding the input pattern by the left with the value 1 (i.e. inputPattern = [1 | inputPattern]).

This class is not very flexible, it is limited to simple output units and does not support embedded pre and post processing nor extra DataNames keywords except DataNames.NET_INPUT. processPattern is slightly faster than processDataSet and it is slightly faster when units implement processPattern directly such as classes derivated from AbstractSimpleUnit.

This class is planned to support left and right weight matrix multiplications or row-based or column-based concatenated weight vector for parametric methods. By default the weighted sum is given by y = Wx (left multiplication) and the parameter vector p = [w1 | ... | wk] where wi are the rows of W (rows concatenation).

Since:
1.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class lnsc.pmvf.FunctionalUnit2
FunctionalUnit2.ProcessPatternResult2
 
Nested classes inherited from class lnsc.FunctionalUnit
FunctionalUnit.ProcessPatternResult
 
Field Summary
 
Fields inherited from interface lnsc.FunctionalUnit
EMPTY_PATTERN
 
Constructor Summary
FastSingleLayerNeuralNetwork(int newInputCount, boolean newHasBias, FunctionalUnit[] newOutputUnits)
          Creates a single layer network for a given number of inputs, and with a given number of output units of a given type.
FastSingleLayerNeuralNetwork(int newInputCount, boolean newHasBias, FunctionalUnit[] newOutputUnits, boolean newUseLeftMultiplication, boolean newUseRowsConcatenation)
          Creates a single layer network for a given number of inputs, and with a given number of output units of a given type.
FastSingleLayerNeuralNetwork(int newInputCount, boolean newHasBias, int newOutputCount, FunctionalUnit newOutputUnit)
          Creates a single layer network for a given number of inputs, and with a given number of output units of a given type.
FastSingleLayerNeuralNetwork(int newInputCount, boolean newHasBias, int newOutputCount, FunctionalUnit newOutputUnit, boolean newUseLeftMultiplication, boolean newUseRowsConcatenation)
          Creates a single layer network for a given number of inputs, and with a given number of output units of a given type.
 
Method Summary
 java.lang.Object clone()
           
 FunctionalUnit[] getOutputUnits()
          Gets a reference to the array of output units.
 double[] getParameters()
          Gets a copy of the parameters as a vector.
 double[][] getWeights()
          Gets a reference to the weight matrix.
 boolean hasBias()
          Indicates whether there is an internal bias.
 FunctionalUnit2.ProcessPatternResult2 processPattern(double[] inputPattern, boolean computeDerivative, boolean computeSecondDerivative, boolean computeParameterDerivative, boolean computeParameterSecondDerivative, java.lang.String[] recordList)
          Processes an input pattern and returns its output pattern and derivatives (if requested).
 void reset()
          Reset internal transient state for non stateless functions.
 void setParameters(double[] parameters)
          Sets the parameters values to those of a given vector.
 void setWeights(double[][] newWeights)
          Assigns a new weight matrix by reference.
 java.lang.String toString()
           
 boolean useLeftMultiplication()
          Indicates whether it used weights matrix as left multiplication (y = Wx) of the input pattern or as right multiplication (y = xW) of the inputs.
 boolean useRowsConcatenation()
          Indicates whether the matrix is tranformed by concatenation of its rows (p = [w1 | ...
 
Methods inherited from class lnsc.pmvf.AbstractFunctionalUnit2
getInputCount, getOutputCount, getParameterCount, isDifferentiable, isParameterDifferentiable, isParameterTwiceDifferentiable, isStateless, isTwiceDifferentiable, processDataSet, processPattern
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastSingleLayerNeuralNetwork

public FastSingleLayerNeuralNetwork(int newInputCount,
                                    boolean newHasBias,
                                    FunctionalUnit[] newOutputUnits)
Creates a single layer network for a given number of inputs, and with a given number of output units of a given type. A bias may be provided internally. have a bias unit on demand.

Parameters:
newInputCount - Number of inputs.
newHasBias - Indicates whether a bias input should be added internally.
newOutputUnits - Array of simple output units.

FastSingleLayerNeuralNetwork

public FastSingleLayerNeuralNetwork(int newInputCount,
                                    boolean newHasBias,
                                    FunctionalUnit[] newOutputUnits,
                                    boolean newUseLeftMultiplication,
                                    boolean newUseRowsConcatenation)
Creates a single layer network for a given number of inputs, and with a given number of output units of a given type. A bias may be provided internally. IMPORTANT: If the output units are not stateless, they must all be DISTINCT (false under == ). have a bias unit on demand.

Parameters:
newInputCount - Number of inputs.
newHasBias - Indicates whether a bias input should be added internally.
newOutputUnits - Array of simple output units.
newUseLeftMultiplication - true for left multiplication (y = Wx) and false for right multiplication (y = xW).
newUseRowsConcatenation - true for rows concatenation (p = [w1 | ... | wk] where wi are rows of W) and false for columns concatenation (p = [w1T | ... | wkT] where wj are columns of W).

FastSingleLayerNeuralNetwork

public FastSingleLayerNeuralNetwork(int newInputCount,
                                    boolean newHasBias,
                                    int newOutputCount,
                                    FunctionalUnit newOutputUnit)
Creates a single layer network for a given number of inputs, and with a given number of output units of a given type. A bias may be provided internally. have a bias unit on demand.

Parameters:
newInputCount - Number of inputs.
newHasBias - Indicates whether a bias input should be added internally.
newOutputCount - Number of outputs.
newOutputUnit - Sample of an output unit.

FastSingleLayerNeuralNetwork

public FastSingleLayerNeuralNetwork(int newInputCount,
                                    boolean newHasBias,
                                    int newOutputCount,
                                    FunctionalUnit newOutputUnit,
                                    boolean newUseLeftMultiplication,
                                    boolean newUseRowsConcatenation)
Creates a single layer network for a given number of inputs, and with a given number of output units of a given type. A bias may be provided internally. have a bias unit on demand.

Parameters:
newInputCount - Number of inputs.
newHasBias - Indicates whether a bias input should be added internally.
newOutputCount - Number of outputs.
newOutputUnit - Sample of an output unit.
newUseLeftMultiplication - true for left multiplication (y = Wx) and false for right multiplication (y = xW).
newUseRowsConcatenation - true for rows concatenation (p = [w1 | ... | wk] where wi are rows of W) and false for columns concatenation (p = [w1T | ... | wkT] where wj are columns of W).
Method Detail

clone

public java.lang.Object clone()
Specified by:
clone in interface FunctionalUnit
Overrides:
clone in class AbstractFunctionalUnit2

getOutputUnits

public final FunctionalUnit[] getOutputUnits()
Gets a reference to the array of output units. Modifying the units inside this array could lead to unexpected error.

Returns:
Reference to the array of output units.

getParameters

public double[] getParameters()
Description copied from interface: FunctionalUnit2
Gets a copy of the parameters as a vector.

Returns:
A copy of the parameter values.

getWeights

public double[][] getWeights()
Gets a reference to the weight matrix. Matrix sizes depends on the {link #useLeftMultiplication()} value.

Returns:
References to the weights matrix.

hasBias

public boolean hasBias()
Indicates whether there is an internal bias.

Returns:
true id there is an internal bias.

processPattern

public FunctionalUnit2.ProcessPatternResult2 processPattern(double[] inputPattern,
                                                            boolean computeDerivative,
                                                            boolean computeSecondDerivative,
                                                            boolean computeParameterDerivative,
                                                            boolean computeParameterSecondDerivative,
                                                            java.lang.String[] recordList)
Description copied from interface: FunctionalUnit2
Processes an input pattern and returns its output pattern and derivatives (if requested).

Specified by:
processPattern in interface FunctionalUnit2
Overrides:
processPattern in class AbstractFunctionalUnit2
Parameters:
inputPattern - The input pattern.
computeDerivative - Must be true if the derivative should be computed.
computeSecondDerivative - Must be true if the second derivative should be computed.
computeParameterDerivative - Must be true if the derivative with respect to the parameters should be computed.
computeParameterSecondDerivative - Must be true if be the derivative with respect to the parameters should be computed.
recordList - Extra data to be recorded.
Returns:
The output pattern and the derivative (if requested).

reset

public void reset()
Description copied from interface: FunctionalUnit
Reset internal transient state for non stateless functions.

Specified by:
reset in interface FunctionalUnit
Overrides:
reset in class AbstractFunctionalUnit2

setParameters

public void setParameters(double[] parameters)
Description copied from interface: FunctionalUnit2
Sets the parameters values to those of a given vector.


setWeights

public void setWeights(double[][] newWeights)
Assigns a new weight matrix by reference. Matrix sizes depends on the {link #useLeftMultiplication()} value.


toString

public java.lang.String toString()
Overrides:
toString in class AbstractFunctionalUnit2

useLeftMultiplication

public boolean useLeftMultiplication()
Indicates whether it used weights matrix as left multiplication (y = Wx) of the input pattern or as right multiplication (y = xW) of the inputs.

Returns:
true if it uses left multiplication (default).

useRowsConcatenation

public boolean useRowsConcatenation()
Indicates whether the matrix is tranformed by concatenation of its rows (p = [w1 | ... | wk] where wi are the rows) or its column (p = [w1T | ... | wkT] where wj are the columns) to generate the vector parameter representation.

Returns:
true if it uses rows concatenation (default).