Class MultilayerPerceptron
java.lang.Object
smile.base.mlp.MultilayerPerceptron
- All Implemented Interfaces:
Serializable, AutoCloseable
Fully connected multilayer perceptron neural network.
An MLP consists of at least three layers of nodes: an input layer,
a hidden layer and an output layer. The nodes are interconnected
through weighted acyclic arcs from each preceding layer to the
following, without lateral or feedback connections. Each node
calculates a transformed weighted linear combination of its inputs
(output activations from the preceding layer), with one of the weights
acting as a trainable bias connected to a constant input. The
transformation, called activation function, is a bounded non-decreasing
(non-linear) function.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleThe gradient clipping norm.protected doubleThe gradient clipping value.protected doubleA small constant for numerical stability in RMSProp.protected doubleThe L2 regularization factor, which is also the weight decay factor.protected TimeFunctionThe learning rate.protected TimeFunctionThe momentum factor.protected Layer[]The input and hidden layers.protected OutputLayerThe output layer.protected intThe dimensionality of input data.protected doubleThe discounting factor for the history/coming gradient in RMSProp.protected intThe training iterations.protected ThreadLocal<Vector> The buffer to store desired target value of training instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbackpropagate(boolean update) Propagates the errors back through the network.voidclose()doubleReturns the gradient clipping norm.doubleReturns the gradient clipping value.doubleReturns the learning rate.doubleReturns the momentum factor.doubleReturns the weight decay factor.protected voidPropagates the signals through the neural network.voidsetClipNorm(double clipNorm) Sets the gradient clipping norm.voidsetClipValue(double clipValue) Sets the gradient clipping value.voidsetLearningRate(TimeFunction rate) Sets the learning rate.voidsetMomentum(TimeFunction momentum) Sets the momentum factor.voidsetParameters(Properties params) Sets MLP hyperparameters such as learning rate, weight decay, momentum, RMSProp, etc.voidsetRMSProp(double rho, double epsilon) Sets RMSProp parameters.voidsetWeightDecay(double lambda) Sets the weight decay factor.toString()protected voidupdate(int m) Updates the weights for mini-batch training.protected Vectorvector(double[] x) Wraps an array into vector.
-
Field Details
-
p
protected int pThe dimensionality of input data. -
output
The output layer. -
net
The input and hidden layers. -
target
The buffer to store desired target value of training instance. -
learningRate
The learning rate. -
momentum
The momentum factor. -
rho
protected double rhoThe discounting factor for the history/coming gradient in RMSProp. -
epsilon
protected double epsilonA small constant for numerical stability in RMSProp. -
lambda
protected double lambdaThe L2 regularization factor, which is also the weight decay factor. -
clipValue
protected double clipValueThe gradient clipping value. -
clipNorm
protected double clipNormThe gradient clipping norm. -
t
protected int tThe training iterations.
-
-
Constructor Details
-
MultilayerPerceptron
Constructor.- Parameters:
net- the input layer, hidden layers, and output layer in order.
-
-
Method Details
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
toString
-
setLearningRate
Sets the learning rate.- Parameters:
rate- the learning rate.
-
setMomentum
Sets the momentum factor. momentum = 0.0 means no momentum.- Parameters:
momentum- the momentum factor.
-
setRMSProp
public void setRMSProp(double rho, double epsilon) Sets RMSProp parameters.- Parameters:
rho- The discounting factor for the history/coming gradient.epsilon- A small constant for numerical stability.
-
setWeightDecay
public void setWeightDecay(double lambda) Sets the weight decay factor. After each weight update, every weight is simply "decayed" or shrunk according to w = w * (1 - 2 * eta * lambda).- Parameters:
lambda- the weight decay factor.
-
setClipValue
public void setClipValue(double clipValue) Sets the gradient clipping value. If clip value is set, the gradient of each weight is clipped to be no higher than this value.- Parameters:
clipValue- the gradient clipping value.
-
setClipNorm
public void setClipNorm(double clipNorm) Sets the gradient clipping norm. If clip norm is set, the gradient of each weight is individually clipped so that its norm is no higher than this value.- Parameters:
clipNorm- the gradient clipping norm.
-
getLearningRate
public double getLearningRate()Returns the learning rate.- Returns:
- the learning rate.
-
getMomentum
public double getMomentum()Returns the momentum factor.- Returns:
- the momentum factor.
-
getWeightDecay
public double getWeightDecay()Returns the weight decay factor.- Returns:
- the weight decay factor.
-
getClipValue
public double getClipValue()Returns the gradient clipping value.- Returns:
- the gradient clipping value.
-
getClipNorm
public double getClipNorm()Returns the gradient clipping norm.- Returns:
- the gradient clipping norm.
-
vector
Wraps an array into vector.- Parameters:
x- the input array.- Returns:
- the vector.
-
propagate
Propagates the signals through the neural network.- Parameters:
x- the input signal.training- true if this is in training pass.
-
backpropagate
protected void backpropagate(boolean update) Propagates the errors back through the network.- Parameters:
update- the flag if update the weights directly. It should be false for (mini-)batch.
-
update
protected void update(int m) Updates the weights for mini-batch training.- Parameters:
m- the mini-batch size.
-
setParameters
Sets MLP hyperparameters such as learning rate, weight decay, momentum, RMSProp, etc.- Parameters:
params- the MLP hyperparameters.
-