-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlvq.m
More file actions
76 lines (66 loc) · 1.1 KB
/
lvq.m
File metadata and controls
76 lines (66 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
clc
close all
clear all
alpha=input('enter the learning rate alpha : ')
c_len=input('enter the number of classes : ')
t=1;
vector=input('enter all vectors in matrix form seperated by semicolon(;) ' )
c=input('enter the target class they belong to respectively : ')
[r cc]=size(vector)
check=c(1);
k=1;
for i=1:length(c)
if check~=c(i)
ind(k)=i;
break;
end
end
ind
for i=1:cc
w(1,i)=vector(1,i);
w(2,i)=vector(ind,i);
end
k=1;
for i=2:length(c)
if(i~=ind)
rem(k)=i;
k=k+1;
end
end
ch=0;
while(ch==0)
for i=1:cc
x(i)=vector(rem(t),i);
end
k=1;
[w_row,w_col]=size(w)
d=zeros(1,w_row);
for i=1:w_row
for j=1:w_col
d(i)=d(i)+((w(k,j)-x(j))^2)
end
k=k+1;
end
T=c(rem(t));
m=1;
j=d(1);
J=1;
for i=1:w_row
if(d(i)<j)
J=i;
end
end
J
if (T==J)
for i=1:w_col
w(J,i)=w(J,i)+(alpha*(x(i)-w(J,i)));
end
else
for i=1:w_col
w(J,i)=w(J,i)-(alpha*(x(i)-w(J,i)));
end
end
w
t=t+1;
ch=input('enter 0 to continue, 1 to exit : ')
end