You are on page 1of 3

Train neural network

Syntax
[net,tr] = train(net,P,T,Pi,Ai)

To Get Help
Type help network/train.

Description
train

trains a network net according to net.trainFcn and net.trainParam. takes

[net,tr] = train(net,P,T,Pi,Ai) net P T Pi Ai

Network Network inputs Network targets (default = zeros) Initial input delay conditions (default = zeros) Initial layer delay conditions (default = zeros)

and returns
net tr

New network Training record (epoch and perf)

Note that T is optional and need only be used for networks that require targets. Pi is also optional and need only be used for networks that have input or layer delays.
train's

signal arguments can have two formats: cell array or matrix.

The cell array format is easiest to describe. It is most convenient for networks with multiple inputs and outputs, and allows sequences of inputs to be presented.
P T Ni-by-TS Nl-by-TS

cell array Each element P{i,j,ts} is an Ni-by-Q matrix. cell array Each element T{i,ts} is a Ui-by-Q matrix. cell array Each element Pi{i,k} is an Ri-by-Q matrix. cell array Each element Ai{i,k} is an Si-by-Q matrix.

Pi Ni-by-ID Ai Nl-by-LD

where
Ni = net.numInputs Nl = net.numLayers ID = net.numInputDelays LD = net.numLayerDelays TS = Q =

Number of time steps Batch size

Ri = net.inputs{i}.size Si = net.layers{i}.size

The columns of Pi and Ai are ordered from the oldest delay condition to the most recent:
Pi{i,k} = Ai{i,k} =

Input i at time ts = k - ID Layer output i at time ts = k - LD

The matrix format can be used if only one time step is to be simulated (TS = 1). It is convenient for networks with only one input and output, but can be used with networks that have more. Each matrix argument is found by storing the elements of the corresponding cell array argument in a single matrix:
P T (sum of Ri)-by-Q (sum of Ui)-by-Q

matrix matrix matrix matrix

Pi (sum of Ri)-by-(ID*Q) Ai (sum of Si)-by-(LD*Q)

Examples
Here input P and targets T define a simple function that you can plot:
p = [0 1 2 3 4 5 6 7 8]; t = [0 0.84 0.91 0.14 -0.77 -0.96 -0.28 0.66 0.99]; plot(p,t,'o')

Here feedforwardnet creates a two-layer feed-forward network. The network has one hidden layer with ten neurons.
net = feedforwardnet(10); net = configure(net,p,t); y1 = net(p) plot(p,t,'o',p,y1,'x')

The network is trained and then resimulated.


net = train(net,p,t); y2 = net(p) plot(p,t,'o',p,y1,'x',p,y2,'*')

You might also like