how can i compute those variables using matlab?
이전 댓글 표시
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
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
카테고리
도움말 센터 및 File Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!