MMSB (Mixed Membership Stochastic Blockmodel) Documentation

πŸ” Overview

MMSB is a probabilistic generative model for graph data where each node is represented by a distribution over latent communities (blocks). Each edge is generated based on sampled community assignments from Dirichlet-distributed memberships and a block interaction matrix B.


βš™οΈ Class Definition

Class Name: MMSB

This class implements a simplified version of MMSB for sampling synthetic graphs.

class MMSB:
    def __init__(self, n_nodes: int, n_blocks: int, alpha: float = 0.5):
        ...

πŸ“‹ Parameters

Parameter

Type

Default

Description

n_nodes

int

β€”

Number of graph nodes

n_blocks

int

β€”

Number of latent blocks (communities)

alpha

float

0.5

Dirichlet prior parameter for membership


πŸ’» Using Example

from soft_clustering._mmsb._mmsb import MMSB

model = MMSB(n_nodes=6, n_blocks=3, alpha=0.5)
Y = model.sample_graph()
pi = model.get_memberships()
B = model.get_block_matrix()

print("Adjacency Matrix:", Y)
print("Memberships:", pi)
print("Block Matrix:", B)

πŸ“₯ Input / πŸ“€ Output

  • Input: None required at inference time (sampling model)

  • Returns:

    • Y (Tensor): Adjacency matrix (n_nodes x n_nodes)

    • pi (Tensor): Membership matrix (n_nodes x n_blocks)

    • B (Tensor): Block interaction matrix (n_blocks x n_blocks)


πŸ› οΈ Methods

  • sample_graph(): Generates a synthetic adjacency matrix from MMSB

  • get_memberships(): Returns Dirichlet-distributed node memberships

  • get_block_matrix(): Returns the B matrix of interaction probabilities


πŸ“ Implementation Notes

  • Memberships are sampled from Dirichlet distributions

  • Each pair of nodes samples latent community assignments

  • Edge presence determined by Bernoulli trials from B matrix


πŸ“š Reference

  1. Airoldi, E. M., Blei, D. M., Fienberg, S. E., & Lafferty, J. D. (2008). Mixed Membership Stochastic Blockmodels. Journal of Machine Learning Research 9.