Main Content

traingd

Gradient descent backpropagation

Description

net.trainFcn = 'traingd'sets the networktrainFcnproperty.

[trainedNet,tr] = train(net,...)火车的network withtraingd.

traingdis a network training function that updates weight and bias values according to gradient descent.

Training occurs according totraingdtraining parameters, shown here with their default values:

  • net.trainParam.epochs— Maximum number of epochs to train. The default value is 1000.

  • net.trainParam.goal— Performance goal. The default value is 0.

  • net.trainParam.lr— Learning rate. The default value is 0.01.

  • net.trainParam.max_fail— Maximum validation failures. The default value is6.

  • net.trainParam.min_grad— Minimum performance gradient. The default value is1e-5.

  • net.trainParam.show— Epochs between displays (NaNfor no displays). The default value is 25.

  • net.trainParam.showCommandLine— Generate command-line output. The default value isfalse.

  • net.trainParam.showWindow— Show training GUI. The default value istrue.

  • net.trainParam.time— Maximum time to train in seconds. The default value isinf.

Input Arguments

collapse all

Input network, specified as a network object. To create a network object, use for example,feedforwardnetornarxnet.

Output Arguments

collapse all

Trained network, returned as anetworkobject.

Training record (epochandperf), returned as a structure whose fields depend on the network training function (net.NET.trainFcn). It can include fields such as:

  • Training, data division, and performance functions and parameters

  • Data division indices for training, validation and test sets

  • Data division masks for training validation and test sets

  • Number of epochs (num_epochs) and the best epoch (best_epoch).

  • A list of training state names (states).

  • Fields for each state name recording its value throughout training

  • Performances of the best network (best_perf,best_vperf,best_tperf)

More About

collapse all

Network Use

You can create a standard network that usestraingdwithfeedforwardnetorcascadeforwardnet. To prepare a custom network to be trained withtraingd,

  1. Setnet.trainFcnto'traingd'. This setsnet.trainParamtotraingd’s default parameters.

  2. Setnet.trainParamproperties to desired values.

In either case, callingtrainwith the resulting network trains the network withtraingd.

Seehelp feedforwardnetandhelp cascadeforwardnetfor examples.

Gradient Descent Backpropagation

Thebatch steepest descent training function istraingd. The weights and biases are updated in the direction of the negative gradient of the performance function. If you want to train a network using batch steepest descent, you should set the networktrainFcntotraingd, and then call the functiontrain. There is only one training function associated with a given network.

There are seven training parameters associated withtraingd:

  • epochs

  • show

  • goal

  • time

  • min_grad

  • max_fail

  • lr

The learning ratelris multiplied times the negative of the gradient to determine the changes to the weights and biases. The larger the learning rate, the bigger the step. If the learning rate is made too large, the algorithm becomes unstable. If the learning rate is set too small, the algorithm takes a long time to converge. See page 12-8 of [HDB96] for a discussion of the choice of learning rate.

The training status is displayed for everyshowiterations of the algorithm. (Ifshowis set toNaN,然后训练状态不显示。)The other parameters determine when the training stops. The training stops if the number of iterations exceedsepochs, if the performance function drops belowgoal, if the magnitude of the gradient is less thanmingrad, or if the training time is longer thantimeseconds.max_fail, which is associated with the early stopping technique, is discussed inImproving Generalization.

The following code creates a training set of inputspand targetst. For batch training, all the input vectors are placed in one matrix.

p = [-1 -1 2 2; 0 5 0 5]; t = [-1 -1 1 1];

Create the feedforward network.

net = feedforwardnet(3,'traingd');

In this simple example, turn off a feature that is introduced later.

net.divideFcn = '';

At this point, you might want to modify some of the default training parameters.

net.trainParam.show = 50; net.trainParam.lr = 0.05; net.trainParam.epochs = 300; net.trainParam.goal = 1e-5;

If you want to use the default training parameters, the preceding commands are not necessary.

Now you are ready to train the network.

[net,tr] = train(net,p,t);

The training recordtrcontains information about the progress of training.

Now you can simulate the trained network to obtain its response to the inputs in the training set.

a = net(p) a = -1.0026 -0.9962 1.0010 0.9960

Try theNeural Network Designdemonstrationnnd12sd1[HDB96] for an illustration of the performance of the batch gradient descent algorithm.

Algorithms

traingdcan train any network as long as its weight, net input, and transfer functions have derivative functions.

Backpropagation is used to calculate derivatives of performanceperfwith respect to the weight and bias variablesX. Each variable is adjusted according to gradient descent:

dX = lr * dperf/dX

Training stops when any of these conditions occurs:

  • The maximum number ofepochs(repetitions) is reached.

  • The maximum amount oftimeis exceeded.

  • Performance is minimized to thegoal.

  • The performance gradient falls belowmin_grad.

  • Validation performance has increased more thanmax_failtimes since the last time it decreased (when using validation).

Introduced before R2006a