Uncertainty/Bayesian Networks: Inference and Relational Models

Lesson 4.43,388 words

Bayesian Networks: Inference and Relational Models

When exact inference is intractable, sampling estimates the posterior instead: prior and rejection sampling, likelihood weighting, and Gibbs/MCMC, whose error shrinks as one over the square root of the sample count. The same graphical idea then lifts from a fixed set of variables to whole populations — relational and open-universe probability models write dependencies once and unroll them over objects — and we close by placing probability against the rule-based, Dempster–Shafer, and fuzzy alternatives it displaced.

╌╌╌╌

This builds on Bayesian Networks, which built the burglary network, read compactness and d-separation off the graph, and ran exact inference by variable elimination. That method is linear on polytrees but intractable in general — so we pick up where it fails, first estimating answers by sampling, then stretching the whole formalism to reason about objects it was never told exist.

Approximate inference by sampling

Sampling — Monte Carlo — algorithms trade exactness for tractability: draw many random samples from a distribution related to the network, count outcomes, and read off probabilities as frequencies. Accuracy improves with the number of samples, with the error in each estimate falling as .1

Direct and rejection sampling

The primitive is sampling a network with no evidence. Prior sampling visits the nodes in topological order and, at each one, draws a value from its CPT conditioned on the values already fixed for its parents. One full pass yields one sample from the joint. Counting how often an event occurs across many samples estimates its probability, converging to the true joint value in the limit.

To answer a query with evidence , rejection sampling wraps prior sampling: generate a full sample, discard it unless it agrees with , and tally the query variable over the survivors. It is correct but wasteful — the fraction of samples consistent with the evidence shrinks exponentially as evidence accumulates, so most samples are thrown away, and for anything but a little evidence the method is unusable.

Likelihood weighting

Likelihood weighting removes the waste by never generating an inconsistent sample. It fixes the evidence variables to their observed values and samples only the rest, then weights each sample by the likelihood the evidence accords the network — the product, over evidence variables, of . A sample in which the evidence looks unlikely receives a small weight; every sample counts, but not equally.2

Algorithm:Weighted-Sample(bn,e)\textsc{Weighted-Sample}(bn, \mathbf{e}) — one likelihood-weighted sample and its weight
  1. 1
    input: bnbn, a Bayesian network; e\mathbf{e}, the fixed evidence
  2. 2
    w1w \gets 1
  3. 3
    x\mathbf{x} \gets an event with the evidence variables set from e\mathbf{e}
  4. 4
    for each variable XiX_i in X1,,XnX_1, \ldots, X_n do
  5. 5
    if XiX_i is an evidence variable with value xix_i in e\mathbf{e} then
  6. 6
    wwP(xiparents(Xi))w \gets w \cdot P(x_i \mid \text{parents}(X_i))
  7. 7
    else
  8. 8
    x[i]\mathbf{x}[i] \gets a random sample from P(Xiparents(Xi))\mathbf{P}(X_i \mid \text{parents}(X_i))
  9. 9
    return x\mathbf{x}, ww

Averaging the query counts weighted by gives a consistent estimate: combining the sampling distribution with the weight recovers exactly the true joint . Likelihood weighting uses every sample, so it beats rejection sampling — but it too degrades as evidence grows, because samples end up carrying tiny weights when the evidence sits far downstream, guiding little of the sampling.

Gibbs sampling and MCMC

Markov chain Monte Carlo works differently again: rather than build each sample from scratch, it makes a small random change to the previous one, wandering through the space of complete assignments. Gibbs sampling is the version suited to Bayesian networks. Fix the evidence, initialize the other variables arbitrarily, then repeatedly pick a nonevidence variable and resample it from its distribution given its Markov blanket — the one set of variables that isolates it. Each visited state is a sample; tallying the query variable over the whole walk estimates the posterior.3

