You are on page 1of 8

install.

packages("igraph")
library(igraph)
dolphin <- read.graph(file='https://lipn.univ-paris13.fr/~kanawati/datasets/dolphins.gml', format='gml')
karate <- read.graph(file='https://lipn.univ-paris13.fr/~kanawati/datasets/karate.gml', format='gml')
football <- read.graph(file='https://lipn.univ-paris13.fr/~kanawati/datasets/football.gml', format='gml')
polblogs <- read.graph(file='https://lipn.univ-paris13.fr/~kanawati/datasets/polblogs.gml', format='gml')

Installing package into ‘/usr/local/lib/R/site-library’


(as ‘lib’ is unspecified)

Double-click (or enter) to edit

#Step 1: find communities on karate


k1 = cluster_walktrap(karate)
k2 = cluster_infomap(karate)
k3 = cluster_edge_betweenness(karate)
k4 = cluster_louvain(karate)
#Step 1: find communities on dolphins
d1 = cluster_walktrap(dolphin)
d2 = cluster_infomap(dolphin)
d3 = cluster_edge_betweenness(dolphin)
d4 = cluster_louvain(dolphin)
#Step 1: find communities on football
f1 = cluster_walktrap(football)
f2 = cluster_infomap(football)
f3 = cluster_edge_betweenness(football)
f4 = cluster_louvain(football)
#Step 1: find communities on polblogs
p1 = cluster_walktrap(polblogs)
p2 = cluster_infomap(polblogs)

#comparison between the karate network and the grund truth


compare(k1,V(karate)$value,method = "nmi")

account_circle 0.504178032536738

compare(k2,V(karate)$value,method = "nmi")

0.699488160981481

compare(k3,V(karate)$value,method = "nmi")

0.579827776314514

compare(k4,V(karate)$value,method = "nmi")

0.602144675303274

#comparison between the Football network and the grund truth


compare(f1,V(football)$value,method = "nmi")

0.88736040155263

compare(f2,V(football)$value,method = "nmi")

0.900191016856867

compare(f3,V(football)$value,method = "nmi")

0.87888840621752

compare(f4,V(football)$value,method = "nmi")

0.890316631205243

#comparison between the Dolphin network and the grund truth


compare(d1,V(dolphin)$value,method = "nmi")

0.537250035472741

compare(d2,V(dolphin)$value,method = "nmi")
0.586466277780293
compare(d3,V(dolphin)$value,method = "nmi")

0.554160499047686

compare(d4,V(dolphin)$value,method = "nmi")

0.516233806972036

compare(p1,V(polblogs)$value,method = "nmi")

0.375993282430778

compare(p2,V(polblogs)$value,method = "nmi")

0.106549726960963

plot(k1,karate)

plot(k2,karate)

plot(k3,karate)
plot(k4,karate)

#football network
plot(f1,football,vertex.label = NA)

plot(f2,football,vertex.label = NA)
plot(f3,football,vertex.label = NA)

plot(f4,football,vertex.label = NA)

#Dolphin network plot


plot(d1,dolphin,vertex.label = NA)
plot(d2,dolphin,vertex.label = NA)

plot(d3,dolphin,vertex.label = NA)

plot(d4,dolphin,vertex.label = NA)
#Polblogs network plot
plot(p1,polblogs,vertex.label = NA)

plot(p2,polblogs,vertex.label = NA)

#Comparisons between communities computed for karate network


compare(k1,k2,method = "nmi")

0.668640471027136

compare(k1,k3,method = "nmi")

0.73116812913428

compare(k1,k4,method = "nmi")

0.681708997903823

compare(k2,k3,method = "nmi")

0.758948951111028

compare(k2,k4,method = "nmi")

0.879553801876572

compare(k3,k4,method = "nmi")

0.830144280446685
#Comparisons between communities computed for football network
compare(f1,f2,method = "nmi")

0.940558812764159

compare(f1,f3,method = "nmi")

0.898524715290849

compare(f1,f4,method = "nmi")

0.953751390955327

compare(f2,f3,method = "nmi")

0.911233562739427

compare(f2,f4,method = "nmi")

0.929334189903369

compare(f3,f4,method = "nmi")

0.944935844842863

#Comparisons between communities computed for Dolphin network


compare(d1,d2,method = "nmi")

0.717795971762254

compare(d1,d3,method = "nmi")

0.660712874202

compare(d1,d4,method = "nmi")

0.69579354619415

compare(d2,d3,method = "nmi")

0.81589590217833

compare(d2,d4,method = "nmi")

0.853539534200068

compare(d3,d4,method = "nmi")

0.783402883314

#Comparisons between communities computed for Polblogs network


compare(p1,p2,method = "nmi")

0.680077909329308

#Modularity of Karate Network


modularity(k1)

0.353221564760026

modularity(k2)

0.402038132807364

modularity(k3)

0.401298487836949

modularity(k4)

0.415598290598291
#Modularity of Football Network
modularity(f1)

0.603811223478088

modularity(f2)

0.579033643994976

modularity(f3)

0.600512922202393

modularity(f4)

0.605445171524886

#Modularity of Dolphin Network


modularity(d1)

0.488845377951822

modularity(d2)

0.52851944147779

modularity(d3)

0.519382144693643

modularity(d4)

0.518828369130968

#Modularity of Karate Network


modularity(p1)

0.430257425264407

modularity(p2)

0.0254857652305077

You might also like