Search code examples
rcluster-analysisigraph

Cluster_leiden(), what is / where can I find the meaning of the value $quality in the result object?


The following code

library(igraph)
g <- make_ring(5)
set.seed(1)
cle <- cluster_leiden(g, resolution=1, objective_function=c("CPM", "modularity")[1])

modularity(g, membership(cle))
cle$quality

# print_all(g)    
# print.default(cle)

returns:

> modularity(g, membership(cle))
[1] -0.2
> cle$quality
[1] -0.5

Question: what is / where can I find the meaning of the value $quality in the result object. It is not the modularity...


Solution

  • As pointed out by https://stackoverflow.com/users/695132/szabolcs the objective function equals:

     (1/2m) (ΣAij - Σ γ.ni.nj), whenever i and j are in the same community.
    

    In this example:

    • ni evaluate to 1, as no weight is assigned to any vertex.
    • m evaluates to 5 edges.
    • ΣAij evaluates to zero as all the communities are singletons without a self loop.
    • γ evaluates to 1.
    • Σ γ.ni.nj evaluates to 5.

    Giving (0 - 5) / 10 = -0.5.