Gibbs sampling as a walk over complete states. Evidence variables (shaded) stay fixed; at each step one nonevidence variable is resampled given its Markov blanket, moving to a neighboring state. The long-run fraction of time the walk spends in each state converges to that state's posterior probability.
Algorithm:Gibbs-Ask(X,e,bn,N)\textsc{Gibbs-Ask}(X, \mathbf{e}, bn, N) — approximate inference by Gibbs sampling
  1. 1
    input: XX, the query variable; e\mathbf{e}, the evidence; bnbn; NN, sample count
  2. 2
    N\mathbf{N} \gets a vector of zero counts, one per value of XX
  3. 3
    Z\mathbf{Z} \gets the nonevidence variables of bnbn
  4. 4
    x\mathbf{x} \gets the current state, evidence set from e\mathbf{e}, rest random
  5. 5
    for j=1j = 1 to NN do
  6. 6
    for each ZiZ_i in Z\mathbf{Z} do
  7. 7
    set ZiZ_i in x\mathbf{x} by sampling from P(Zimb(Zi))\mathbf{P}(Z_i \mid mb(Z_i))
  8. 8
    N[x]N[x]+1\mathbf{N}[x] \gets \mathbf{N}[x] + 1
    xx is the value of XX in x\mathbf{x}
  9. 9
    return Normalize(N)\textsc{Normalize}(\mathbf{N})

The walk defines a Markov chain over states whose stationary distribution coincides with the posterior : the long-run fraction of time spent in each state equals its probability. This holds because the transition satisfies detailed balance with that posterior, and resampling from the Markov blanket needs only the variable's own CPT and those of its children, so each step is cheap. Given enough steps, the samples are drawn from the true posterior — a correct answer built incrementally, one variable flip at a time.

Message passing, loopy BP, and variational inference

Variable elimination and the three samplers are AIMA's account, but the graphical models community organizes exact and approximate inference around a different object — message passing on a graph — and it is worth seeing where the two meet.

Exact inference as messages: the junction tree. Pearl's belief propagation (Probabilistic Reasoning in Intelligent Systems, 1988) computes exact posteriors on a polytree by passing two messages along each edge: a message carrying causal support down from parents and a message carrying diagnostic support up from children. Each node combines its incoming messages with its CPT to get its posterior, and every message is computed once, so the whole network is solved in one forward and one backward sweep — linear time, the polytree bound this lesson already met. For a multiply connected network the trick that restores exactness is the junction tree (or clique tree) algorithm of Lauritzen and Spiegelhalter (Journal of the Royal Statistical Society B, 1988): cluster the loopy variables into cliques so the cliques form a tree, then run belief propagation between cliques. This is variable elimination in disguise — the largest clique's size is the treewidth of the graph, and inference is exponential in exactly that width, which is the precise statement of sparse enough that makes exact inference affordable. Koller and Friedman's Probabilistic Graphical Models (2009) develops this clique-tree view as the organizing frame for the whole subject.

Loopy belief propagation. The cheap idea is to run Pearl's message-passing rules on a multiply connected graph anyway, ignoring that they are only exact on trees, and iterate until the messages stop changing. Loopy belief propagation has no guarantee of converging or of giving the right answer when it does, yet Murphy, Weiss, and Jordan (UAI, 1999) showed empirically that it often converges to useful approximate posteriors — and it became the decoding algorithm behind turbo codes and low-density parity-check codes, whose near-Shannon-limit performance is loopy BP running on a code's factor graph. Yedidia, Freeman, and Weiss (2005) later connected its fixed points to the stationary points of the Bethe free energy, explaining when the approximation is good.

Variational inference. The other large family replaces sampling with optimization. Rather than draw from the true posterior , variational inference picks a tractable family of distributions — often a fully factored mean field — and finds the member closest to the posterior by minimizing the KL divergence , equivalently maximizing a lower bound on the evidence (the ELBO). The result is a deterministic estimate rather than a noisy one, and it scales where MCMC mixes too slowly. Jordan, Ghahramani, Jaakkola, and Saul's 1999 introduction (Machine Learning 37) framed the mean-field approach for graphical models, and Blei, Kucukelbir, and McAuliffe's review (Journal of the American Statistical Association, 2017) traces its growth into the default inference method for large Bayesian models. The connection back to deep learning is direct: the variational autoencoder (Kingma and Welling, 2014) is variational inference with the approximating and the generative model both parameterized by neural networks, trained by maximizing the same ELBO — the sampling-versus-optimization choice this lesson draws in miniature, scaled to models with millions of latent variables.

