Custom networks

Neural Networks course (practical examples) © 2012 Primoz Potocnik

PROBLEM DESCRIPTION: Create and view custom neural networks

Contents

Define one sample: inputs and outputs

close all, clear all, clc, format compact

inputs  = [1:6]' % input vector (6-dimensional pattern)
outputs = [1 2]' % corresponding target output vector
inputs =
     1
     2
     3
     4
     5
     6
outputs =
     1
     2

Define and custom network

% create network
net = network( ...
1,          ... % numInputs,    number of inputs,
2,          ... % numLayers,    number of layers
[1; 0],     ... % biasConnect,  numLayers-by-1 Boolean vector,
[1; 0],     ... % inputConnect, numLayers-by-numInputs Boolean matrix,
[0 0; 1 0], ... % layerConnect, numLayers-by-numLayers Boolean matrix
[0 1]       ... % outputConnect, 1-by-numLayers Boolean vector
);

% View network structure
view(net);

Define topology and transfer function

% number of hidden layer neurons
net.layers{1}.size = 5;

% hidden layer transfer function
net.layers{1}.transferFcn = 'logsig';
view(net);

Configure network

net = configure(net,inputs,outputs);
view(net);

Train net and calculate neuron output

% initial network response without training
initial_output = net(inputs)

% network training
net.trainFcn = 'trainlm';
net.performFcn = 'mse';
net = train(net,inputs,outputs);

% network response after training
final_output = net(inputs)
initial_output =
     0
     0
final_output =
    1.0000
    2.0000