---
kind: concept
slug: bayesian-scoring-metric
title: Bayesian scoring metric
summary: >-
  Score a Bayesian network structure from data plus prior beliefs, so candidate graphs can be ranked. One paper gives a general metric (Be) and two closed forms: BDe for discrete variables with Dirichlet priors and BGe for Gaussian variables with normal-Wishart priors. Needs complete data and assessed priors. No experiments, so no accuracy numbers.
tags: [structure-learning, bayesian-networks, dirichlet-prior, normal-wishart-prior]
papers: ["1302.4957"]
related: [bayesian-network, causal-discovery, model-selection]
status: draft
updated_at: 2026-11-12
---

## Overview

A Bayesian scoring metric assigns a number to each candidate structure of a
Bayesian network, given a data set and prior beliefs. A higher score means the
structure explains the data better, weighted by the prior. Structures are then
ranked by this number. The score of a structure S is its relative posterior,
p(D, H_S | ξ), up to a normalising constant. Dividing by a reference structure
such as the empty graph gives the same ranking [arxiv:1302.4957 §2] [eq. 8].

The shared invariant is likelihood equivalence: two structures that imply the
same independence statements receive the same score [arxiv:1302.4957 §3]
[arxiv:1302.4957 §7.3 Theorem 14]. The priors are not chosen per structure. A
single complete reference structure fixes all of them, through a small set of
assumptions [arxiv:1302.4957 §3 Theorem 2].

Only one card on this wiki covers the metric:
[Learning Bayesian Networks: A Unification for Discrete and Gaussian Domains](/papers/1302.4957).
The paper reports no experiments, so every statement on this page is about the
formulas, not about measured structure recovery.

## Variants

### General Be metric

The base metric for complete data. It requires four prior assumptions:
likelihood equivalence, a positive prior on every complete structure, global
parameter independence, and parameter modularity [arxiv:1302.4957 §3]. Under
these, the score of any structure factorises into one term per child, each a
ratio of marginal likelihoods on a complete reference structure
[arxiv:1302.4957 §4 Theorem 6] [eq. 14]. Card:
[Learning Bayesian Networks: A Unification for Discrete and Gaussian Domains](/papers/1302.4957).

### BDe, discrete variables

The closed form for discrete variables. The joint parameters get a Dirichlet
prior whose exponents come from an effective sample size N' and a prior
network [arxiv:1302.4957 §5.1] [eq. 15]. The score is a product of Gamma
functions over each child and each parent configuration [arxiv:1302.4957 §5.1
Theorem 7] [eq. 18]. Card:
[Learning Bayesian Networks: A Unification for Discrete and Gaussian Domains](/papers/1302.4957).

### BGe, Gaussian variables

The closed form for continuous variables. The prior is normal-Wishart with
effective sizes N'_mu > 0 and N'_tau > n - 1, where n is the number of variables
[arxiv:1302.4957 §5.2] [§6]. The score uses the marginal over each child and
its parents, with a multivariate gamma factor and a posterior scale matrix
[arxiv:1302.4957 §5.2 Theorem 8] [eq. 21] [eq. 23] [eq. 24]. Card:
[Learning Bayesian Networks: A Unification for Discrete and Gaussian Domains](/papers/1302.4957).

### Mixed discrete and continuous domains

Order the discrete variables before the continuous ones. Use the BDe term for
the discrete part, and a BGe term per discrete state for the continuous part
[arxiv:1302.4957 §5.2]. The paper states this as a construction and gives no
experiment on mixed data [arxiv:1302.4957 §5.2] [§6]. Card:
[Learning Bayesian Networks: A Unification for Discrete and Gaussian Domains](/papers/1302.4957).

## When to use which

| Situation | Use | Why |
|---|---|---|
| All variables discrete, complete data, and a prior network over the joint table can be assessed | BDe | Closed form with Gamma functions and one effective sample size N' [arxiv:1302.4957 §5.1] [eq. 18] |
| All variables continuous, complete data, and effective sizes N'_mu and N'_tau can be set | BGe | Closed form for normal-Wishart priors [arxiv:1302.4957 §5.2] [eq. 23] |
| Both kinds of variable in one network | Mixed construction | Discrete ordered first, BDe plus BGe per discrete state [arxiv:1302.4957 §5.2] |
| A prior family other than Dirichlet or normal-Wishart | General Be metric, if the four assumptions hold for that prior | The paper's Theorem 6 is stated for any prior satisfying them [arxiv:1302.4957 §4] [§3] |
| Missing values in the data | None of the closed forms applies | Closed forms assume complete data [arxiv:1302.4957 §4 Assumption 6]; the paper names filling in, EM and Gibbs sampling but does not develop them [arxiv:1302.4957 §4] |
| Causal rather than acausal network | Check likelihood equivalence as an assumption | For causal networks the paper treats likelihood equivalence as a reasonable assumption in many domains, not a given [arxiv:1302.4957 §3] |
| Acausal network with many equivalent structures | Score equivalence classes | The paper says to score classes rather than single structures in the acausal case [arxiv:1302.4957 §3] |

