JMSLTM Numerical Library 4.0

com.imsl.datamining.neural
Class EpochTrainer

java.lang.Object
  extended bycom.imsl.datamining.neural.EpochTrainer
All Implemented Interfaces:
Serializable, Trainer

public class EpochTrainer
extends Object
implements Trainer, Serializable

Two-stage training using randomly selected training patterns in stage I. The epoch trainer, is a meta-trainer that combines two trainers. The first 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.

Stage II then refines the result found in stage 1. The best result from the stage 1 trainings is used as the initial guess with the second trainer operating on the full set of training patterns. Stage II is optional, if the second trainer is null then the best stage 1 result is returned as the epoch trainer's result.

The Java Logging API can be used to trace the performance training. The name of this logger is com.imsl.datamining.EpochTrainer. Accumulated levels of detail correspond to Java's FINE, FINER, and FINEST logging levels with FINE yielding the smallest amount of information and FINEST yielding the most. The levels of output yield the following:

LevelOutput
FINEA message on entering and exiting method train, a message entering and exiting both stages 1 and 2, and a summary report (based on Network.computeStatistics(double[][], double[][])) upon completion of training.
FINERAll of the messages in FINE, a message entering and exiting each epoch in stage 1, the input settings, the value of the function being minimized in stage 1 for each epoch, a time stamp at the start of each iteration in stage 1 and at the beginning and end of stage 2, and (if there is a stage 2) a summary at the end of stage 1.
FINESTAll of the messages in FINER and a table of the computed weights and their gradient values.

See Also:
Feed Forward Class Example 1, Level, Serialized Form

Constructor Summary
EpochTrainer(Trainer stage1Trainer)
          Creates a single stage EpochTrainer.
EpochTrainer(Trainer stage1Trainer, Trainer stage2Trainer)
          Creates an two-stage EpochTrainer.
 
Method Summary
 int getEpochSize()
          Returns the number of sample training patterns in each stage 1 epoch.
 double[] getErrorGradient()
          Returns the value of the gradient of the error function with respect to the weights.
 int getErrorStatus()
          Returns the training error status.
 double getErrorValue()
          Returns the value of the error function.
static Formatter getFormatter()
          Returns the logging Formatter object.
static Logger getLogger()
          Returns the Logger object.
 int getNumberOfEpochs()
          Returns the number of epochs used during stage I training.
 int getNumberOfThreads()
          Gets the number of threads to use during stage I training.
 Random getRandom()
          Returns the random number generator used to perturb the stage 1 guesses.
protected  com.imsl.datamining.neural.RandomSampleIndicies getRandomSampleIndicies()
          Gets the random number generators used to select random training patterns in stage 1.
protected  Trainer getStage1Trainer()
          Returns the stage 1 trainer.
protected  Trainer getStage2Trainer()
          Returns the stage 1 trainer.
protected  int incrementEpochCount()
          Increments the epoch counter.
 void setEpochSize(int epochSize)
          Sets the number of randomly selected training patterns in stage 1 epoch.
 void setNumberOfEpochs(int numberOfEpochs)
          Sets the number of epochs.
 void setNumberOfThreads(int number)
          Sets the number of threads to use during stage I training.
 void setRandom(Random random)
          Sets the random number generator used to perturb the initial stage 1 guesses.
 void setRandomSamples(Random randomA, Random randomB)
          Sets the random number generators used to select random training patterns in stage 1.
 void train(Network network, double[][] xData, double[][] yData)
          Trains the neural network using supplied training patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EpochTrainer

public EpochTrainer(Trainer stage1Trainer)
Creates a single stage EpochTrainer. Stage 2 training is bypassed.

Parameters:
stage1Trainer - The Trainer used in stage I.

EpochTrainer

public EpochTrainer(Trainer stage1Trainer,
                    Trainer stage2Trainer)
Creates an two-stage EpochTrainer.

Parameters:
stage1Trainer - The stage I Trainer.
stage2Trainer - The stage II Trainer, or null if stage II is to be bypassed.
Method Detail

getEpochSize

