Effacer les filtres
Effacer les filtres

Cosine Similarity and distances between nodes

3 vues (au cours des 30 derniers jours)
Christian Basa
Christian Basa le 16 Avr 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?

Réponses (1)

Austin Thai
Austin Thai le 17 Avr 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

Catégories

En savoir plus sur Construction dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by