```
library(igraph)
library(gsbm)
library(missSBM)
#>
#> Attaching package: 'missSBM'
#> The following objects are masked from 'package:stats':
#>
#> simulate, smooth
#> The following object is masked from 'package:base':
#>
#> sample
library(RColorBrewer)
```

Les Misérables characters network, encoding interactions between characters of Victor Hugo’s novel, was first created by Donald Knuth as part of the Stanford Graph Base (https://people.sc.fsu.edu/~jburkardt/datasets/sgb/sgb.html). It contains 77 nodes corresponding to characters of the novel, and 254 vertices connecting two characters whenever they appear in the same chapter.

```
data(les_miserables)
les_miserables$A
A<- les_miserables$names
names <- graph_from_adjacency_matrix(A, mode = "undirected")
net <-V(net)$name <- names
V(net)$color <- "gray80"
degree(net, mode="all")
deg <-V(net)$size <- deg
plot(net, vertex.label.cex = 0.4)
```

We fit a classical SBM to the graph and represent the graph with nodes proportional to their degrees and colored by community assignment. The number of communities has been selected so as to minimize the ICL criterion.

```
1:10
vBlocks <- missSBM::estimate(prepare_data(A), vBlocks = vBlocks, sampling = "node")
collection_sbm <-#>
#>
#> Adjusting Variational EM for Stochastic Block Model
#>
#> Imputation assumes a 'node' network-sampling process
#>
#> Initialization of model with 1 blocks.
2 blocks.
Initialization of model with 3 blocks.
Initialization of model with 4 blocks.
Initialization of model with 5 blocks.
Initialization of model with 6 blocks.
Initialization of model with 7 blocks.
Initialization of model with 8 blocks.
Initialization of model with 9 blocks.
Initialization of model with 10 blocks.
Initialization of model with #> Performing VEM inference for model with 1 blocks.
for model with 2 blocks.
Performing VEM inference for model with 3 blocks.
Performing VEM inference for model with 4 blocks.
Performing VEM inference for model with 5 blocks.
Performing VEM inference for model with 6 blocks.
Performing VEM inference for model with 7 blocks.
Performing VEM inference for model with 8 blocks.
Performing VEM inference for model with 9 blocks.
Performing VEM inference for model with 10 blocks.
Performing VEM inference collection_sbm$bestModel$fittedSBM$connectProb
L_missSBM <- round(collection_sbm$bestModel$fittedSBM$blocks)
colo <- sapply(1:nrow(A), function(i) which.max(colo[i,]))
colo <- brewer.pal(10, "Set3")
pal3 <-V(net)$color <- pal3[colo]
V(net)$label <- NA
V(net)$size <- deg
plot(net)
```

We observe that the main character Jean Valjean is alone in his community, and one of the clusters groups important characters (Thénardier, Éponine, Javert).

The Generalized stochastic Block Model accounts for outlier profiles (hubs, mixed memberships). In this model, nodes are divided into two sets: the inliers which follow a classical SBM, and the outliers, for which we make no assumptions on the connectivity model. These two sets are unknown a priori and are learned automatically by our procedure. Below we represent the result of the clustering, with the detected outliers indicated in red. They correspond to hubs (large center node, Jean Valjean) and nodes with mixed memberships (e.g. smaller central nodes with connections to several clusters).

```
4
lambda1 <- 5
lambda2 <- gsbm_mcgd(A, lambda1 = lambda1, lambda2 = lambda2)
res <- names[which(colSums(res$S)>0)]
outliers <- svd(res$L)
sv <- sv$u[,1:4]
pc <-rownames(pc) <- names
pc[setdiff(names, outliers),]
pc <- kmeans(pc, centers=4, nstart=50)
com <-$cluster
com#> Napoleon MlleBaptistine MmeMagloire CountessDeLo
#> 4 4 4 4
#> Geborand Champtercier Cravatte Count
#> 4 4 4 4
#> OldMan Labarre Marguerite MmeDeR
#> 4 4 4 4
#> Isabeau Gervais Tholomyes Listolier
#> 4 4 1 1
#> Fameuil Blacheville Favourite Dahlia
#> 1 1 1 1
#> Zephine MmeThenardier Fauchelevent Bamatabois
#> 1 4 4 3
#> Perpetue Simplice Scaufflaire Woman1
#> 4 4 4 4
#> Judge Champmathieu Brevet Chenildieu
#> 3 3 3 3
#> Cochepaille Pontmercy Boulatruelle Eponine
#> 3 4 4 4
#> Anzelma Woman2 MotherInnocent Gribier
#> 4 4 4 4
#> Jondrette MmeBurgon Gillenormand Magnon
#> 4 4 4 4
#> MlleGillenormand MmePontmercy MlleVaubois LtGillenormand
#> 4 4 4 4
#> BaronessT Mabeuf Enjolras Combeferre
#> 4 2 2 2
#> Prouvaire Feuilly Courfeyrac Bahorel
#> 2 2 2 2
#> Bossuet Joly Grantaire MotherPlutarch
#> 2 2 2 4
#> Gueulemer Babet Claquesous Montparnasse
#> 4 4 4 4
#> Toussaint Child1 Child2 Brujon
#> 4 4 4 4
#> MmeHucheloup
#> 2
1:nrow(A)
colo2 <-names(colo2) <- names
com$cluster
comu <-which(comu==4)] <- 6
comu[setdiff(names, outliers)] <- pal3[comu]
colo2[ "red"
colo2[outliers] <- names(A)
labels <-names(labels) <- names(A)
setdiff(names, outliers)] <- NA
labels[V(net)$label <- NA
V(net)$color <- colo2
V(net)$size <- deg
E(net)$arrow.size <- 5
plot(net, vertex.label.dist=20)
```