suppressPackageStartupMessages({
    library(gmmase)
    library(igraph)
})

## Please set this TRUE to use user's own graph!
user <- FALSE
if (user) {
#    fname <- readline(prompt="Enter a file name (e.g., /path/edgelist.txt): ")
    fname <- "g.el"
    g <- read_graph(fname, format="edgelist")
} else {
    data(g)
}

E(g)$weight <- stats::runif(ecount(g), 1, 5) # add random edge weights
summary(g)
## IGRAPH acabb9b D-W- 1000 165178 -- Stochastic block-model
## + attr: name (g/c), loops (g/l), weight (e/n)
# GMM for a large graph takes long time (e.g., it takes >5 minutes for a graph with 10K vertices), so "kmeans" is recommended.
system.time(Y <- gmmase(g, dmax=20, embed = "LSE", clustering="kmeans", verbose=FALSE, doplot=TRUE))
## 1. Finding an lcc...
## IGRAPH 488da42 D-W- 1000 165178 -- Stochastic block-model
## + attr: name (g/c), loops (g/l), weight (e/n)
## 2. Passing-to-rank...
## IGRAPH 488da42 D-W- 1000 165178 -- Stochastic block-model
## + attr: name (g/c), loops (g/l), weight (e/n)
## 3. Embedding the graph into dmax = 20...
## 4. Finding an elbow (dimension reduction)...

## , use dhat =  2 
## 5. Clustering vertices...

## , Khat =  2 
## Y
##   1   2 
## 300 700
##    user  system elapsed 
##   5.263   0.133   5.466
table(Y$Y)
## 
##   1   2 
## 300 700