0% found this document useful (0 votes)
16 views

Assignment 2

The document describes training and testing a learning vector quantization (LVQ) neural network for classification. It defines input data and target classes, trains the network over 500 epochs, then tests it on new unseen data, achieving good accuracy on the test classifications.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment 2

The document describes training and testing a learning vector quantization (LVQ) neural network for classification. It defines input data and target classes, trains the network over 500 epochs, then tests it on new unseen data, achieving good accuracy on the test classifications.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

clc;

x = [95 95 85 89;
49 52 83 80;
90 90 41 42;
97 94 84 90;
96 94 86 88;
50 50 85 84;
92 96 43 40];
% Data has to be input colum wise to the ANN, and hence
% transposition is necessary
%
q = x'

q = 4×7
95 49 90 97 96 50 92
95 52 90 94 94 50 96
85 83 41 84 86 85 43
89 80 42 90 88 84 40

% Let us now define the target classes for the 7 input vectors as follows:

Tc=[3 2 1 3 3 2 1]

Tc = 1×7
3 2 1 3 3 2 1

% specify datarate for normalization


% 10 specifies 1 hidden layer with 10 neurons
% Class representation of each class
% 0.5 is the learning rate

net = newlvq(minmax(q),10,[3/7 2/7 2/7],0.5);


view(net)
%
% Next convert the Tc matrix to target vectors.
%
T = ind2vec(Tc)

T =
(3,1) 1
(2,2) 1
(1,3) 1
(3,4) 1
(3,5) 1
(2,6) 1
(1,7) 1

%
% This gives a sparse matrix T that can be displayed in full with
%

1
targets = full(T)

targets = 3×7
0 0 1 0 0 0 1
0 1 0 0 0 1 0
1 0 0 1 1 0 0

%
net.trainParam.epochs = 500;
net = train(net,q,T);
% After training is completed, Simulate the network with the same input set
% to verify the success of training
a = sim(net,q);
% Output Class index of the input patterns can be checked as:
%
class_index = vec2ind(a)

class_index = 1×7
3 2 1 3 3 2 1

%
% This yields
% class_index =

%
% 3 2 1 3 3 2 1
%
% Note that the network is trained to classify the input vectors into two pre-defined groups,
% First two vectors are put into class 1, and the other two vectors are put into class 2.
%
% Now it is necessary to chechk the classification accuracy for unseen
% vectors. Let us choose four unseen input vectors as:
%
q1= [45 48 82 95;
90 82 76 77;
96 87 84 84;
95 90 63 45];
%
% Now simulate the network with these new unknown inputs
a = sim(net,q1');
%
% which should belong to Class 2, 3 and 4 respectively
% Output Class index of this unseen input patterns can be checked as:
%
class_index = vec2ind(a)

class_index = 1×4
2 3 3 1

%
% This yields
% class_index = 2 3 3 1

2
3

You might also like