Borrar filtros
Borrar filtros

how can i compute those variables using matlab?

1 visualización (últimos 30 días)
sam mohel
sam mohel el 9 de Abr. de 2022
Respondida: Anurag el 25 de Oct. de 2023
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)

Respuestas (1)

Anurag
Anurag el 25 de Oct. de 2023
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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by