dLife Home Page

dlife.nn
Class FFNeuralNetwork

java.lang.Object
  extended by dlife.sys.SerializationBase
      extended by dlife.nn.NeuralNetwork
          extended by dlife.nn.FFNeuralNetwork
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ElmanNeuralNetwork, FFBPNeuralNetwork

public class FFNeuralNetwork
extends NeuralNetwork

Implementation of a fully connected multi-layer feed forward neural network. The input layer of the network consists of a layer of "identity neurons" where the outputs are identical to the inputs. Further, there are no weights between an input and its associated "identity neuron." There is a layer of weights between every pair of Neuron layers. Each neuron in a hidden or output layer contains a bias weight with input 1. The output of the network is the output of the neurons in the final layer (after possible filtering by an NNDataFilter).

Version:
Jan 9, 2007
Author:
Grant Braught, Dickinson College
See Also:
Serialized Form

Field Summary
protected  double[][][] ffweights
           
protected  double[][] layerInputs
           
protected  double[][] layerOutputs
           
protected  Neuron nType
           
 
Fields inherited from class dlife.nn.NeuralNetwork
filteredInputs, filteredOutputs, rawInputs, rawOutputs
 
Constructor Summary
FFNeuralNetwork(double[][][] ffweights, Neuron nType)
          Construct a new FFNeuralNetwork by providing the weight matrix for the network.
FFNeuralNetwork(int[] layers, double[] weights, Neuron nType)
          Construct a new FFNeuralNetwork using the provided 1d array of weights.
FFNeuralNetwork(int[] layers, Neuron nType)
          Construct a new FFNeuralNetwork with the specified number of neurons in the layers and using the specified type of Neuron.
 
Method Summary
 boolean[][] getConnections()
          This method throws an UnsupportedOperationException because the FFNeuralNetwork does not use the connections matrix in the underlying NeuralNetwork class.
 double[][][] getFFWeights()
          Return the internal weights matrix.
 double[] getFFWeights1d()
          Get a 1d representation of the weights in this FFNeuralNetwork.
 double[][] getLayerInputs()
          Get the inputs to the input, each hidden and output layers of neurons for this FFNeuralNetwork.
 double[][] getLayerOutputs()
          Get the outputs of the input, each hidden and output layers of neurons for this FFNeuralNetwork.
 double[][] getWeights()
          This method throws an UnsupportedOperationException because the FFNeuralNetwork does not rely on the weights in the underlying NeuralNetwork class.
protected  void makeLayerInputs()
           
protected  void makeLayerOutputs()
           
 int numInputs()
          Get the number of inputs that there are in this FFNeuralNetowrk.
 int numOutputs()
          Get the number of outputs that there are in this FFNeuralNetwork.
 void propagate()
          Propagate the current filtered input values through the network.
 void randomizeWeights()
          Randomize the weights in this neural network.
static Object read(String filename)
          Read and return the FFNeuralNetwork contained in the specified filename using Java's object serialization mechanism.
 void setInputs(double[] inputs)
          Set the inputs to this FFNeuralNetwork.
 
Methods inherited from class dlife.nn.NeuralNetwork
evaluate, evaluate, getFilteredInputs, getFilteredOutputs, getInputFilter, getInputFilter, getOutputFilter, getOutputFilter, getRawInputs, getRawOutputs, setInputFilter, setInputFilter, setOutputFilter, setOutputFilter, setOutputs
 
Methods inherited from class dlife.sys.SerializationBase
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nType

protected Neuron nType

ffweights

protected double[][][] ffweights

layerInputs

protected transient double[][] layerInputs

layerOutputs

protected transient double[][] layerOutputs
Constructor Detail

FFNeuralNetwork

public FFNeuralNetwork(int[] layers,
                       Neuron nType)
Construct a new FFNeuralNetwork with the specified number of neurons in the layers and using the specified type of Neuron.

Parameters:
layers - an array of ints specifying the number of neurons in each layer of the network.
nType - the type of neuron in the network.

FFNeuralNetwork

