%% Create Layer Graph from Function
% The simplemodel function at the end of this example creates fully connected outputs followed by a softmax operation. To create a layer graph from this function based on dlarray data, create input arrays as dlarray objects, and create a function handle to the simplemodel function including the data.

rng default % For reproducibility
dlX1 = dlarray(rand(10),'CB');
dlX2 = dlarray(zeros(10,1),'CB');
fun = @(x)simplemodel(x,dlX1,dlX2);

% Call functionToLayerGraph using a dlarray for the input data dlX.

dlX = dlarray(ones(10,1),'CB');
lgraph = functionToLayerGraph(fun,dlX)

% Examine the resulting layers in lgraph.

disp(lgraph.Layers)

%

function y = simplemodel(x,w,b)
y = fullyconnect(x,w,b);
y = softmax(y);
end

% Copyright 2019 The MathWorks, Inc.