Class EpochTrainer

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

public class EpochTrainer extends Object implements 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

    Constructors
    Constructor
    Description
    EpochTrainer(Trainer stage1Trainer)
    Creates a single stage EpochTrainer.
    EpochTrainer(Trainer stage1Trainer, Trainer stage2Trainer)
    Creates a two-stage EpochTrainer.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns 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.
    int
    Returns the training error status.
    double
    Returns the value of the error function.
    int
    Returns the number of epochs used during stage I training.
    int
    Gets the number of java.lang.Thread instances to use during stage I training.
    Returns the random number generator used to perturb the stage 1 guesses.
    protected com.imsl.datamining.neural.RandomSampleIndices
    Gets the random number generators used to select random training patterns in stage 1.
    protected Trainer
    Returns the stage 1 trainer.
    protected Trainer
    Returns the stage 1 trainer.
    protected int
    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 numberOfThreads)
    Sets the number of java.lang.Thread instances to be used for parallel processing.
    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 Details

    • 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 a two-stage EpochTrainer.
      Parameters:
      stage1Trainer - The stage I Trainer.
      stage2Trainer - The stage II Trainer, or null if 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 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.
    • setNumberOfThreads

      public void setNumberOfThreads(int numberOfThreads)
      Sets the number of java.lang.Thread instances to be used for parallel processing.
      Parameters:
      numberOfThreads - an int specifying the number of java.lang.Thread instances to be used for parallel processing.

      Default: numberOfThreads = 1.

    • getNumberOfThreads

      public int getNumberOfThreads()
      Gets the number of java.lang.Thread instances to use during stage I training.
      Returns:
      An int which contains the number of java.lang.Thread instances to use.
    • 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.

    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.