public FFNeuralNetwork(double[][][] ffweights,
                       Neuron nType)
                throws IllegalArgumentException
Construct a new FFNeuralNetwork by providing the weight matrix for the network. The format of the weight matrix for a FFNeuralNetwork is: Therefore:

Parameters:
ffweights - the weights matrix.
nType - the type of Neuron to use for this network.
Throws:
IllegalArgumentException - if the ffweights do not specify a fully connected network.

FFNeuralNetwork

public FFNeuralNetwork(int[] layers,
                       double[] weights,
                       Neuron nType)
Construct a new FFNeuralNetwork using the provided 1d array of weights. The order of the weights in the 1d array is expected to be in the same order as that returned by the getFFWeights1d method.

Parameters:
layers - an array of ints specifying the number of neurons in each layer of the network.
weights - the weights for this network.
nType - the type of Neuron to use for this network.
Throws:
illegalArgumentException - if weights does not contain the correct number of weights.
Method Detail

makeLayerInputs

protected void makeLayerInputs()

makeLayerOutputs

protected void makeLayerOutputs()

randomizeWeights

public void randomizeWeights()
Randomize the weights in this neural network. The weights are normally distributed with mean 0 and standard deviation 0.5.


getFFWeights

public double[][][] getFFWeights()
Return the internal weights matrix.

Returns:
the internal weight matrix.

getFFWeights1d

public double[] getFFWeights1d()
Get a 1d representation of the weights in this FFNeuralNetwork. The weights are serialized into a 1D array from the 3d ffWeights array by iterating over each neuron in each layer and adding each weight in turn.

Returns:
a 1d array holding all of the weights in this network.

numInputs

public int numInputs()
Get the number of inputs that there are in this FFNeuralNetowrk.

Returns:
the number of inputs.

numOutputs

public int numOutputs()
Get the number of outputs that there are in this FFNeuralNetwork.

Returns:
the number of outputs.

getConnections

public boolean[][] getConnections()
This method throws an UnsupportedOperationException because the FFNeuralNetwork does not use the connections matrix in the underlying NeuralNetwork class.

Throws:
UnsupportedOperationException.

getWeights

public double[][] getWeights()
This method throws an UnsupportedOperationException because the FFNeuralNetwork does not rely on the weights in the underlying NeuralNetwork class.

Throws:
UnsupportedOperationException.

setInputs

public void setInputs(double[] inputs)
               throws IllegalArgumentException
Set the inputs to this FFNeuralNetwork. The inputs are immediately filtered and made ready for a call to the propagate method.

Overrides:
setInputs in class NeuralNetwork
Parameters:
inputs - the inputs to the network.
Throws:
IllegalArgumentException - if the number of inputs does not match the size of the input layer.

propagate

public void propagate()
               throws IllegalStateException
Propagate the current filtered input values through the network. A call to this method causes the raw network outputs to be computed. Those raw outputs are then also filtered using the output filters to compute the filtered outputs.

Specified by:
propagate in class NeuralNetwork
Throws:
IllegalStateException - if this method is called before the inputs have been set by a call to setInputs.

getLayerInputs

public double[][] getLayerInputs()
Get the inputs to the input, each hidden and output layers of neurons for this FFNeuralNetwork. These inputs are reset by each call to propagate.

Returns:
The array that is returned has one row for each layer of neurons and each entry in the row corresponds to a neuron in that layer.

getLayerOutputs

public double[][] getLayerOutputs()
Get the outputs of the input, each hidden and output layers of neurons for this FFNeuralNetwork. These outputs are reset by each call to propagate.

Returns:
The array that is returned has one row for each layer of neurons and each entry in the row corresponds to a neuron in that layer.

read

public static Object read(String filename)
                   throws SerializationError
Read and return the FFNeuralNetwork contained in the specified filename using Java's object serialization mechanism. It is the caller's responsibility to cast the returned object to the correct type.

Parameters:
filename - the full path of the file from which to read the object.
Returns:
the object read from the specified file.
Throws:
SerializationError - if there is a problem reading the object.

dLife Home Page