-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_mds.m
50 lines (36 loc) · 991 Bytes
/
get_mds.m
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
function [y,stress,dy] = get_mds(dx,dims)
stress = zeros(1,length(dims));
J = zeros(1,4000);
for dim = dims
N = size(dx,1);
y = 0.001*randn(N,dim);
dy = calcD(y);
passo = 0.001;
k = 1;
% J(k) = sqrt((sum(sum(dx-dy)).^2)/sum(sum(dx.^2)));
a = (dx-dy).^2;
b = dx.^2;
J(k) = sqrt(sum(a(:))/sum(b(:)));
for k = 2:5000
pesos = (dx-dy)./(dy+eps);
for n = 1:N
vetores = y-ones(N,1)*y(n,:);
ynovo(n,1:dim) = y(n,:)-passo*pesos(n,:)*vetores;
end
dy = calcD(ynovo);
a = (dx-dy).^2;
% b = dx.^2;
J(k) = sqrt(sum(a(:))/sum(b(:)));
if J(k) < J(k-1)
y = ynovo;
end
end
stress(dim) = J(end);
end
plot(stress); grid on;
% Plota o espaço inicial (aleatório).
%for k = 1:length(C)
% plot(y(k,1),y(k,2),'b*'); hold on; grid on;
% text(y(k,1),y(k,2),C(k),'FontSize',15);
%end
end