@PublicationReference(author="Wikipedia", title="Multilayer perceptron", type=WebPage, year=2009, url="http://en.wikipedia.org/wiki/Multilayer_perceptron") public class ThreeLayerFeedforwardNeuralNetwork extends AbstractRandomized implements VectorizableVectorFunction, VectorInputEvaluator<Vector,Vector>, VectorOutputEvaluator<Vector,Vector>, GradientDescendable
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_INITIALIZATION_RANGE
Default initialization range, 0.001.
|
static int |
DEFAULT_RANDOM_SEED
Default random seed, 1.
|
static DifferentiableUnivariateScalarFunction |
DEFAULT_SQUASHING_FUNCTION
Default squashing function, AtanFunction.
|
protected Vector |
hiddenToOutputBiasWeights
Bias weights to add to each of the output units.
|
protected Matrix |
hiddenToOutputWeights
Matrix of weights to pre-multiply the hidden-unit activations by.
|
protected Vector |
inputToHiddenBiasWeights
Bias weights to add to each of the hidden units.
|
protected Matrix |
inputToHiddenWeights
Matrix of weights to pre-multiply the inputs by.
|
random
Constructor and Description |
---|
ThreeLayerFeedforwardNeuralNetwork()
Creates a new instance of ThreeLayerFeedforwardNeuralNetwork
|
ThreeLayerFeedforwardNeuralNetwork(int numInputs,
int numHidden,
int numOutputs)
Creates a new instance of ThreeLayerFeedforwardNeuralNetwork
|
ThreeLayerFeedforwardNeuralNetwork(int numInputs,
int numHidden,
int numOutputs,
DifferentiableUnivariateScalarFunction squashingFunction)
Creates a new instance of ThreeLayerFeedforwardNeuralNetwork
|
ThreeLayerFeedforwardNeuralNetwork(int numInputs,
int numHidden,
int numOutputs,
DifferentiableUnivariateScalarFunction squashingFunction,
int randomSeed,
double initializationRange)
Creates a new instance of ThreeLayerFeedforwardNeuralNetwork
|
Modifier and Type | Method and Description |
---|---|
ThreeLayerFeedforwardNeuralNetwork |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
Matrix |
computeParameterGradient(Vector input)
Computes the derivative of the function about the input with respect
to the parameters of the function.
|
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 Vector |
evaluateHiddenLayerActivation(Vector input)
Computes the raw (unsquashed) activation at the hidden layer for the
given input.
|
protected Vector |
evaluateOutputFromSquashedHiddenLayerActivation(Vector squashedHiddenActivation)
Evaluates the output from the squashed hidden-layer activation.
|
protected Vector |
evaluateSquashedHiddenLayerActivation(Vector hiddenActivation)
Evaluates the squashed hidden-layer activation from its raw activation
value.
|
int |
getHiddenDimensionality()
Gets the number of hidden units, not including the bias term.
|
double |
getInitializationRange()
Getter for initializationRange
|
int |
getInputDimensionality()
Gets the expected dimensionality of the input vector to the evaluator,
if it is known.
|
int |
getNumParameters()
Gets the total number of parameters in the neural net, including
the bias weights.
|
int |
getOutputDimensionality()
Gets the expected dimensionality of the output vector of the evaluator,
if it is known.
|
DifferentiableUnivariateScalarFunction |
getSquashingFunction()
Getter for squashingFunction
|
void |
initializeWeights(int inputDimensionality,
int hiddenDimensionality,
int outputDimensionality)
Initializes the neural net parameters for the given dimensions, not
including the bias terms, using the object's random-number generator
uniformly between the initialization range (and its negative value).
|
void |
reinitializeWeights()
Reinitializes the neural network parameters based on its current setup.
|
void |
setHiddenDimensionality(int hiddenDimensionality)
Sets the number of hidden units, not including the bias term, by
re-initializing the neural net's weights.
|
void |
setInitializationRange(double initializationRange)
Setter for initializationRange
|
void |
setInputDimensionality(int inputDimensionality)
Sets the number of input units, not counting the bias term,
by re-initializing the neural net's parameters.
|
void |
setOutputDimensionality(int outputDimensionality)
Sets the output dimensionality of the neural net by re-initializing the
weights.
|
void |
setSquashingFunction(DifferentiableUnivariateScalarFunction squashingFunction)
Setter for squashingFunction
|
getRandom, setRandom
public static final double DEFAULT_INITIALIZATION_RANGE
public static final DifferentiableUnivariateScalarFunction DEFAULT_SQUASHING_FUNCTION
public static final int DEFAULT_RANDOM_SEED
protected Matrix inputToHiddenWeights
protected Vector inputToHiddenBiasWeights
protected Matrix hiddenToOutputWeights
protected Vector hiddenToOutputBiasWeights
public ThreeLayerFeedforwardNeuralNetwork()
public ThreeLayerFeedforwardNeuralNetwork(int numInputs, int numHidden, int numOutputs)
numInputs
- Input dimensionality, not including the bias term,
must be greater than zero.numHidden
- Number of hidden units, not including the bias term,
must be greater than zero.numOutputs
- Output dimensionality, must be greater than zero.public ThreeLayerFeedforwardNeuralNetwork(int numInputs, int numHidden, int numOutputs, DifferentiableUnivariateScalarFunction squashingFunction)
numInputs
- Input dimensionality, not including the bias term,
must be greater than zero.numHidden
- Number of hidden units, not including the bias term,
must be greater than zero.numOutputs
- Output dimensionality, must be greater than zero.squashingFunction
- Function to apply at the hidden layer.public ThreeLayerFeedforwardNeuralNetwork(int numInputs, int numHidden, int numOutputs, DifferentiableUnivariateScalarFunction squashingFunction, int randomSeed, double initializationRange)
numInputs
- Input dimensionality, not including the bias term,
must be greater than zero.numHidden
- Number of hidden units, not including the bias term,
must be greater than zero.numOutputs
- Output dimensionality, must be greater than zero.squashingFunction
- Function to apply at the hidden layer.randomSeed
- Value to use as the random seed for the random-number generator.initializationRange
- Range of values to initialize the weights between, must be greater than
or equal to zero.public ThreeLayerFeedforwardNeuralNetwork clone()
AbstractCloneableSerializable
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.clone
in interface GradientDescendable
clone
in interface Vectorizable
clone
in interface VectorizableVectorFunction
clone
in interface CloneableSerializable
clone
in class AbstractRandomized
public Matrix computeParameterGradient(Vector input)
GradientDescendable
computeParameterGradient
in interface GradientDescendable
computeParameterGradient
in interface ParameterGradientEvaluator<Vector,Vector,Matrix>
input
- Point about which to differentiate w.r.t. the parameters.public Vector convertToVector()
Vectorizable
convertToVector
in interface Vectorizable
public int getNumParameters()
public void convertFromVector(Vector parameters)
Vectorizable
convertFromVector
in interface Vectorizable
parameters
- The parameters to incorporate.public Vector evaluate(Vector input)
Evaluator
protected Vector evaluateHiddenLayerActivation(Vector input)
input
- Input to compute the raw hidden activation of.protected Vector evaluateSquashedHiddenLayerActivation(Vector hiddenActivation)
hiddenActivation
- Raw (unsquashed) hidden activation values.protected Vector evaluateOutputFromSquashedHiddenLayerActivation(Vector squashedHiddenActivation)
squashedHiddenActivation
- Squashed hidden-layer activation.public void reinitializeWeights()
public void initializeWeights(int inputDimensionality, int hiddenDimensionality, int outputDimensionality)
inputDimensionality
- Number of the inputs, not including the bias term,
must be greater than zero.hiddenDimensionality
- Number of the hidden units, not including the bias term,
must be greater than zero.outputDimensionality
- Number of the outputs, must be greater than zero.public int getOutputDimensionality()
VectorOutputEvaluator
getOutputDimensionality
in interface VectorOutputEvaluator<Vector,Vector>
public void setOutputDimensionality(int outputDimensionality)
outputDimensionality
- Desired output dimensionality, must be greater than zero.public int getHiddenDimensionality()
public void setHiddenDimensionality(int hiddenDimensionality)
hiddenDimensionality
- Number of hidden units, must be greater than zero.public int getInputDimensionality()
VectorInputEvaluator
getInputDimensionality
in interface VectorInputEvaluator<Vector,Vector>
public void setInputDimensionality(int inputDimensionality)
inputDimensionality
- Desired input dimensionality, must be greater than zero.public DifferentiableUnivariateScalarFunction getSquashingFunction()
public void setSquashingFunction(DifferentiableUnivariateScalarFunction squashingFunction)
squashingFunction
- Squashing function to apply at the hidden layer.public double getInitializationRange()
public void setInitializationRange(double initializationRange)
initializationRange
- Range of values to initialize the weights between, must be greater than
or equal to zero.