[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Calculating Q-Spa modularity for spatially embedded network
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] Calculating Q-Spa modularity for spatially embedded networks |
Date: |
Mon, 11 Apr 2011 12:28:24 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 |
> I am no mathematician, but can code OK in R. From the look of equations, I
> am guessing that practically it will mean creating another matrix
> containing the pairwise distances between nodes, then.. well that's when it
> gets fuzzy.
In a first (rough and not scalable) implementation, you will need three
matrices (let's neglect the weights for now):
A - the adjacency matrix of the graph where A_{ij} is 1 if i and j are
connected, zero otherwise.
P - the null model matrix which you obtain from Eqs (5) and (6)
delta - a matrix where delta_{ij} is 1 if i and j are in the same cluster,
zero otherwise.
The modularity is then simply the sum of the elements in the *elementwise*
product of (A-P) and delta, divided by 2m (which is the sum of elements in
A). I don't know how to implement this in R, but I hope this helps anyway.
If you implement this, an easy way to check your implementation is to take
an undirected graph and make P equal to d * d', where d is the column vector
of vertex degrees. Your function should then give the same results as
igraph's built-in modularity() function.
--
Tamas