public int getEpochSize()
Returns the number of sample training patterns in each stage 1 epoch.

Returns:
An int which contains the number of sample training patterns in each stage I epoch.

getErrorGradient

public double[] getErrorGradient()
Returns the value of the gradient of the error function with respect to the weights.

Specified by:
getErrorGradient in interface Trainer
Returns:
A 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.

getErrorStatus

public int getErrorStatus()
Returns the training error status.

Specified by:
getErrorStatus in interface Trainer
Returns:
An int containing 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.

getErrorValue

public double getErrorValue()
Returns the value of the error function.

Specified by:
getErrorValue in interface Trainer
Returns:
A double containing final value of the error function from the last training. Before training, NaN is returned.

getFormatter

public static Formatter getFormatter()
Returns the logging Formatter object. Logger support requires JDK1.4. Use with earlier versions returns null .

The returned Formatter is used as input to Handler.setFormatter(java.util.logging.Formatter) to format the output log.

Returns:
The Formatter object, if present, or null otherwise.

getLogger

public static Logger getLogger()
Returns the Logger object. This is the Logger used to trace this class. It is named QuasiNewtonTrainer.

Returns:
The Logger object, if present, or null otherwise.

getNumberOfEpochs

public int getNumberOfEpochs()
Returns the number of epochs used during stage I training.

Returns:
An int which contains the number of epochs used during stage I training.

getNumberOfThreads

public int getNumberOfThreads()
Gets the number of threads to use during stage I training.

Returns:
An int which contains the number of threads to use.

getRandom

public Random getRandom()
Returns the random number generator used to perturb the stage 1 guesses.

Returns:
The Random object used to generate stage 1 perturbations.

getRandomSampleIndicies

protected com.imsl.datamining.neural.RandomSampleIndicies getRandomSampleIndicies()
Gets the random number generators used to select random training patterns in stage 1.

Returns:
A RandomSampleIndicies containing the random number generators.

getStage1Trainer

protected Trainer getStage1Trainer()
Returns the stage 1 trainer.

Returns:
A Trainer containing the stage 1 trainer.

getStage2Trainer

protected Trainer getStage2Trainer()
Returns the stage 1 trainer.

Returns:
A Trainer containing the stage 2 trainer.

incrementEpochCount

protected int incrementEpochCount()
Increments the epoch counter.


setEpochSize

public void setEpochSize(int epochSize)
Sets the number of randomly selected training patterns in stage 1 epoch.

Parameters:
epochSize - An int which specifies the number of sample training patterns in each stage I epoch. The default value is the number of observations in the training data.

setNumberOfEpochs

public void setNumberOfEpochs(int numberOfEpochs)
Sets the number of epochs.

Parameters:
numberOfEpochs - An int which specifies the number of epochs to be used during stage I training. The default value is 10.

setNumberOfThreads

public void setNumberOfThreads(int number)
Sets the number of threads to use during stage I training.

Parameters:
number - An int which specifies the number of threads to use. Default: number = 1.

setRandom

public void setRandom(Random random)
Sets the random number generator used to perturb the initial stage 1 guesses.

Parameters:
random - The Random object used to set the random number generator.

setRandomSamples

public void setRandomSamples(Random randomA,
                             Random randomB)
Sets the random number generators used to select random training patterns in stage 1. The two random number generators should be independent.

Parameters:
randomA - A Random object which is the first random number generator.
randomB - A Random object which is the second random number generator, independent of randomA.

train

public void train(Network network,
                  double[][] xData,
                  double[][] yData)
Trains the neural network using supplied training patterns.

Specified by:
train in interface Trainer
Parameters:
network - The Network to be trained.
xData - A double matrix specifying the input training patterns. The number of columns in xData must equal the number of Nodes in the InputLayer.
yData - A double containing the output training patterns. The number of columns in yData must equal the number of Perceptrons in the OutputLayer.

Each row of xData and yData contains a training pattern. These number of rows in two arrays must be equal.


JMSLTM Numerical Library 4.0

Copyright 1970-2006 Visual Numerics, Inc.
Built June 1 2006.