Package com.imsl.datamining.neural
Class EpochTrainer
java.lang.Object
com.imsl.datamining.neural.EpochTrainer
- All Implemented Interfaces:
Trainer,Serializable
Performs two-stage training using randomly selected training patterns in stage I.
The
EpochTrainer is a meta-trainer that combines two trainers. The first or Stage I
trainer is used on a series of randomly selected subsets of the training
patterns. For each subset, the weights are initialized to their initial
values plus a random offset.
The best result from
Stage I training is used as the initial guess for the second or Stage II trainer.
The Stage II trainer uses the full set of training patterns. In EpochTrainer the second trainer
is optional. If the Stage II trainer is null then the best result from
Stage I is returned.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionEpochTrainer(Trainer stage1Trainer) Creates a single stageEpochTrainer.EpochTrainer(Trainer stage1Trainer, Trainer stage2Trainer) Creates a two-stageEpochTrainer. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of sample training patterns in each stage 1 epoch.double[]Returns the value of the gradient of the error function with respect to the weights.intReturns the training error status.doubleReturns the value of the error function.intReturns the number of epochs used during stage I training.intGets the number ofjava.lang.Threadinstances to use during stage I training.Returns the random number generator used to perturb the stage 1 guesses.protected com.imsl.datamining.neural.RandomSampleIndicesGets the random number generators used to select random training patterns in stage 1.protected TrainerReturns the stage 1 trainer.protected TrainerReturns the stage 1 trainer.protected intIncrements the epoch counter.voidsetEpochSize(int epochSize) Sets the number of randomly selected training patterns in stage 1 epoch.voidsetNumberOfEpochs(int numberOfEpochs) Sets the number of epochs.voidsetNumberOfThreads(int numberOfThreads) Sets the number ofjava.lang.Threadinstances to be used for parallel processing.voidSets the random number generator used to perturb the initial stage 1 guesses.voidsetRandomSamples(Random randomA, Random randomB) Sets the random number generators used to select random training patterns in stage 1.voidTrains the neural network using supplied training patterns.
-
Constructor Details
-
EpochTrainer
Creates a single stageEpochTrainer. Stage 2 training is bypassed.- Parameters:
stage1Trainer- TheTrainerused in stage I.
-
EpochTrainer
Creates a two-stageEpochTrainer.- Parameters:
stage1Trainer- The stage ITrainer.stage2Trainer- The stage IITrainer, ornullif stage II is to be bypassed.
-
-
Method Details
-
incrementEpochCount
protected int incrementEpochCount()Increments the epoch counter. -
getRandomSampleIndicies
protected com.imsl.datamining.neural.RandomSampleIndices getRandomSampleIndicies()Gets the random number generators used to select random training patterns in stage 1.- Returns:
- A
RandomSampleIndiciescontaining the random number generators.
-
getStage1Trainer
Returns the stage 1 trainer.- Returns:
- A
Trainercontaining the stage 1 trainer.
-
getStage2Trainer
Returns the stage 1 trainer.- Returns:
- A
Trainercontaining the stage 2 trainer.
-
setNumberOfThreads
public void setNumberOfThreads(int numberOfThreads) Sets the number ofjava.lang.Threadinstances to be used for parallel processing.- Parameters:
numberOfThreads- anintspecifying the number ofjava.lang.Threadinstances to be used for parallel processing.Default:
numberOfThreads= 1.
-
getNumberOfThreads
public int getNumberOfThreads()Gets the number ofjava.lang.Threadinstances to use during stage I training.- Returns:
- An
intwhich contains the number ofjava.lang.Threadinstances to use.
-
train
Trains the neural network using supplied training patterns.- Specified by:
trainin interfaceTrainer- Parameters:
network- TheNetworkto be trained.xData- Adoublematrix specifying the input training patterns. The number of columns inxDatamust equal the number ofNodes in theInputLayer.yData- Adoublecontaining the output training patterns. The number of columns inyDatamust equal the number ofPerceptrons in theOutputLayer.Each row of
xDataandyDatacontains a training pattern. These number of rows in two arrays must be equal.
-
getErrorValue
public double getErrorValue()Returns the value of the error function.- Specified by:
getErrorValuein interfaceTrainer- Returns:
- A
doublecontaining final value of the error function from the last training. Before training,NaNis returned.
-
getErrorStatus
public int getErrorStatus()Returns the training error status.- Specified by:
getErrorStatusin interfaceTrainer- Returns:
- An
intcontaining the error status from stage 2. If there is no stage 2 then the number of stage 1 epochs that returned a non-zero error status is returned.
-
getErrorGradient
public double[] getErrorGradient()Returns the value of the gradient of the error function with respect to the weights.- Specified by:
getErrorGradientin interfaceTrainer- Returns:
- A
doublearray whose length is equal to the number ofNetworkweights, containing the value of the gradient of the error function with respect to the weights. Before training,nullis returned.
-
getRandom
Returns the random number generator used to perturb the stage 1 guesses.- Returns:
- The
Randomobject used to generate stage 1 perturbations.
-
setRandom
Sets the random number generator used to perturb the initial stage 1 guesses.- Parameters:
random- TheRandomobject used to set the random number generator.
-
setRandomSamples
Sets the random number generators used to select random training patterns in stage 1. The two random number generators should be independent.- Parameters:
randomA- ARandomobject which is the first random number generator.randomB- ARandomobject which is the second random number generator, independent ofrandomA.
-
getNumberOfEpochs
public int getNumberOfEpochs()Returns the number of epochs used during stage I training.- Returns:
- An
intwhich contains the number of epochs used during stage I training.
-
setNumberOfEpochs
public void setNumberOfEpochs(int numberOfEpochs) Sets the number of epochs.- Parameters:
numberOfEpochs- Anintwhich specifies the number of epochs to be used during stage I training. The default value is 10.
-
getEpochSize
public int getEpochSize()Returns the number of sample training patterns in each stage 1 epoch.- Returns:
- An
intwhich contains the number of sample training patterns in each stage I epoch.
-
setEpochSize
public void setEpochSize(int epochSize) Sets the number of randomly selected training patterns in stage 1 epoch.- Parameters:
epochSize- Anintwhich specifies the number of sample training patterns in each stage I epoch. The default value is the number of observations in the training data.
-