mixle.models.random_graph moduleΒΆ

Dependency-free random graph models.

These model helpers deliberately keep graph likelihood math in the model layer. They do not add graph-specific code to compute engines.

class HardEMResult(model, history, validation_history=None)[source]

Bases: FitResult[StochasticBlockGraphModel]

Result from hard-EM fitting of a stochastic block model.

Parameters:
class ErdosRenyiGraphModel(p, directed=False, self_loops=False, name=None)[source]

Bases: object

Independent Bernoulli edge model for directed or undirected graphs.

Parameters:
classmethod fit_mle(adjacency, directed=False, self_loops=False, pseudo_count=0.0, prior_p=0.5, name=None)[source]

Thin shim delegating to fit_erdos_renyi_mle (kept for the classmethod-fit call API).

Parameters:
Return type:

ErdosRenyiGraphModel

log_likelihood(adjacency)[source]

Return the Bernoulli graph log likelihood.

Parameters:

adjacency (Any)

Return type:

float

sample(num_nodes, seed=None)[source]

Draw one binary adjacency matrix.

Parameters:
  • num_nodes (int)

  • seed (int | None)

Return type:

ndarray

bic(adjacency)[source]

Bayesian information criterion with one free parameter.

Parameters:

adjacency (Any)

Return type:

float

class StochasticBlockGraphModel(block_probs, block_assignments, directed=False, self_loops=False, name=None)[source]

Bases: object

Bernoulli stochastic block model with fixed node assignments.

Parameters:
  • block_probs (Any)

  • block_assignments (Sequence[int])

  • directed (bool)

  • self_loops (bool)

  • name (str | None)

classmethod fit_mle(adjacency, block_assignments, num_blocks=None, directed=False, self_loops=False, pseudo_count=0.0, prior_p=0.5, name=None)[source]

Thin shim delegating to fit_stochastic_block_mle (kept for the classmethod-fit call API).

Parameters:
Return type:

StochasticBlockGraphModel

log_likelihood(adjacency)[source]

Return the Bernoulli SBM log likelihood.

Parameters:

adjacency (Any)

Return type:

float

sample(seed=None)[source]

Draw one graph from the block model.

Parameters:

seed (int | None)

Return type:

ndarray

bic(adjacency)[source]

BIC using the number of identifiable block edge probabilities.

Parameters:

adjacency (Any)

Return type:

float

fit_erdos_renyi_mle(adjacency, directed=False, self_loops=False, pseudo_count=0.0, prior_p=0.5, name=None)[source]

Conjugate-Bernoulli MLE of the edge probability (module-level estimation, not a classmethod-fit).

Parameters:
Return type:

ErdosRenyiGraphModel

fit_stochastic_block_mle(adjacency, block_assignments, num_blocks=None, directed=False, self_loops=False, pseudo_count=0.0, prior_p=0.5, name=None)[source]

Conjugate-Bernoulli MLE of block edge probabilities for fixed assignments (module-level estimation).

Parameters:
Return type:

StochasticBlockGraphModel

hard_em_stochastic_block_model(adjacency, num_blocks, max_its=20, restarts=1, seed=None, directed=False, self_loops=False, pseudo_count=1.0, prior_p=0.5)[source]

Classification/hard-EM fit for a stochastic block model.

Parameters:
Return type:

HardEMResult