The paper gives no default values for the prior constants and no guidance on
choosing the effective sample sizes. Prior assessment is described only in
outline, and detailed methods are deferred to the 1994 Gaussian paper, which
has no card here: [arXiv:1302.6808](https://arxiv.org/abs/1302.6808)
[arxiv:1302.4957 §6].

## Implementation sketch

The core is the same for both closed forms: a score per child, computed from
counts (discrete) or from marginal terms (Gaussian), plus the log structure
prior. The BDe version below works in logs. Its only inputs are counts and a
prior count table.

```pseudocode
# BDe log score of one structure  [§5.1] [eq. 18] [eq. 19]
# counts[i][j, k] = N_ijk; prior[i][j, k] = N'_ijk  [eq. 19]
# Output: log p(D, H_S | xi), with log p(H_S | xi) added in
def bde_log_score(counts, prior, log_structure_prior):
    total = log_structure_prior              # log p(H_S | xi)  [§2]
    for child in range(len(counts)):
        # N'_ij and N_ij: sums over the child states k  [eq. 19]
        prior_cfg = prior[child].sum(axis=1)
        count_cfg = counts[child].sum(axis=1)
        # Gamma(N'_ij) / Gamma(N'_ij + N_ij), product over j  [eq. 18]
        total += gammaln(prior_cfg).sum()
        total -= gammaln(prior_cfg + count_cfg).sum()
        # Gamma(N'_ijk + N_ijk) / Gamma(N'_ijk), product over j and k
        total += gammaln(prior[child] + counts[child]).sum()
        total -= gammaln(prior[child]).sum()
    return total
```

For the Gaussian case, the same loop applies with each child term replaced by
the difference of two marginal terms, one with the child in the subset and one
without [arxiv:1302.4957 §4 Theorem 6] [eq. 14]. Each marginal term uses the
Wishart degrees of freedom nu = N'_tau - n + l, where l is the subset size
[arxiv:1302.4957 §5.2] [eq. 23].

### Pitfalls

- **Corrected exponent.** The source marks a correction in red, taken from a
  2014 addendum. The corrected marginal degrees of freedom are N'_tau - n + l
  [arxiv:1302.4957 §5.2] [eq. 23]. Code written from older text may use another
  exponent, which the paper does not state as an error; use the corrected form.
- **Scatter matrix undefined.** The posterior scale matrix uses a sample scatter
  matrix S_m whose formula the paper does not write out. It defers that formula
  to the 1994 Gaussian paper [arxiv:1302.4957 §5.2].
- **Empty parent sets.** The child-over-parents ratio needs a term for an empty
  parent set, which the paper does not define. Root nodes need that term to be
  1 [arxiv:1302.4957 §4] [eq. 14]. Check the implementation against this.
- **Zero prior cells.** The BDe closed form takes Gamma(0) when a prior cell is
  zero. The paper's positive-prior assumption on complete structures means each
  cell should stay positive [arxiv:1302.4957 §3] [eq. 18].
- **Choice of reference.** The score does not depend on the reference complete
  structure by Theorem 14 [arxiv:1302.4957 §7.3], but the prior that is assumed
  does depend on it [arxiv:1302.4957 §4] [§5].
- **Numerics.** Products of Gamma functions and determinants overflow for many
  variables. Work in logs. The paper gives no numerical guidance.
- **No validation.** The paper measures nothing about structure recovery,
  predictive accuracy or runtime. Test any implementation on a known network
  before use [arxiv:1302.4957 §5].

## Contradictions

None known. Only one card covers this slug.

## Papers

- [Learning Bayesian Networks: A Unification for Discrete and Gaussian Domains](/papers/1302.4957): derives the Be metric from likelihood equivalence, parameter independence and modularity, and gives the BDe and BGe closed forms with consistency proofs. No experiments.
