how can i compute those variables using matlab?

2 ビュー (過去 30 日間)
sam mohel
sam mohel 2022 年 4 月 9 日
回答済み: Anurag 2023 年 10 月 25 日
I'm very new to Matlab and I applied the density peak algorithm to my data using the Matlab code but I need to calculate sigma and rho. how can I start
the code is
mdist="ex.dat"
disp('Reading input distance matrix')
xx=load(mdist);
ND=max(xx(:,2));
NL=max(xx(:,1));
if (NL>ND)
ND=NL;
end
N=size(xx,1);
for i=1:ND
for j=1:ND
dist(i,j)=0;
end
end
for i=1:N
ii=xx(i,1);
jj=xx(i,2);
dist(ii,jj)=xx(i,3);
dist(jj,ii)=xx(i,3);
end
percent=2.0;
fprintf('average percentage of neighbours (hard coded): %5.6f\n', percent);
position=round(N*percent/100);
sda=sort(xx(:,3));
dc=sda(position);
fprintf('Computing Rho with gaussian kernel of radius: %12.6f\n', dc);
for i=1:ND
rho(i)=0.;
end
for i=1:ND-1
for j=i+1:ND
rho(i)=rho(i)+exp(-(dist(i,j)/dc)*(dist(i,j)/dc));
rho(j)=rho(j)+exp(-(dist(i,j)/dc)*(dist(i,j)/dc));
end
end
maxd=max(max(dist));
[rho_sorted,ordrho]=sort(rho,'descend');
delta(ordrho(1))=-1.;
nneigh(ordrho(1))=0;
for ii=2:ND
delta(ordrho(ii))=maxd;
for jj=1:ii-1
if(dist(ordrho(ii),ordrho(jj))<delta(ordrho(ii)))
delta(ordrho(ii))=dist(ordrho(ii),ordrho(jj));
nneigh(ordrho(ii))=ordrho(jj);
end
end
end
the variables that i need to compute is
rho(i) = sum(X(dij-dc))
and
sigma(i) = min(dij)

回答 (1 件)

Anurag
Anurag 2023 年 10 月 25 日
Hi Sam,
I understand that you want to compute the variables “Rho” and “Sigma” based on the explanation and the code that you have provided.
  • For computing “Rho” for each data point (i") you need to calculate the sum of Gaussian-weighted distances between point i and all other data points. Which translates to the following in code –
rho(i) = rho(i) + exp(-(dist(i, j) / dc) * (dist(i, j) / dc));
  • To compute “sigma” for each data point (i), you need to find the minimum distance (dij) between point i and its nearest neighbour. Refer to the following code for the computation of the same.
delta(ordrho(ii)) = maxd; % Set delta to a large initial value
for jj = 1:ii-1
if dist(ordrho(ii), ordrho(jj)) < delta(ordrho(ii))
delta(ordrho(ii)) = dist(ordrho(ii), ordrho(jj));
nneigh(ordrho(ii)) = ordrho(jj);
end
end
Hope this helped.
Regards,
Anurag

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by