Cosine Similarity and distances between nodes

5 Ansichten (letzte 30 Tage)
Christian Basa
Christian Basa am 16 Apr. 2021
Beantwortet: Austin Thai am 17 Apr. 2021
Is it possible to use cosine similarity to find the distances on a graph between a node and other nodes surrounding it? For example, I have 80 nodes. I find the distance from node 1 to nodes 2:80 and then node 2 from node 1 and nodes 3:80 and repeat that process until i get all the distances?

Antworten (1)

Austin Thai
Austin Thai am 17 Apr. 2021
I assume you are trying to calculate the cosine distance using the cosine similarity.
You can use a for loop , e.g.
nodalCoordinates=rand(80,3); % Replace these with your coordinates
nodalNorms=vecnorm(nodalCoordinates,2,2);
cosineDistances=zeros(80,80); % Include the distance to itself (zero) for simplicity
for i=1:80
cosineSimilarity=nodalCoordinates*nodalCoordinates(i,:)'./(nodalNorms(i)*nodalNorms);
cosineDistances(i,:)=1-cosineSimilarity;
end
If you simply want the spatial distance,
spatialDistances=zeros(80,80); % Include the distance to itself (zero) for simplicity
for i=1:80
spatialDistances(i,:)=vecnorm(nodalCoordinates-nodalCoordinates(i,:),2,2);
end

Kategorien

Mehr zu Construction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by