gov.sandia.cognition.learning.function.vector
Class FeedforwardNeuralNetwork

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.vector.FeedforwardNeuralNetwork
All Implemented Interfaces:
Evaluator<Vector,Vector>, VectorFunction, Vectorizable, VectorizableVectorFunction, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
DifferentiableFeedforwardNeuralNetwork

public class FeedforwardNeuralNetwork
extends AbstractCloneableSerializable
implements VectorizableVectorFunction

A feedforward neural network that can have an arbitrary number of layers, and an arbitrary squashing (activation) function assigned to each layer. The squashing functions need not be differentiable! To use a neural net with backprop (GradientDescent), then use DifferentiableFeedforwardNeuralNetwork

Since:
1.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
FeedforwardNeuralNetwork(ArrayList<? extends GeneralizedLinearModel> layers)
          Creates a new instance of FeedforwardNeuralNetwork
FeedforwardNeuralNetwork(ArrayList<Integer> nodesPerLayer, ArrayList<? extends UnivariateScalarFunction> layerActivationFunctions)
          Creates a new instance of FeedforwardNeuralNetwork
FeedforwardNeuralNetwork(int numInputs, int numHiddens, int numOutputs, UnivariateScalarFunction activationFunction)
          Creates a new instance of FeedforwardNeuralNetwork
 
Method Summary
 FeedforwardNeuralNetwork clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector convertToVector()
          Converts the object to a vector.
 Vector evaluate(Vector input)
          Evaluates the function on the given input and returns the output.
protected  ArrayList<Vector> evaluateAtEachLayer(Vector input)
          Returns the activations that occured at each layer
 ArrayList<? extends GeneralizedLinearModel> getLayers()
          Getter for layers
 void setLayers(ArrayList<? extends GeneralizedLinearModel> layers)
          Setter for layers
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FeedforwardNeuralNetwork

public FeedforwardNeuralNetwork(ArrayList<Integer> nodesPerLayer,
                                ArrayList<? extends UnivariateScalarFunction> layerActivationFunctions)
Creates a new instance of FeedforwardNeuralNetwork

Parameters:
nodesPerLayer - Number of nodes in each layer, must have no fewer than 2 layers
layerActivationFunctions - Squashing function to assign to each layer, must have one fewer squashing function than you do layers (that is, the input layer has no squashing)

FeedforwardNeuralNetwork

public FeedforwardNeuralNetwork(int numInputs,
                                int numHiddens,
                                int numOutputs,
                                UnivariateScalarFunction activationFunction)
Creates a new instance of FeedforwardNeuralNetwork

Parameters:
numInputs - Number of nodes in the input layer
numHiddens - Number of nodes in the hidden (middle) layer
numOutputs - Number of nodes in the output layer
activationFunction - Squashing function to assign to all layers

FeedforwardNeuralNetwork

public FeedforwardNeuralNetwork(ArrayList<? extends GeneralizedLinearModel> layers)
Creates a new instance of FeedforwardNeuralNetwork

Parameters:
layers - Layers that comprise this neural network
Method Detail

clone

public FeedforwardNeuralNetwork clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface Vectorizable
Specified by:
clone in interface VectorizableVectorFunction
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

convertToVector

public Vector convertToVector()
Description copied from interface: Vectorizable
Converts the object to a vector.

Specified by:
convertToVector in interface Vectorizable
Returns:
The Vector form of the object.

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Vectorizable
Converts the object from a Vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameters to incorporate.

evaluate

public Vector evaluate(Vector input)
Description copied from interface: Evaluator
Evaluates the function on the given input and returns the output.

Specified by:
evaluate in interface Evaluator<Vector,Vector>
Parameters:
input - The input to evaluate.
Returns:
The output produced by evaluating the input.

evaluateAtEachLayer

protected ArrayList<Vector> evaluateAtEachLayer(Vector input)
Returns the activations that occured at each layer

Parameters:
input - Input to evaluate
Returns:
activations at each layer, where get(0) is the input layer and get(n) is the output layer

getLayers

public ArrayList<? extends GeneralizedLinearModel> getLayers()
Getter for layers

Returns:
Layers that comprise this neural network

setLayers

public void setLayers(ArrayList<? extends GeneralizedLinearModel> layers)
Setter for layers

Parameters:
layers - Layers that comprise this neural network

toString

public String toString()
Overrides:
toString in class Object