Edge Priors
The edge prior framework controls which edges are included in the graph. All priors inherit from BaseEdgePrior in src/priors/edge_prior.h.
BaseEdgePrior interface
class BaseEdgePrior {
virtual void update(const arma::imat& edge_indicators,
arma::mat& inclusion_probability,
int num_variables, int num_pairwise,
SafeRNG& rng) = 0;
virtual std::unique_ptr<BaseEdgePrior> clone() const = 0;
virtual bool has_allocations() const { return false; }
virtual arma::ivec get_allocations() const { return arma::ivec(); }
};The update() method is called once per MCMC iteration (when edge selection is active). It receives the current edge indicators and updates the inclusion probability matrix in place. The updated probabilities are used by the model’s update_edge_indicators() method for the next round of edge proposals.
clone() produces an independent copy for parallel chain execution.
BernoulliEdgePrior
The simplest prior: each edge has a fixed inclusion probability that does not change during sampling. The update() method is a no-op.
This prior is used when the user specifies edge_prior = "Bernoulli" with a fixed inclusion probability matrix. This is the default edge prior in bgms.
BetaBernoulliEdgePrior
A conjugate prior that learns a shared inclusion probability from the data. At each iteration:
- Count the number of included edges: \(k = \sum_{i<j} \gamma_{ij}\)
- Count the total number of possible edges: \(m = p(p-1)/2\)
- Draw a new inclusion probability: \(\pi \sim \text{Beta}(\alpha + k,\; \beta + m - k)\)
- Set all entries of the inclusion probability matrix to \(\pi\)
The hyperparameters \(\alpha\) and \(\beta\) default to 1 (uniform prior on the inclusion probability).
StochasticBlockEdgePrior
The stochastic block model (SBM) prior assigns variables to latent clusters and allows different inclusion probabilities for within-cluster and between-cluster edges. See SBM Prior for the full formulation.
The StochasticBlockEdgePrior class stores:
cluster_allocations_— Current cluster assignment for each variablecluster_prob_— \(K \times K\) matrix of block inclusion probabilitieslog_Vn_— Log partition coefficients for the MFM prior on cluster count
Its update() method runs collapsed Gibbs sampling to update cluster assignments and block probabilities (delegated to functions in sbm_edge_prior.cpp).
has_allocations() returns true, and get_allocations() returns the current cluster assignment vector. These are stored in ChainResult::allocation_samples for post-hoc analysis.
Prior selection in R
The edge_prior argument in bgm() maps to these classes:
| R value | C++ class | Behavior |
|---|---|---|
"Bernoulli" |
BernoulliEdgePrior |
Fixed inclusion probabilities |
"Beta-Bernoulli" |
BetaBernoulliEdgePrior |
Learns shared inclusion rate |
"Stochastic-Block" |
StochasticBlockEdgePrior |
Cluster-structured inclusion |
When edge_selection = FALSE, no edge prior is instantiated and all edges remain included throughout sampling.
Factory dispatch
The create_edge_prior() factory in edge_prior.h maps an EdgePrior enum value to the concrete class. The enum is produced from the R string by edge_prior_from_string() in common_helpers.h.
Execution order
Within each MCMC iteration, the edge prior update runs after the model’s edge indicator and parameter updates:
model.update_edge_indicators()— MoMS add/delete moves using the current inclusion probability matrixsampler->step(model, iteration)— parameter updatesedge_prior.update(...)— update the inclusion probability matrix based on the new edge indicators
The updated probabilities take effect in the next iteration’s edge indicator proposals.