# In-class demo for 2016-12-06
# Needs the smoothingGraphs library, currently in private release on GitHub
  # TODO: Fix that up and make it public
  
library(igraph)
library(smoothingGraphs)

# Make up a 200-node graph from the "continuous homophily" model
cont_homoph_200 <- rgraphon(n=200, f=cont_homoph)
image(get.adjacenccy(cont_homoph_200$net))
# Find the (Laplacian) spectral order of the nodes
spectral_order <- rank(spectral.primer(cont_homoph_200$net),ties.method="first")
# Plot the graph in spectral order
image(get.adjacency(cont_homoph_200$net)[spectral_order,rev(spectral_order)])
# Smooth it!
system.time(cont.200.smooth <- graph.smoother(cont_homoph_200$net,primer=spectral.primer,iterative=FALSE))
plot(cont.200.smooth)

# Increase network size
cont_homoph_400 <- rgraphon(n=200, f=cont_homoph)
image(get.adjacency(cont_homoph_400$net))
spectral_order <- rank(spectral.primer(cont_homoph_400$net),ties.method="first")
image(get.adjacency(cont_homoph_400$net)[spectral_order,rev(spectral_order)])
system.time(cont.400.smooth <- graph.smoother(cont_homoph_400$net,primer=spectral.primer,iterative=FALSE))
plot(cont.400.smooth)

# Nothing magic about that model
unif_attach_200 <- rgraphon(n=200,f=unif_attach)
bimodal_200 <- rgraphon(n=200, f=bimodal_homoph)
system.time(unif.200.smooth <- graph.smoother(unif_attach_200$net,primer=spectral.primer,iterative=FALSE))
system.time(bimodal.200.smooth <- graph.smoother(bimodal_200$net,primer=spectral.primer,iterative=FALSE))
plot(unif.200.smooth)
plot(bimodal.200.smooth)