public class LeastSquaresTrainer extends Object implements Trainer, Serializable
FeedForwardNetwork
using a Levenberg-Marquardt
algorithm for minimizing a sum of squares error.NonlinLeastSquares
,
Serialized FormConstructor and Description |
---|
LeastSquaresTrainer()
Creates a
LeastSquaresTrainer . |
Modifier and Type | Method and Description |
---|---|
protected Object |
clone()
Clones a copy of the trainer.
|
double[] |
getErrorGradient()
Returns the value of the gradient of the error function with
respect to the weights.
|
int |
getErrorStatus()
Returns the error status from the trainer.
|
double |
getErrorValue()
Returns the final value of the error function.
|
protected void |
setEpochNumber(int num)
Sets the epoch number for the trainer.
|
void |
setFalseConvergenceTolerance(double falseConvergenceTolerance)
Set the false convergence tolerance.
|
void |
setGradientTolerance(double gradientTolerance)
Set the gradient tolerance.
|
void |
setInitialTrustRegion(double initialTrustRegion)
Sets the intial trust region.
|
void |
setMaximumStepsize(double maximumStepsize)
Sets the maximum step size.
|
void |
setMaximumTrainingIterations(int maximumSolverIterations)
Sets the maximum number of iterations used by the nonlinear least
squares solver.
|
protected void |
setParallelMode(ArrayList[] allLogRecords)
Sets the trainer to be used in multi-threaded EpochTainer.
|
void |
setRelativeTolerance(double relativeTolerance)
Sets the relative tolerance.
|
void |
setStepTolerance(double stepTolerance)
Set the step tolerance used to step between weights.
|
void |
train(Network network,
double[][] xData,
double[][] yData)
Trains the neural network using supplied training patterns.
|
protected void setParallelMode(ArrayList[] allLogRecords)
allLogRecords
- An ArrayList
array containing the log
records.protected void setEpochNumber(int num)
num
- An int
array containing the epoch number.public void setMaximumStepsize(double maximumStepsize)
maximumStepsize
- A nonnegative double
value
specifying the maximum allowable stepsize in the
optimizer.
Default: \(10^3 || w ||_2\), where w are the values
of the weights in the network when training starts.NonlinLeastSquares.setMaximumStepsize(double)
public void setInitialTrustRegion(double initialTrustRegion)
initialTrustRegion
- A double
which specifies the
initial trust region radius. Default:
unlimited trust region.NonlinLeastSquares.setInitialTrustRegion(double)
public void setMaximumTrainingIterations(int maximumSolverIterations)
maximumSolverIterations
- An int
which specifies the
maximum number of iterations to be used
by the nonlinear least squares solver.
Its default value is 1000.NonlinLeastSquares.setRelativeTolerance(double)
public void setRelativeTolerance(double relativeTolerance)
relativeTolerance
- A double
which specifies the
relative error tolerance. It must be in the
interval [0,1]. Its default value is
1.0e-20.NonlinLeastSquares.setRelativeTolerance(double)
public void setFalseConvergenceTolerance(double falseConvergenceTolerance)
falseConvergenceTolerance
- a double
specifying the
false convergence tolerance.
Default: 1.0e-14.NonlinLeastSquares.setFalseConvergenceTolerance(double)
public void setGradientTolerance(double gradientTolerance)
gradientTolerance
- A double
specifying
the gradient tolerance. Default:
2.0e-5.MinUnconMultiVar.setGradientTolerance(double)
public void setStepTolerance(double stepTolerance)
stepTolerance
- A double
which specifies the scaled
step tolerance to use when changing the
weights. Default: 1.0e-5.NonlinLeastSquares.setStepTolerance(double)
public void train(Network network, double[][] xData, double[][] yData)
Each row of xData
and yData
contains a
training pattern. These number of rows in two arrays must be equal.
train
in interface Trainer
network
- The Network
to be trained.xData
- A double
matrix which contains the input
training patterns. The number of columns in xData
must equal the number of Node
s in
the InputLayer
.yData
- A double
matrix which contains the output
training patterns. The number of columns in yData
must equal the number of Perceptron
s
in the OutputLayer
.public double getErrorValue()
getErrorValue
in interface Trainer
double
containing the final value of the error
function from the last training. Before training, NaN
is returned.public double[] getErrorGradient()
getErrorGradient
in interface Trainer
double
array whose length is equal to the number
of network weights, containing the value of the
gradient of the error function with respect to the weights.
Before training, null
is returned.public int getErrorStatus()
getErrorStatus
in interface Trainer
int
which contains the error status. Zero
indicates that no errors were encountered during training.
Any non-zero value indicates that some error condition arose
during training.
In many cases the trainer is able to recover from these conditions and produce a well-trained network.
Value | Meaning |
0 | All convergence tests were met. |
1 | Scaled step tolerance was
satisfied. The current point may be an approximate local
solution, or the algorithm is making very slow progress
and is not near a solution, or StepTolerance
is too big. |
2 | Scaled actual and predicted
reductions in the function are less than or equal to the
relative function convergence tolerance
RelativeTolerance . |
3 | Iterates appear to be converging to a noncritical point. Incorrect gradient information, a discontinuous function, or stopping tolerances being too tight may be the cause. |
4 | Five consecutive steps with the maximum stepsize have been taken. Either the function is unbounded below, or has a finite asymptote in some direction, or the maximum stepsize is too small. |
5 | Too many iterations required |
Copyright © 2020 Rogue Wave Software. All rights reserved.