dLife Home Page

dlife.nn
Class NeuralNetwork

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

public abstract class NeuralNetwork
extends SerializationBase

Abstract base class that provides common functionality for a variety of neural networks. This includes setting up filters on the inputs and outputs as well as evaluating the performance of the network. Concrete subclasses of NeuralNetwork are expected to implement their own means of defining the type(s) of neurons that are used and also for handling any weights and/or connections.

When a NeuralNetwork is serialized its input and output filters are serialized. However, the current inputs and outputs of the network are transient and are not serialized with the network.

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

Field Summary
protected  double[] filteredInputs
           
protected  double[] filteredOutputs
           
protected  double[] rawInputs
           
protected  double[] rawOutputs
           
 
Constructor Summary
NeuralNetwork()
          Construct a new NeuralNetwork with no input or output filters.
 
Method Summary
 NNResults evaluate(NNDataSet data, double tolerance)
          Evaluate the performance of this NeuralNetwork on the provided NNDataSet.
 NNResults evaluate(NNDataSet data, double tolerance, boolean trace)
          Evaluate the performance of this NeuralNetwork on the provided NNDataSet.
 double[] getFilteredInputs()
          Get the values of the inputs of this NeuralNetowrk after all input filters have been applied.
 double[] getFilteredOutputs()
          Get the filtered output of this NeuralNetwork.
 NNDataFilter getInputFilter()
          Get the NNDataFilter that is to be applied to all inputs.
 NNDataFilter getInputFilter(int input)
          Get the NNDataFilter that is to be applied to the specified input.
 NNDataFilter getOutputFilter()
          Get the NNDataFilter that is to be applied to all outputs.
 NNDataFilter getOutputFilter(int output)
          Get the NNDataFilter that is to be applied to the specified output.
 double[] getRawInputs()
          Get the current raw values of the inputs to this NeuralNetowrk.
 double[] getRawOutputs()
          Get the raw outputs of this NeuralNetwork.
abstract  void propagate()
          Propagate the current (filtered) input values through this NeuralNetwork.
 void setInputFilter(NNDataFilter filter)
          Set the NNDataFilter that will be used for every input to this NeuralNetwork.
 void setInputFilter(NNDataFilter filter, int input)
          Set the NNDataFilter applied to a specific input of the NeuralNetwork.
 void setInputs(double[] inputs)
          Set the inputs of this NeuralNetwork to the specified values.
 void setOutputFilter(NNDataFilter filter)
          Set the NNDataFilter that will be used for every output of this NeuralNetwork.
 void setOutputFilter(NNDataFilter filter, int output)
          Set the NNDataFilter used by a specific output of the NeuralNetwork.
protected  void setOutputs(double[] outputs)
          Set the outputs of this NeuralNetwork.
 
Methods inherited from class dlife.sys.SerializationBase
read, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rawInputs

protected transient double[] rawInputs

filteredInputs

protected transient double[] filteredInputs

rawOutputs

protected transient double[] rawOutputs

filteredOutputs

protected transient double[] filteredOutputs
Constructor Detail

NeuralNetwork

public NeuralNetwork()
Construct a new NeuralNetwork with no input or output filters.

Method Detail

setInputFilter

public void setInputFilter(NNDataFilter filter)
Set the NNDataFilter that will be used for every input to this NeuralNetwork. NNDataFilters added to individual inputs using the addInputFilter(NNDataFilter, int) method will override the filter added with this method. If multiple filters are set, only the most recently set filter will be applied.

Parameters:
filter - the NNDataFilter to use or null to clear the filter.

setInputFilter

public void setInputFilter(NNDataFilter filter,
                           int input)
Set the NNDataFilter applied to a specific input of the NeuralNetwork. NNDataFilters set with this method override the NNDataFilter set for to all inputs. If multiple filters are set for the same input, only the most recently added filter will be applied.

Parameters:
filter - the NNDataFilter to use or null to clear the filter.
input - the input to which to assign the filter.

getInputFilter

public NNDataFilter getInputFilter()
Get the NNDataFilter that is to be applied to all inputs. Note that this filter may be overridden by filters applied to specific inputs.

Returns:
the NNDataFilter to be applied to all inputs or null if there is no filter.

getInputFilter

public NNDataFilter getInputFilter(int input)
Get the NNDataFilter that is to be applied to the specified input.

Parameters:
input - the input for which to get the filter.
Returns:
the NNDataFilter for the specified input or null if there is no filter for the specified input.

setOutputFilter

public void setOutputFilter(NNDataFilter filter)
Set the NNDataFilter that will be used for every output of this NeuralNetwork. NNDataFilters added to individual outputs using the addOutputFilter(NNDataFilter, int) method will override the filter added with this method. If multiple filters are set, only the most recently added filter will be applied.

Parameters:
filter - the NNDataFilter to use or null to clear the filter.

setOutputFilter

public void setOutputFilter(NNDataFilter filter,
                            int output)
