AI Glossary / Probabilistic machine learning / Intermediate
Probabilistic inference by automatic differentiation
Definition
Probabilistic inference by automatic differentiation uses derivatives of a suitable probability computation to recover quantities such as marginal probabilities or sensitivities. In a classic exact formulation, a discrete probabilistic model is compiled into an arithmetic circuit, evaluated for evidence, and differentiated. The probabilistic meaning comes from the chosen representation, not from differentiation alone.
What it means
Automatic differentiation normally brings to mind training a neural network by calculating loss gradients. Here a derivative can answer an inference question directly. A carefully constructed function encodes the sum of probabilities of assignments compatible with observations; derivatives identify contributions associated with particular variable states.
This does not turn every arbitrary program into an efficient inference engine. The computation must represent the right probability quantity, and its size can be the main obstacle. The term also appears more broadly in differentiable probabilistic computing, so this entry focuses on the exact circuit and evidence-indicator interpretation.
How it works
For a finite discrete distribution, attach an evidence indicator lambda_x to each possible state x of each variable. Construct a sum over complete assignments: each term is its probability multiplied by the indicators for the states in that assignment. Set an indicator to zero when its state conflicts with evidence, and to one when it is compatible. Unknown variables have all their state indicators set to one.
Evaluating this polynomial gives the probability of the evidence. For an unobserved query variable, differentiating with respect to one of its indicators gives the joint probability of that state and the evidence. Dividing by the evidence probability gives the posterior marginal, provided the denominator is positive.
A factored arithmetic circuit can evaluate the function and propagate derivatives efficiently relative to its circuit size. Compilation and representation may nevertheless be expensive. Automatic differentiation supplies the derivative calculation; the polynomial's semantics supplies the probability interpretation.
Three practical examples
- Discrete diagnostic models: compute several posterior state probabilities after entering observed evidence into a compiled representation.
- Repeated inference services: reuse a circuit across evidence patterns when the underlying model structure remains suitable for the compilation.
- Sensitivity analysis: examine derivatives with respect to model parameters, while respecting probability-normalization constraints when interpreting actual parameter changes.
Think of it this way
Think of a ledger that totals the weights of all compatible explanations. An indicator acts like a switch selecting which explanations remain eligible. Differentiation reveals the contribution associated with a particular switch. This is a mathematical analogy: a derivative is not itself a probability in every program, and its meaning depends on how the ledger was constructed.
Worked example
Consider an original joint distribution for binary A and B: P(0,0) = 0.4, P(0,1) = 0.1, P(1,0) = 0.2, and P(1,1) = 0.3. These four entries sum to one.
Its evidence polynomial is F = 0.4 lambda_A0 lambda_B0 + 0.1 lambda_A0 lambda_B1 + 0.2 lambda_A1 lambda_B0 + 0.3 lambda_A1 lambda_B1.
Observe B = 1 and leave A unknown. Set lambda_B0 = 0, lambda_B1 = 1, and both A indicators to 1. Evaluation gives F = 0.1 + 0.3 = 0.4, the probability of B = 1.
The derivative with respect to lambda_A1 is 0.2 lambda_B0 + 0.3 lambda_B1, which evaluates to 0.3. Thus P(A = 1 | B = 1) = 0.3/0.4 = 0.75. The derivative for lambda_A0 evaluates to 0.1, giving posterior probability 0.25. The two posterior probabilities sum to one.
This small example can be differentiated by hand. Automatic differentiation becomes useful when a larger factored computation must propagate many such derivatives consistently.
Illustrative case study
Fictional case: Beacon Diagnostics maintains a discrete model for equipment states and observed indicators. The team considers compiling the model because users repeatedly request several posterior probabilities for different evidence patterns.
Before adopting the approach, it compares circuit results against direct enumeration on a reduced model, including the four-state example above. It then measures compilation cost, memory use, and repeated-query time separately. Impossible evidence receives explicit handling rather than a division by zero. This invented scenario illustrates implementation review, not a report of operational reliability or proof that compilation will be economical for every model.
Common misconceptions and mistakes
Inference derivatives should not be confused with gradients used to fit the model's parameters. Both may use the same differentiation machinery, but the questions and differentiated inputs differ.
An unobserved variable is not encoded by setting all its indicators to zero; that would eliminate every assignment involving it. Also, differentiating after discarding the indicator structure as numeric constants loses the intended query inputs. Finally, linear-time differentiation in circuit size does not remove an exponential compilation or representation bottleneck.
Business use
This approach can be relevant when a business repeatedly queries a stable discrete model and needs several conditional probabilities under changing observations. Its practical advantage depends on whether the model admits a manageable compiled representation.
Document the query semantics, input indicator convention, numerical precision, and behavior for zero-probability evidence. Compare total system cost with alternative inference methods, including the work required after model changes. An exact answer under the encoded model still requires separate assessment of whether that model is credible for the application.
People also ask
Is automatic differentiation the same as numerical finite differences?
No. It propagates derivatives through the operations of the computation, rather than estimating them by subtracting nearby function evaluations.
Does it automatically make inference exact?
Only if the represented computation and derivative interpretation support exact inference; differentiating an approximation generally retains its limitations.
What if the evidence probability is zero?
The ordinary conditional probability ratio is undefined, so the system needs explicit handling rather than returning a fabricated posterior.
Check your understanding
In the worked example, is the derivative 0.3 already P(A = 1 | B = 1)?
Answer: No. It is the joint probability P(A = 1, B = 1). Dividing by the evidence probability 0.4 gives the conditional probability 0.75.
Related terms
- Automatic differentiation
- Bayesian network
- Sensitivity analysis
- arithmetic circuit
- network polynomial
- evidence indicator
- marginal inference
- reverse-mode differentiation
Learn next
Reproduce the four-state polynomial with no evidence, then with one observed variable. Verify derivatives against direct probability sums. Next examine factorization and reverse-mode differentiation, keeping inference-query derivatives distinct from parameter-learning gradients.
More in Probabilistic machine learning
- Potts model - A Potts model is a model of interacting variables that each take one of several categorical states.
- Preconditioned stochastic gradient descent - Preconditioned stochastic gradient descent modifies a stochastic gradient with a matrix before using it to update model parameters.
- Probabilistic circuit - A probabilistic circuit represents a probability distribution through a computational graph of simple functions, weighted sums, and products.
- Probability integral transform - The probability integral transform maps a random variable through its own cumulative distribution function.
- Probability of improvement - Probability of improvement is an acquisition criterion used in Bayesian optimization.
- Prototypical network - A prototypical network is a few-shot classification method that learns an embedding space and represents each class by the mean embedding of its labeled...
Sources
Darwiche, A Differential Approach to Inference in Bayesian Networks, original UAI 2000 paper archived by the author: https://arxiv.org/pdf/1301.3847 Choi, Vergari and Van den Broeck, Probabilistic Circuits: A Unifying Framework for Tractable Probabilistic Models: https://yoojungchoi.github.io/files/ProbCirc20.pdf Darwiche Theorem 2 first-derivative semantics and the probabilistic-circuit marginal discussion were independently consulted.
Previous: Probabilistic inference Next: Probabilistic language model