%% 输入环节
date = [1.2,1.3,1.1,3.8,4.2];
X = date(:);
%% 相似度矩阵求解环节
S = squareform(pdist(X, 'euclidean'));
S = -S;
p = min(S(:));
N = size(S, 1);
P = diag( p * ones(N,1) );
S = S+P;
%% 参数设置环节
R = zeros(N, N);
A = zeros(N, N);
damping = 0.5;
max_iter = 1000;
%% 迭代环节
for m=1:max_iter;
AS=A+S;
ROLD=R;
AOLD=A;
for i=1:N
ASH=AS(i,:);
for k=1:N
ash = ASH(~ismember(1:length(ASH), k));
R(i,k)=S(i,k)-max(ash);
end
end
for i = 1:N
for k = 1:N
RL = R(:, k);
if i == k
RL1 = RL(~ismember(1:length(RL), k));
RZ1 = RL1(RL1 > 0);
RZ1S = sum(RZ1);
A(i, k) = RZ1S;
else
RL2 = RL(~ismember(1:length(RL), [i, k]));
RZ2 = RL2(RL2 > 0);
RZ2S = sum(RZ2);
A(i, k) = min(0, R(k, k) + RZ2S);