0% found this document useful (0 votes)
2 views4 pages

Nfs Exp 1

This document outlines an experiment to design a neural network using MATLAB's neural network toolbox. It details the steps to calculate the output of a simple neuron, define inputs and outputs, configure the network, and train it using specific functions. The experiment concludes with a comparison of the initial and final outputs of the trained network.

Uploaded by

prernamn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Nfs Exp 1

This document outlines an experiment to design a neural network using MATLAB's neural network toolbox. It details the steps to calculate the output of a simple neuron, define inputs and outputs, configure the network, and train it using specific functions. The experiment concludes with a comparison of the initial and final outputs of the trained network.

Uploaded by

prernamn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

-1
Aim: Design a neural network using neural network toolbox
Software Used: MATLAB
Program:
1. Calculate the output of a simple neuron

Define neuron parameters


close all, clear all, clc, format compact
% Neuron weights
w = [4 -2]
% Neuron bias
b = -3
% Activation function
func = 'tansig'
% func = 'purelin'
% func = 'hardlim'
% func = 'logsig'
OUTPUT:
w= 4 -2
b= -3
func = tansig
Define input vector
p= [2 3]
Calculate neuron output
activation_potential = p*w'+b

neuron_output = feval(func, activation_potential)


activation_potential
= -1
neuron_output
= -0.7616
Plot neuron output over the range of inputs
[p1,p2] = meshgrid(-10:.25:10);
z = feval (func, [p1 (:) p2 (:)]*w'+b );
z = reshape(z,length(p1),length(p2));
plot3(p1,p2,z)
grid on
xlabel('Input 1')
ylabel('Input 2')
zlabel('Neuron output')

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
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] ... % output Connect, 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

final_output = 1.0000

2.0000

You might also like