Three routes to a posterior. Exact inference (variable elimination / junction tree) is exponential in the treewidth. Sampling (MCMC, likelihood weighting) trades exactness for noisy estimates that improve with more samples. Variational inference optimizes a tractable to approximate the posterior deterministically. Loopy BP sits between exact and approximate: exact rules run on a loopy graph.

Relational and first-order probability models

Everything so far assumed a fixed cast of variables drawn in advance. Real problems are not so tidy: an online store has thousands of customers and books, and you cannot draw a node for each by hand. The move here mirrors the leap from propositional to first-order logic — write the dependencies once, with logical variables ranging over objects, and let the model expand itself to however many customers and books actually exist.

A Bayesian network is essentially propositional: its set of random variables is fixed and finite, and each has a fixed domain. That is a real limit. First-order logic gained its power over propositional logic by committing to objects and relations and quantifying over them, and we would like probability to gain the same. A model that could speak of all customers, or every book, without naming each in advance, would multiply the range of problems probability can handle.4

Take an online retailer aggregating customer recommendations into an overall quality estimate for each book. The crude answer — average the recommendations — ignores that some customers are kinder than others (they rate mediocre books highly) and some are less honest (they rate for reasons unrelated to quality, say because they work for a publisher). A Bayesian network for one customer recommending one book has depending on , , and . With two customers and two books the network already needs four recommendation nodes, and for realistic numbers of customers and books it is hopeless to draw by hand.

The book-recommendation Bayes net for two customers and two books. Each node depends on that customer's honesty and kindness and that book's quality; the structure repeats identically for every customer-book pair, which is what a first-order language captures in one line.

Relational probability models

The network has enormous repeated structure: every node has the same three kinds of parent, and its CPT is identical across all pairs, as are all the priors, and so on. This is tailor-made for a first-order language. A relational probability model (RPM) has constant, function, and predicate symbols, and a type signature fixing the type of each argument and value:4

The random variables are obtained by instantiating each function on every combination of objects — , , , and so on. Because each type has finitely many instances, the set of variables is finite. The dependencies are written once, with logical variables ranging over objects:

where is one shared table with rows. The RPM's semantics is defined by unrolling: instantiate the dependencies for all known constants to produce an ordinary Bayesian network over the RPM's variables. A template written once thus unfolds into arbitrarily many objects.

An RPM template (top) unrolled over concrete objects (bottom). The single dependency generates one Bayes-net fragment per customer-book pair, all sharing the same CPT; adding objects grows the network but never the specification.

The model refines easily. A context-specific independence lets a variable ignore some parents given certain values of others: a dishonest customer ignores a book's quality, so is independent of and when , and the dependency becomes an if–then–else whose test the inference engine may not know the value of. Layer on more structure — an honest customer who is a fan of a book's author always gives a — and if the author is itself unknown, the system must reason over all possible authors, with acting as a multiplexer selecting which variable influences the recommendation. Uncertainty about , which changes the dependency structure itself, is relational uncertainty. From a model of a few lines, the posterior can infer things like who wrote a book — if three customers who are fans only of author all rate a while others find it dismal, is very likely its author.

Inference by unrolling then running variable elimination is correct but can produce a huge network, and unknown relations give some variables many parents. Three economies help: the repeated substructure makes many elimination factors identical, so caching yields speedups of orders of magnitude; context-specific independence prunes work; and MCMC samples complete possible worlds, in each of which the relational structure is fully known, so relational uncertainty costs no extra network complexity — the sampler simply includes moves that change which author has. A lifted inference, analogous to resolution over propositionalization, would instantiate logical variables only as needed, letting one lifted factor stand for many ground ones.

Open-universe probability models

