The Encog Project

org.encog.neural.networks.training.propagation.gradient
Class CalculateGradient

java.lang.Object
  extended by org.encog.neural.networks.training.propagation.gradient.CalculateGradient

public class CalculateGradient
extends java.lang.Object

This class is used to calculate the gradients for each of the weights and thresholds values in a neural network. It is used by the propagation training methods. This class must visit every training set element. Multithreading is used to process every training set element, however it requires an indexable training set to run in multithreaded mode. Multithreaded mode allows the training method to run much faster on a multicore machine.


Constructor Summary
CalculateGradient(BasicNetwork network, NeuralDataSet training)
          Construct the object using a network and training set.
CalculateGradient(BasicNetwork network, NeuralDataSet training, int threads)
          Construct the object for multithreaded use.
 
Method Summary
 void calculate(double[] weights)
          Calculate the gradients based on the specified weights.
 NeuralDataPair createPair()
          Create a new neural data pair object of the correct size for the neural network that is being trained.
 int getCount()
           
 double getError()
           
 double[] getGradients()
           
 BasicNetwork getNetwork()
           
 double[] getWeights()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CalculateGradient

public CalculateGradient(BasicNetwork network,
                         NeuralDataSet training)
Construct the object using a network and training set. This constructor will use only a single thread.

Parameters:
network - The network to be used to calculate.
training - The training set to use.

CalculateGradient

public CalculateGradient(BasicNetwork network,
                         NeuralDataSet training,
                         int threads)
Construct the object for multithreaded use. The number of threads can be specified.

Parameters:
network - The network to use.
training - The training set to use.
threads - The number of threads. Specify one for single threaded. Specify zero to allow Encog to determine the best number of threads to use, based on how many processors this machine has.
Method Detail

calculate

public void calculate(double[] weights)
Calculate the gradients based on the specified weights.

Parameters:
weights - The weights to use.

createPair

public NeuralDataPair createPair()
Create a new neural data pair object of the correct size for the neural network that is being trained. This object will be passed to the getPair method to allow the neural data pair objects to be copied to it.

Returns:
A new neural data pair object.

getCount

public int getCount()
Returns:
The training set count.

getError

public double getError()
Returns:
The current overall error.

getGradients

public double[] getGradients()
Returns:
The gradients.

getNetwork

public BasicNetwork getNetwork()
Returns:
The network that is being trained.

getWeights

public double[] getWeights()
Returns:
The weights and thresholds from the network that is being trained.

The Encog Project