Documentation |
Adapt neural network to data as it is simulated
[net,Y,E,Pf,Af,tr] = adapt(net,P,T,Pi,Ai)
This function calculates network outputs and errors after each presentation of an input.
[net,Y,E,Pf,Af,tr] = adapt(net,P,T,Pi,Ai) takes
net | Network |
P | Network inputs |
T | Network targets (default = zeros) |
Pi | Initial input delay conditions (default = zeros) |
Ai | Initial layer delay conditions (default = zeros) |
and returns the following after applying the adapt function net.adaptFcn with the adaption parameters net.adaptParam:
net | Updated network |
Y | Network outputs |
E | Network errors |
Pf | Final input delay conditions |
Af | Final layer delay conditions |
tr | Training record (epoch and perf) |
Note that T is optional and is only needed for networks that require targets. Pi and Pf are also optional and only need to be used for networks that have input or layer delays.
adapt'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 | Ni-by-TS cell array | Each element P{i,ts} is an Ri-by-Q matrix. |
T | Nt-by-TS cell array | Each element T{i,ts} is a Vi-by-Q matrix. |
Pi | Ni-by-ID cell array | Each element Pi{i,k} is an Ri-by-Q matrix. |
Ai | Nl-by-LD cell array | Each element Ai{i,k} is an Si-by-Q matrix. |
Y | No-by-TS cell array | Each element Y{i,ts} is a Ui-by-Q matrix. |
E | No-by-TS cell array | Each element E{i,ts} is a Ui-by-Q matrix. |
Pf | Ni-by-ID cell array | Each element Pf{i,k} is an Ri-by-Q matrix. |
Af | Nl-by-LD cell array | Each element Af{i,k} is an Si-by-Q matrix. |
where
Ni | = | net.numInputs |
Nl | = | net.numLayers |
No | = | net.numOutputs |
ID | = | net.numInputDelays |
LD | = | net.numLayerDelays |
TS | = | Number of time steps |
Q | = | Batch size |
Ri | = | net.inputs{i}.size |
Si | = | net.layers{i}.size |
Ui | = | net.outputs{i}.size |
The columns of Pi, Pf, Ai, and Af are ordered from oldest delay condition to most recent:
Pi{i,k} | = | Input i at time ts = k - ID |
Pf{i,k} | = | Input i at time ts = TS + k - ID |
Ai{i,k} | = | Layer output i at time ts = k - LD |
Af{i,k} | = | Layer output i at time ts = 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 | (sum of Ri)-by-Q matrix |
T | (sum of Vi)-by-Q matrix |
Pi | (sum of Ri)-by-(ID*Q) matrix |
Ai | (sum of Si)-by-(LD*Q) matrix |
Y | (sum of Ui)-by-Q matrix |
E | (sum of Ui)-by-Q matrix |
Pf | (sum of Ri)-by-(ID*Q) matrix |
Af | (sum of Si)-by-(LD*Q) matrix |
Here two sequences of 12 steps (where T1 is known to depend on P1) are used to define the operation of a filter.
p1 = {-1 0 1 0 1 1 -1 0 -1 1 0 1}; t1 = {-1 -1 1 1 1 2 0 -1 -1 0 1 1};
Here linearlayer is used to create a layer with an input range of [-1 1], one neuron, input delays of 0 and 1, and a learning rate of 0.1. The linear layer is then simulated.
net = linearlayer([0 1],0.1);
Here the network adapts for one pass through the sequence.
The network's mean squared error is displayed. (Because this is the first call to adapt, the default Pi is used.)
[net,y,e,pf] = adapt(net,p1,t1); mse(e)
Note that the errors are quite large. Here the network adapts to another 12 time steps (using the previous Pf as the new initial delay conditions).
p2 = {1 -1 -1 1 1 -1 0 0 0 1 -1 -1}; t2 = {2 0 -2 0 2 0 -1 0 0 1 0 -1}; [net,y,e,pf] = adapt(net,p2,t2,pf); mse(e)
Here the network adapts for 100 passes through the entire sequence.
p3 = [p1 p2]; t3 = [t1 t2]; for i = 1:100 [net,y,e] = adapt(net,p3,t3); end mse(e)
The error after 100 passes through the sequence is very small. The network has adapted to the relationship between the input and target signals.