Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- close all;
- clc
- X = load('/Users/marialukasova/Downloads/CD_ИАД_2019-3/ЛР_6/Data_Lab6/data4.txt');
- figure;
- plot(X(:,1), X(:,2), '*');
- numNeuron = 2;
- C = zeros(numNeuron,2);
- mnX = min(X(:,1));
- mxX = max(X(:,1));
- mnY = min(X(:,2));
- mxY = max(X(:,2));
- C(1,1) = mnX + (mxX-mnX).*rand();
- C(2,1) = mnX + (mxX-mnX).*rand();
- C(1,2) = mnY + (mxY-mnY).*rand();
- C(2,2) = mnY + (mxY-mnY).*rand();
- k_max = 1000;
- h=0.01;
- R = zeros(1,numNeuron);
- for k = 1:k_max
- num = ceil(1+(length(X)-1).*rand());
- for n = 1 : numNeuron
- R(n) = pdist([X(num , :) ; C(n , :)],'euclidean');
- end
- nC = C;
- for n = 1 : numNeuron
- if R(n) == min(R)
- nC(n,1) = C(n,1)+ h*(X(num,1)-C(n,1));
- nC(n,2) = C(n,2)+ h*(X(num,2)-C(n,2));
- end
- end
- C = nC;
- end
- U = zeros(length(X));
- for i = 1 : length(X)
- for n = 1 : numNeuron
- P(n) = pdist([X(i , :) ; C(n , :)],'euclidean');
- end
- for n = 1 : numNeuron
- if P(n) == min(P)
- U(i) = n;
- end
- end
- end
- figure
- scatter(C(:,1),C(:,2),'*')
- hold on
- gscatter(X(:,1), X(:,2), U(:,1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement