Neural Network Toolbox | Search  Help Desk |
sim | Examples See Also |
[Y,Pf,Af] = sim(net,P,Pi,Ai)
[Y,Pf,Af] = sim(net,{Q TS},Pi,Ai)
[Y,Pf,Af] = sim(net,Q,Pi,Ai)
Type help network/sim
sim
simulates neural networks.
[Y,Pf,Af]
= sim(net,P,Pi,Ai)
takes,
Pi -
Initial input delay conditions, default = zeros.
Ai -
Initial layer delay conditions, default = zeros.
Pi
, Ai
, Pf
, and Af
are optional and need only be used for networks that have input or layer delays.
sim
'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
x TS
cell array, each element P{i,ts}
is an Ri
x Q
matrix.
Pi - Ni
x ID
cell array, each element Pi{i,k}
is an Ri
x Q
matrix.
Ai - Nl
x LD
cell array, each element Ai{i,k}
is an Si
x Q
matrix.
Y - NO
x TS
cell array, each element Y{i,ts}
is a Ui
x Q
matrix.
Pf - Ni
x ID
cell array, each element Pf{i,k}
is an Ri
x Q
matrix.
Af - Nl
x LD
cell array, each element Af{i,k}
is an Si
x Q
matrix.
Ui =
net.outputs{i}.size
Pi
, Ai
, Pf
, 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
.
(TS = 1)
. It is convenient for networks with only one input and output, but can also be used with networks that have more.
Each matrix argument is found by storing the elements of the corresponding cell array argument into a single matrix:
Pi - (sum of Ri)
x (ID*Q)
matrix.
Ai - (sum of Si)
x (LD*Q)
matrix.
Pf - (sum of Ri)
x (ID*Q)
matrix.
Af - (sum of Si)
x (LD*Q)
matrix.
[Y,Pf,Af]
= sim(net,{Q TS},Pi,Ai)
is used for networks which do not have an input, such as Hopfield networks, when cell array notation is used.
[Y,Pf,Af]
= sim(net,Q,Pi,Ai)
is used for networks which do not have an input, such as Hopfield networks, when matrix notation is used.
Here newp is used to create a perceptron layer with a 2-element input (with ranges of [0 1]
), and a single neuron.
net = newp([0 1;0 1],1);Here the perceptron is simulated for an individual vector, a batch of 3 vectors, and a sequence of 3 vectors.
p1 = [.2; .9]; a1 = sim(net,p1) p2 = [.2 .5 .1; .9 .3 .7]; a2 = sim(net,p2) p3 = {[.2; .9] [.5; .3] [.1; .7]}; a3 = sim(net,p3)Here newlin
d
is used to create a linear layer with a 3-element input, 2 neurons.
net = newlin([0 2;0 2;0 2],2,[0 1]);Here the linear layer is simulated with a sequence of 2 input vectors using the default initial input delay conditions (all zeros).
p1 = {[2; 0.5; 1] [1; 1.2; 0.1]}; [y1,pf] = sim(net,p1)Here the layer is simulated for 3 more vectors using the previous final input delay conditions as the new initial delay conditions.
p2 = {[0.5; 0.6; 1.8] [1.3; 1.6; 1.1] [0.2; 0.1; 0]}; [y2,pf] = sim(net,p2,pf)Here newelm is used to create an Elman network with a 1-element input, and a layer 1 with 3 tansig neurons followed by a layer 2 with 2 purelin neurons. Because it is an Elman network it has a tap delay line with a delay of 1 going from layer 1 to layer 1.
net = newelm([0 1],[3 2],{'tansig','purelin'});Here the Elman network is simulated for a sequence of 3 values using default initial delay conditions.
p1 = {0.2 0.7 0.1}; [y1,pf,af] = sim(net,p1)Here the network is simulated for 4 more values, using the previous final delay conditions as the new initial delay conditions.
p2 = {0.1 0.9 0.8 0.4}; [y2,pf,af] = sim(net,p2,pf,af)
sim
uses these properties to simulate a network net
.
net.numInputs, net.numLayers net.outputConnect, net.biasConnect net.inputConnect, net.layerConnectThese properties determine the network's weight and bias values, and the number of delays associated with each weight:
net.inputWeights{i,j}.value net.layerWeights{i,j}.value net.layers{i}.value net.inputWeights{i,j}.delays net.layerWeights{i,j}.delaysThese function properties indicate how
sim
applies weight and bias values to inputs to get each layer's output:
net.inputWeights{i,j}.weightFcn net.layerWeights{i,j}.weightFcn net.layers{i}.netInputFcn net.layers{i}.transferFcnSee Chapter 2 for more information on network simulation.
init
,
adapt
,
train