Neural Network Toolbox Previous page   Next Page

Learning Functions

You can create four kinds of initialization functions: training, adaption, performance, and weight/bias learning.

Training Functions

One kind of general learning function is a network training function. Training functions repeatedly apply a set of input vectors to a network, updating the network each time, until some stopping criterion is met. Stopping criteria can consist of a maximum number of epochs, a minimum error gradient, an error goal, etc.

Once defined, you can assign your training function to a network.

Your network initialization function is used whenever you train your network.

To be a valid training function your function must take and return a network,

where:

The dimensions above have the following definitions:

Your training function must also provide information about itself using this calling format,

where the correct information is returned for each of the following string codes:

When you set the network training function (net.trainFcn) to be your function, the network's training parameters (net.trainParam) automatically are set to your default structure. Those values can be altered (or not) before training.

Your function can update the network's weight and bias values in any way you see fit. However, you should be careful not to alter any other properties, or to set the weight matrices and bias vectors to the wrong size. For performance reasons, train turns off the normal type checking for network properties before calling your training function. So if you set a weight matrix to the wrong size, it won't immediately generate an error, but will cause problems later when you try to simulate or adapt the network.

If you are interested in creating your own training function, you can examine the implementations of toolbox functions such as trainc and trainr. The help for each of these utility functions lists the input and output arguments they take.

Utility Functions.   If you examine training functions such as trainc, traingd, and trainlm, note that they use a set of utility functions found in the nnet/nnutils directory.

These functions are not listed in Reference because they may be altered in the future. However, you can use these functions if you are willing to take the risk that you might have to update your functions for future versions of the toolbox. Use help on each function to view the function's input and output arguments.

These two functions are useful for creating a new training record and truncating it once the final number of epochs is known:

These three functions calculate network signals going forward, errors, and derivatives of performance coming back:

These two functions get and set a network's weight and bias values with single vectors. Being able to treat all these adjustable parameters as a single vector is often useful for implementing optimization algorithms:

These next three functions are also useful for implementing optimization functions. One calculates all network signals going forward, including errors and performance. One backpropagates to find the derivatives of performance as a single vector. The third function backpropagates to find the Jacobian of performance. This latter function is used by advanced optimization techniques like Levenberg-Marquardt:

Adapt Functions

The other kind of the general learning function is a network adapt function. Adapt functions simulate a network, while updating the network for each time step of the input before continuing the simulation to the next input.

Once defined, you can assign your adapt function to a network.

Your network initialization function is used whenever you adapt your network.

To be a valid adapt function, it must take and return a network,

where:

The dimensions above have the following definitions:

Your adapt function must also provide information about itself using this calling format,

where the correct information is returned for each of the following string codes:

When you set the network adapt function (net.adaptFcn) to be your function, the network's adapt parameters (net.adaptParam) automatically are set to your default structure. Those values can then be altered (or not) before adapting.

Your function can update the network's weight and bias values in any way you see fit. However, you should be careful not to alter any other properties, or to set the weight matrices and bias vectors of the wrong size. For performance reasons, adapt turns off the normal type checking for network properties before calling your adapt function. So if you set a weight matrix to the wrong size, it won't immediately generate an error, but will cause problems later when you try to simulate or train the network.

If you are interested in creating your own training function, you can examine the implementation of a toolbox function such as trains.

Utility Functions.   If you examine the toolbox's only adapt function trains, note that it uses a set of utility functions found in the nnet/nnutils directory. The help for each of these utility functions lists the input and output arguments they take.

These functions are not listed in Reference because they may be altered in the future. However, you can use these functions if you are willing to take the risk that you will have to update your functions for future versions of the toolbox.

These two functions are useful for simulating a network, and calculating its derivatives of performance:

Performance Functions

Performance functions allow a network's behavior to be graded. This is useful for many algorithms, such as backpropagation, which operate by adjusting network weights and biases to improve performance.

Once defined you can assign your training function to a network.

Your network initialization function will then be used whenever you train your adapt your network.

To be a valid performance function your function must be called as follows,

where:

If E is a cell array you can convert it to a matrix as follows.

Alternatively, your function must also be able to be called as follows,

where you can get X and PP (if needed) as follows.

Your performance function must also provide information about itself using this calling format,

where the correct information is returned for each of the following string codes:

When you set the network performance function (net.performFcn) to be your function, the network's adapt parameters (net.performParam) are automatically set to your default structure. Those values can then be altered or not before training or adaption.

To see how an example custom performance function works type in these lines of code.

Use this command to see how mypf was implemented.

You can use mypf as a template to create your own weight and bias initialization function.

Performance Derivative Functions.   If you want to use backpropagation with your performance function, you need to create a custom derivative function for it. It needs to calculate the derivative of the network's errors and combined weight and bias vector, with respect to performance,

where:

To see how the example custom performance derivative function mydpf works, type

Use this command to see how mydpf was implemented.

You can use mydpf as a template to create your own performance derivative functions.

Weight and Bias Learning Functions

The most specific kind of learning function is a weight and bias learning function. These functions are used to update individual weights and biases during learning with some training and adapt functions.

Once defined. you can assign your learning function to any weight and bias in a network. For example, the following lines of code assign the weight and bias learning function yourwblf to the second layer's bias, and the weight coming from the first input to the second layer.

Weight and bias learning functions are only called to update weights and biases if the network training function (net.trainFcn) is set to trainb, trainc, or trainr, or if the network adapt function (net.adaptFcn) is set to trains. If this is the case, then your function is used to update the weight and biases it is assigned to whenever you train or adapt your network with train or adapt.

To be a valid weight and bias learning function, it must be callable as follows,

where:

Your function is called as follows to update bias vector

where:

Your learning function must also provide information about itself using this calling format,

where the correct information is returned for each of the following string codes:

To see how an example custom weight and bias initialization function works, type

Use this command to see how mywbif was implemented.

You can use mywblf as a template to create your own weight and bias learning function.


Previous page  Initialization Functions Self-Organizing Map Functions Next page

© 1994-2005 The MathWorks, Inc.