[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [igraph] what does the knn() function do with weighted graphs?

**From**: |
Szabolcs Horvát |

**Subject**: |
[igraph] what does the knn() function do with weighted graphs? |

**Date**: |
Tue, 25 Apr 2017 20:32:19 +0200 |

Hello,
I am having some trouble understanding what the
igraph_avg_nearest_neighbor_degree() function does with weights. This
function is called knn() in R.
I thought that it simply computed the average strengths of a vertex's
neighbours. But this does not seem to be the case.
Let's make a 3-ring with edge weights 1,2,3:
g<-make_ring(3)
E(g)$weight <- c(1,2,3)
The strengths are 4, 3, 5, as I expected:
>* strength(g)*
[1] 4 3 5
knn() gives the following result:
>* knn(g)*
$knn
[1] 2.0 3.0 1.4
I would have expected this to be (3+5)/2 = 4, (4+5)/2 = 4.5, and
(4+3)/2 = 3.5 for the three vertices, as each of them have two
neighbours.
What am I misunderstanding?
The documentation says,
"Calculate the average nearest neighbor degree of the given vertices"
and
"If the graph has a weight edge attribute, then this is used by
default. If this argument is given, then vertex strength (see
strength) is used instead of vertex degree."
Szabolcs

**[igraph] what does the knn() function do with weighted graphs?**,
*Szabolcs Horvát* **<=**