Main Content

gensim

Generate万博1manbetxblock for shallow neural network simulation

Description

example

gensim(net,st)creates a Simulink®system containing a block that simulates neural networknetwith a sampling time ofst.

Ifnethas no input or layer delays (net.numInputDelaysandnet.numLayerDelaysare both 0), you can use –1 forstto get a network that samples continuously.

gensimdoes not support deep learning networks such as convolutional or LSTM networks. For more information on code generation for deep learning, seeDeep Learning Code Generation.

For more information ongensim, at the MATLAB command prompt, enterhelp network/gensim.

Examples

collapse all

This example shows how to generate a Simulink block for a feedforward network.

Create a feed-forward network using the data from the simple fit data set and generate the Simulink block.

[x,t] = simplefit_dataset; net = feedforwardnet(10); net = train(net,x,t) gensim(net)

This example shows how to generate a Simulink block for a NARX network.

Create a NARX network.

[x,t] = simplenarx_dataset; net = narxnet(1:2,1:2,20); view(net) [xs,xi,ai,ts] = preparets(net,x,{},t); net = train(net,xs,ts,xi,ai); y = net(xs,xi,ai);

Convert the network to closed loop.

net = closeloop(net); view(net)

Prepare the data and simulate the network’s closed loop response.

[xs,xi,ai,ts] = preparets(net,x,{},t); y = net(xs,xi,ai);

Convert the network to a Simulink system with workspace input and output ports.

[sysName,netName] = gensim(net,'InputMode','Workspace',...'OutputMode','WorkSpace','SolverMode','Discrete');

Initialize the delay states. Note that this is an important step to obtain the same output as in MATLAB®.

setsiminit(sysName,netName,net,xi,ai,1);

Define the model inputX1in the workspace, simulate the system programmatically.

x1 = nndata2sim(xs,1,1); out = sim(sysName,'ReturnWorkspaceOutputs','on','StopTime',num2str(x1.time(end))); ysim = sim2nndata(out.y1);

Input Arguments

collapse all

Input network, specified as a network object. To create a network object, use for example,feedforwardnetornarxnet.

Specify the sample time as a value other than -1. For more information, seeSpecify Sample Time(Simulink).

H版istory

Introduced before R2006a

See Also