Set the NNDataFilter used by a specific output of the NeuralNetwork. NNDataFilters set with this method override the NNDataFilter set for to all outputs. If multiple filters are set for the same output, only the most recently added filter will be applied.

Parameters:
filter - the NNDataFilter to use or null to clear the filter.
output - the output to which to assign the filter.

getOutputFilter

public NNDataFilter getOutputFilter()
Get the NNDataFilter that is to be applied to all outputs. Note that this filter may be overridden by filters applied to specific outputs.

Returns:
the NNDataFilter to be applied to all outputs or null if there is no filter.

getOutputFilter

public NNDataFilter getOutputFilter(int output)
Get the NNDataFilter that is to be applied to the specified output.

Parameters:
output - the output for which to get the filter.
Returns:
the NNDataFilter for the specified output or null if there is no filter for the specified output.

setInputs

public void setInputs(double[] inputs)
Set the inputs of this NeuralNetwork to the specified values. This method causes both the raw inputs and the filtered inputs to be set. If no input filter is set for a given input, then the filtered value of the input will be equal to the raw value of the input. Note that this method does not propagate the input values through the network. Call the propagate method after setting the inputs to propagate the values through the network and set the output values.

Parameters:
inputs - the inputs to the network.

getRawInputs

public double[] getRawInputs()
                      throws IllegalStateException
Get the current raw values of the inputs to this NeuralNetowrk. These are the values that were set by the most recent call to setInputs.

Returns:
the unfiltered input values.
Throws:
IllegalStateException - if the inputs have not been set.

getFilteredInputs

public double[] getFilteredInputs()
                           throws IllegalStateException
Get the values of the inputs of this NeuralNetowrk after all input filters have been applied. These are the values that were set by the most recent call to setInputs after they have been passed through all of the input filters.

Returns:
the filtered input values.
Throws:
IllegalStateException - if the inputs have not been set.

propagate

public abstract void propagate()
                        throws IllegalStateException
Propagate the current (filtered) input values through this NeuralNetwork. This method will typically be called following setInputs to propagate the new (filtered) inputs through the network. All concrete implementations of this method must end with a call to protected setOutputs method to ensure that both the raw outputs and the filtered outputs have been set.

Throws:
IllegalStateException - if the inputs have not been set.

setOutputs

protected void setOutputs(double[] outputs)
Set the outputs of this NeuralNetwork. Both the raw outputs and the filtered outputs are set.

Parameters:
outputs - the raw outputs for this network.

getRawOutputs

public double[] getRawOutputs()
                       throws IllegalStateException
Get the raw outputs of this NeuralNetwork. The raw outputs are the exact outputs generated by the most recent call to the propagate method, none of the output filters are applied. If the inputs have been changed by a call to set input, but propagate has not been called then this method will return stale output values.

Returns:
the raw outputs.
Throws:
IllegalStateException - if propagate has never been called.

getFilteredOutputs

public double[] getFilteredOutputs()
                            throws IllegalStateException
Get the filtered output of this NeuralNetwork. The filtered outputs are the outputs after all of the output filters have been applied to the network outputs resulting from the most recent call to propagate. If no filter has been set for a particular output then its value will be equal to the raw value of the output. If the inputs have been changed by a call to set input, but propagate has not been called then this method will return stale output values.

Returns:
the filtered outputs.
Throws:
IllegalStateException - if propagate has never been called.

evaluate

public NNResults evaluate(NNDataSet data,
                          double tolerance,
                          boolean trace)
                   throws IllegalArgumentException
Evaluate the performance of this NeuralNetwork on the provided NNDataSet. The performance is evaluated by presenting each input in the NNDataSet to the network, calling propagate, and comparing the filtered outputs of the network to the corresponding output in the NNDataSet. See the NNResults class for a description of the metrics that are computed by this method.

Parameters:
data - the NNDataSet to be used to evaluate this NeuralNetwork.
tolerance - a fraction of the desired output value within which an actual result is to be considered to be equal to the desired output. E.g. 0.1 means that any actual output within 10% of the specified correct output will be counted as a correct response.
trace - if true then a complete trace of the network outputs will be reported for each input in the NNDataSet.
Returns:
a NNResults object that summarizes the performance of this NeuralNetwork on the provided NNDataSet.
Throws:
IllegalArgumentException - if the provided NNDataSet is empty.

evaluate

public NNResults evaluate(NNDataSet data,
                          double tolerance)
Evaluate the performance of this NeuralNetwork on the provided NNDataSet. This method invokes the evaluates the three argument method with trace set to false.

Parameters:
data - the NNDataSet to be used to evaluate this NeuralNetwork.
tolerance - a fraction of the desired output value within which an actual result is to be considered to be equal to the desired output. E.g. 0.1 means that any actual output within 10% of the specified correct output will be counted as a correct response.
Returns:
a NNResults object that summarizes the performance of this NeuralNetwork on the provided NNDataSet.
Throws:
IllegalArgumentException - if the provided NNDataSet is empty.

dLife Home Page