Clustering, density estimation, and anomaly detection · Graph and community clustering · UCL034 · Model
Stochastic block model (SBM)
Model a network using latent blocks whose members have similar connection probabilities. Unlike purely assortative community objectives, an SBM can represent bipartite, core–periphery, or disassortative structure.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.
- Stochastic blockmodel Experimental
Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.
- Availability
- Runs in CodeSplash (Experimental)
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.sbm. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Model a network using latent blocks whose members have similar connection probabilities. Unlike purely assortative community objectives, an SBM can represent bipartite, core–periphery, or disassortative structure.
Question / hypotheses
Which partition or latent block structure best explains the supplied graph relationships? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.
Architecture / computational structure
Latent node labels plus a block-to-block edge probability matrix.
Assumptions
Conditional edge independence is restrictive for triangles and other dependence. Ordinary SBM treats nodes within a block as degree-homogeneous in expectation apart from block sizes.
Formula / computational definition
For a simple undirected graph, independently for . Here is node 's block and is the probability of an edge between blocks . Fit labels and block probabilities using likelihood, variational inference, or Bayesian description-length methods.
Parameters and notation
Learned or fitted quantities: Block memberships, block proportions, and edge probabilities. User-set hyperparameters/design choices: Choose block count or a selection prior, directedness, edge distribution, and self-loop convention. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.
Fitting, fine-tuning, and adaptation
Neural fine-tuning is not applicable. Refit after material edge or weight changes and compare several initializations. Warm-starting a partition can help computation but may preserve an obsolete solution; use the same graph construction when comparing versions.
How to use and calibrate
Use held-out edge/nonedge prediction with an explicit sampling scheme, posterior predictive graph summaries, and penalized model selection. Raw likelihood increases with complexity and cannot alone choose block count.
Example application
Distinguish core, peripheral, and cross-connected roles in a network. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.
Interpretation / pitfalls
Watch out
The reported result is conditional on the representation and objective. A stable partition can reflect nuisance structure such as batch, collection site, or missingness. Confirm the interpretation in original variables and an independent sample.
Python and R code examples
Python graph-tool provides SBM inference; choose deg_corr=False for the ordinary model. R packages blockmodels and sbm supply model-based network clustering. Confirm Bernoulli versus multigraph conventions before comparing likelihoods.
Component: Bernoulli SBM likelihood for supplied labels. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Bernoulli SBM likelihood for supplied labels. · needs numpy
import numpy as np
A=np.array([[0,1,0],[1,0,0],[0,0,0]]); z=np.array([0,0,1])
B=np.array([[.8,.1],[.1,.6]]); i,j=np.triu_indices(3,1); p=B[z[i],z[j]]
result=np.sum(A[i,j]*np.log(p)+(1-A[i,j])*np.log1p(-p))
print(result)
Component demo, not a trained model — Bernoulli SBM likelihood for supplied labels.
A=rbind(c(0,1,0),c(1,0,0),c(0,0,0)); z=c(1,1,2); B=rbind(c(.8,.1),c(.1,.6))
ij=which(upper.tri(A),arr.ind=TRUE); p=B[cbind(z[ij[,1]],z[ij[,2]])]
result=sum(A[ij]*log(p)+(1-A[ij])*log1p(-p))
print(result)
Sources
- Source 1graph-tool.skewed.de
- Source 2cran.r-project.org
From the CodeSplash reference, entry UCL034.