Database semantics assumes we know exactly which objects exist and can name them unambiguously. That assumption is often false. A book may carry several ISBNs, so aggregating recommendations across the same book is uncertain; a dishonest customer may hold thousands of login IDs (a sibyl attack). More broadly: a vision system does not know what is around the corner or whether it is the same object seen a minute ago; a text system does not know in advance which entities a document mentions or whether Mary, she, and his mother corefer; an analyst hunting spies never knows how many spies there are. These are existence uncertainty (what objects underlie the data) and identity uncertainty (which symbols name the same object), and much of human cognition seems to require exactly this — learning what objects exist and connecting observations, which almost never arrive with unique IDs, to hypothesized objects.

For these we need open-universe probability models (OUPMs) built on the standard semantics of first-order logic, where possible worlds vary in the objects they contain. The trick is to see how a Bayes net defines a unique distribution — it generates a world event by event, in topological order, each event assigning a value to a variable — and to extend that generative view. An RPM extends it to sets of events (the instantiations of a predicate); an OUPM goes further, allowing generative steps that add objects to the world under construction, where the number and type of new objects may depend on those already present. The generated event is now the very existence of an object.

The generative hierarchy. A Bayesian network generates a world by assigning a value to one variable at a time; an RPM assigns values to whole sets of variables (all instantiations of a function); an OUPM additionally generates the existence of objects, so the number of objects is itself uncertain.

One way to write an OUPM is to give conditional distributions over the numbers of objects. To separate customers (real people) from their login IDs, expecting between and customers, use a prior ; honest customers own one ID, dishonest ones between and :

Here is an origin function recording where each generated object came from. Under acyclicity and well-foundedness conditions, such a model defines a unique distribution over possible worlds, and there exist inference algorithms whose answer to any first-order query approaches the true posterior in the limit — though they are delicate: an MCMC sampler cannot enumerate unbounded worlds, so it samples finite partial worlds and includes moves that merge two objects into one or split one into two. The result is that the probability of any first-order sentence is still well defined as a sum over the worlds where it holds,

so open-universe first-order probability lets one small model reason about an unbounded, unknown population of objects — the increase in expressive power that makes vision, text understanding, and intelligence analysis tractable as probabilistic inference.

Other approaches to uncertain reasoning

Probability is the dominant calculus of uncertainty, but AI tried many alternatives, especially during the years (roughly 1975 to 1988) when efficient Bayesian-network algorithms were unknown and the full joint's exponential size seemed to doom the probabilistic approach.5 Three families are worth knowing, if only to see what they trade away.

Rule-based methods attach a fudge factor to each logical rule and combine them by purely local, truth-functional operations — the belief in a function of the beliefs in and alone. Logical rule systems enjoy three properties: locality (rule fires on alone), detachment (a proved is usable regardless of how it was proved), and truth-functionality. None survives contact with uncertainty. Truth-functionality fails because depends on the events, not just their probabilities: with a fair coin, but and , all from operands of probability . Locality and detachment fail because chaining causal and diagnostic rules ( and ) forms a feedback loop that double-counts evidence, and a truth-functional system cannot explain away — seeing the sprinkler on should lower belief in rain, but forward chaining only raises it. The certainty-factors model of the MYCIN medical system worked only by restricting rule sets to be purely diagnostic or purely causal, singly connected, with evidence entered at the roots; outside those bounds it over-counted, and Bayesian networks displaced it.

Dempster–Shafer theory targets the distinction between uncertainty and ignorance. A fair coin and a coin of unknown bias both give , yet the two states of knowledge differ. Rather than a probability, Dempster–Shafer computes a belief function : the probability that the evidence supports. It assigns masses to sets of possible worlds (events), summing to , and is the total mass of events that entail . With no evidence about the coin, and — a skeptical stance. An expert sure the coin is fair gives and likewise for tails, leaving a -point gap: the interval between and bounds the probability of . The gap is also the theory's difficulty — with belief uncommitted over an interval, a decision problem can be posed that the system cannot resolve, since the meaning of masses and their link to utility remains unsettled.

Dempster-Shafer belief for the coin from a magician's pocket, an expert 90 percent sure it is fair. Bel(Heads) = 0.45 and Bel(not Heads) = 0.45 leave a 0.10 gap of uncommitted belief; the interval [Bel(A), 1 - Bel(not A)] = [0.45, 0.55] bounds the probability of heads, rather than fixing it at a single number.

