sim
(To be removed) Simulate neural network
sim will be removed in a future release. For more information,
see Transition Legacy Neural Network Code to dlnetwork Workflows.
For advice on updating your code, see Version History.
Syntax
[Y,Xf,Af] = sim(net,X,Xi,Ai,T)
[Y,Xf,Af] = sim(net,{Q TS},Xi,Ai)
[Y,...] = sim(net,...,'useParallel',...)
[Y,...]
= sim(net,...,'useGPU',...)
[Y,...] = sim(net,...,'showResources',...)
[Ycomposite,...] = sim(net,Xcomposite,...)
[Ygpu,...] = sim(net,Xgpu,...)
To Get Help
Type help network/sim.
Description
sim simulates neural networks.
[Y,Xf,Af] = sim(net,X,Xi,Ai,T) takes
net | Network |
X | Network inputs |
Xi | Initial input delay conditions (default = zeros) |
Ai | Initial layer delay conditions (default = zeros) |
T | Network targets (default = zeros) |
and returns
Y | Network outputs |
Xf | Final input delay conditions |
Af | Final layer delay conditions |
sim is usually called implicitly by calling the neural network as a
function. For instance, these two expressions return the same result:
y = sim(net,x,xi,ai) y = net(x,xi,ai)
Note that arguments Xi, Ai,
Xf, and Af are optional and need only be used
for networks that have input or layer delays.
The 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:
X |
| Each element |
Xi |
| Each element |
Ai |
| Each element |
T |
| Each element |
Y |
| Each element |
Xf |
| Each element |
Af |
| Each element |
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 Xi, Ai, Xf,
and Af are ordered from oldest delay condition to most recent:
Xi{i,k} | = | Input |
Xf{i,k} | = | Input |
Ai{i,k} | = | Layer output |
Af{i,k} | = | Layer output |
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 also 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:
X |
|
Xi |
|
Ai |
|
T |
|
Y |
|
Xf |
|
Af |
|
[Y,Xf,Af] = sim(net,{Q TS},Xi,Ai) is used for networks that do
not have an input when cell array notation is used.
[Y,...] = sim(net,...,'useParallel',...), [Y,...]
= sim(net,...,'useGPU',...), or
[Y,...] = sim(net,...,'showResources',...) (or the network called
as a function) accepts optional name/value pair arguments to control how calculations
are performed. Two of these options allow training to happen faster or on larger
datasets using parallel workers or GPU devices if Parallel Computing Toolbox is
available. These are the optional name/value pairs:
'useParallel','no' | Calculations occur on normal MATLAB thread. This is the default
|
'useParallel','yes' | Calculations occur on parallel workers if a parallel pool is open. Otherwise calculations occur on the normal MATLAB thread. |
'useGPU','no' | Calculations occur on the CPU. This is the default 'useGPU' setting. |
'useGPU','yes' | Calculations occur on the current gpuDevice if it is a
supported GPU (See Parallel Computing Toolbox for GPU requirements.)
If the current gpuDevice is not supported, calculations remain on
the CPU. If |
'useGPU','only' | If no parallel pool is open, then this setting is the same as
|
'showResources','no' | Do not display computing resources used at the command line. This is the default setting. |
'showResources','yes' | Show at the command line a summary of the computing resources actually used. The actual resources may differ from the requested resources, if parallel or GPU computing is requested but a parallel pool is not open or a supported GPU is not available. When parallel workers are used, each worker’s computation mode is described, including workers in the pool that are not used. |
[Ycomposite,...] = sim(net,Xcomposite,...) takes Composite data
and returns Composite results. If Composite data is used, then
'useParallel' is automatically set to
'yes'.
[Ygpu,...] = sim(net,Xgpu,...) takes gpuArray data and returns
gpuArray results. If gpuArray data is used, then 'useGPU' is
automatically set to 'yes'.
Examples
In the following examples, the sim function is called implicitly by
calling the neural network object (net) as a function.
Simulate Feedforward Networks
This example loads a dataset that maps anatomical measurements x to body fat percentages t. A feedforward network with 10 neurons is created and trained on that data, then simulated.
[x,t] = bodyfat_dataset; net = feedforwardnet(10); net = train(net,x,t);

y = net(x);
Algorithms
sim uses these properties to simulate a network
net.
net.numInputs, net.numLayers net.outputConnect, net.biasConnect net.inputConnect, net.layerConnect
These properties determine the network’s weight and bias values and the number of delays associated with each weight:
net.IW{i,j}
net.LW{i,j}
net.b{i}
net.inputWeights{i,j}.delays
net.layerWeights{i,j}.delays
These 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}.transferFcn
Version History
Introduced before R2006aSee Also
Time Series
Modeler | fitrnet (Statistics and Machine Learning Toolbox) | fitcnet (Statistics and Machine Learning Toolbox) | trainnet | trainingOptions | dlnetwork | predict | minibatchpredict