I'm using karate.gml dataset, from two visualization software gephi and SocNetV both gives me an average path length of 2.408. I want to compute the average path length in matlab using the same dataset, but mine gives me 1.76. My matlab procedure is below:
I add the distance {d} returned by the shortestpath function {[P,d] = shortestpath(G,c,nodesize);} to an array I've declared and afterwards find the mean. Not sure what I'm doing wrong.
size = nodesize;
x = [];
for c = 1:size
[P,d] = shortestpath(G,c,nodesize);
x = [x, d];
end
answer = mean(x)

1 commentaire

Walter Roberson
Walter Roberson le 20 Sep 2018
I would tend to think that average path length would include alternative paths, not just the shortest path.

Connectez-vous pour commenter.

 Réponse acceptée

Isaac Osei Agyemang
Isaac Osei Agyemang le 20 Sep 2018
Modifié(e) : Walter Roberson le 20 Sep 2018

0 votes

size = nodesize;
x = [];
for c = 1:size
for dest=1:size
if(c~=dest)
[P,d] = shortestpath(G,c,dest);
x = [x, d];
end
end
answer = mean(x)

Plus de réponses (1)

KSSV
KSSV le 20 Sep 2018
Modifié(e) : KSSV le 20 Sep 2018

0 votes

nodesize = numnodes(G);
thesize = nodesize;
x = zeros(thesize,1);
for c = 1:size
[P,d] = shortestpath(G,c,nodesize);
x(C) = d ;
end
answer = mean(x)

7 commentaires

Isaac Osei Agyemang
Isaac Osei Agyemang le 20 Sep 2018
@KSSV, Please it still gave me 1.7647
KSSV
KSSV le 20 Sep 2018
What is value of thesize?According to the above code...x should be a vector. Show us your complete code.
Isaac Osei Agyemang
Isaac Osei Agyemang le 20 Sep 2018
Modifié(e) : Walter Roberson le 20 Sep 2018
nodesize = numnodes(G);
size = nodesize;
x = [];
for c = 1:size
[P,d] = shortestpath(G,c,nodesize);
x = [x, d];
end
answer = mean(x)
KSSV
KSSV le 20 Sep 2018
YOu try the code, whic I gave. x will be an vector and answer will be a number as it is mean of x.
Isaac Osei Agyemang
Isaac Osei Agyemang le 20 Sep 2018
I've tried your code, it still gives me 1.76 which the other two visualization software gephi and SocNetV gives 2.4
KSSV
KSSV le 20 Sep 2018
YOu mean mean(x)?
Isaac Osei Agyemang
Isaac Osei Agyemang le 20 Sep 2018
Modifié(e) : Walter Roberson le 20 Sep 2018
I've been able to work things out, thanks for your help.
size = nodesize;
x = [];
for c = 1:size
for dest=1:size
if(c~=dest)
[P,d] = shortestpath(G,c,dest);
x = [x, d];
end
end
answer = mean(x)

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by