A Bayesian would say no new formalism is needed: model the coin's (a number in ) with a prior reflecting its magician's-pocket provenance and a conditional . If the prior is symmetric about the predicted , the same number as for a coin believed fair — but the two are not treated identically, because the difference shows up in how the posterior over moves after evidence. Three heads barely budge a strong belief in fairness, but shift a magician's-pocket coin sharply toward biased. Ignorance, in the Bayesian view, is expressed by how beliefs would change under future evidence, not by a gap.

Fuzzy logic addresses a different thing entirely: vagueness, not uncertainty. Nate is tall at is not something we are uncertain about — we know his height — the predicate simply has no sharp boundary. Fuzzy set theory gives a truth value in , and fuzzy logic combines them truth-functionally: , , . Being truth-functional, it stumbles the same way rule-based systems do — looks reasonable, but does not, because a truth-functional rule cannot see the anticorrelation between and . Fuzzy control, which maps real-valued inputs to outputs by fuzzy rules, succeeds commercially (transmissions, cameras, shavers), but critics argue the success owes to small rule bases and tunable parameters, the fuzzy operators being incidental to providing a concise smoothly interpolated function.

The two axes these formalisms address. Probability and Dempster-Shafer handle uncertainty (is the proposition true?); fuzzy logic handles vagueness (is the predicate sharply defined?). The axes are orthogonal — a proposition can be certainly-known yet vague, or sharply-defined yet uncertain.

The common point is probability's discipline — carrying dependences and the provenance of evidence rather than collapsing everything into one local number. The truth-functional shortcuts throw that away, and keeping it is what lets a Bayesian model do the work Dempster–Shafer and fuzzy logic each aim at from one side.

Structure is the whole story

One idea recurs throughout. Writing down the direct dependences of a domain as a graph fixes its conditional independences; those independences factor the joint into small local tables, which is what makes the model both compact to store and fast to reason over. Exact inference stays linear precisely when the graph is sparse enough to be a polytree; when it is not, the same structure guides the sampling that approximates the answer. The identical assumption — that the world's dependences are local, so a graph of them stands in for a full joint — reappears in deep learning's structured probabilistic models, where the graph organizes a distribution over thousands of variables that no table could hold. The next lesson lets the network run in time, unrolling the same factorization across a sequence of steps; after that, we attach payoffs and choose actions in making decisions.

Footnotes

  1. Russell & Norvig, AIMA, §14.5, §14.5.1, Figures 14.13–14.14 — Monte Carlo / randomized sampling, prior sampling () generating events in topological order, and rejection sampling for evidence with its exponential rejection rate; error falling as .
  2. Russell & Norvig, AIMA, §14.5.1, Figure 14.15 — likelihood weighting as importance sampling: fixing evidence, sampling nonevidence variables, weighting by the product of evidence likelihoods , consistency of the weighted estimate, and degradation when evidence occurs late in the ordering.
  3. Russell & Norvig, AIMA, §14.5.2, Figure 14.16 — Markov chain Monte Carlo and Gibbs sampling: resampling each nonevidence variable from its Markov blanket , the Markov chain whose stationary distribution is the posterior, ergodicity, and detailed balance.
  4. Russell & Norvig, AIMA, §14.6 — Relational and First-Order Probability Models: the propositional limit of Bayesian networks, the book-recommendation example (Figure 14.17), possible worlds and Equation (14.13) , RPMs with type signatures and shared dependencies (§14.6.2), unrolling, context-specific independence, relational uncertainty (the multiplexer, Figure 14.19), lifted inference, and open-universe models (§14.6.3) with number statements, origin functions, existence/identity uncertainty, sibyl attacks, and merge/split MCMC. 2
  5. Russell & Norvig, AIMA, §14.7 — Other Approaches to Uncertain Reasoning: rule-based methods and the failure of locality, detachment, and truth-functionality (certainty factors and MYCIN, §14.7.1); Dempster–Shafer theory with belief functions, masses, and the belief gap (§14.7.2); and fuzzy set theory / fuzzy logic / fuzzy control as a treatment of vagueness rather than uncertainty (§14.7.3).

╌╌ END ╌╌