ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
ConjugatePosterior.h File Reference

Exact conjugate-prior posteriors for observe-evidence circuits. More...

#include <optional>
#include "GenericCircuit.h"
#include "RandomVariable.h"
Include dependency graph for ConjugatePosterior.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  provsql

Functions

std::optional< DistributionSpecprovsql::conjugatePosterior (const GenericCircuit &gc, gate_t target, gate_t evidence)
 The exact posterior of target given evidence, as a resolved distribution spec, when the circuit matches the conjugate shape; std::nullopt on any mismatch (the caller falls back to importance sampling).
std::optional< double > provsql::conjugateLogEvidence (const GenericCircuit &gc, gate_t evidence)
 The exact log marginal likelihood \(\ln P(\mathrm{data})\) of a conjugate-shaped evidence circuit; std::nullopt on any shape mismatch or when a rule in the fold has no predictive density (the caller keeps the Monte Carlo mean-weight path).

Detailed Description

Exact conjugate-prior posteriors for observe-evidence circuits.

Recognises conjugate prior/likelihood structure in an and_agg evidence conjunction of gate_observe atoms and computes the latent's posterior in closed form: the posterior of a bare all-literal gate_rv prior, observed through leaves that wire it into one parameter slot, stays in the prior's family with parameters folded one observation at a time through the conjugate-update registry (registerConjugateRule in distributions/Distribution.h).

The recogniser computes exactly the estimand likelihood-weighting importance sampling targets (the IS weight is \(\prod_i f(d_i \mid \theta)\) and the conjugate posterior is the prior times that same product, renormalised), so where it fires only the method changes, never the semantics – exact, deterministic, and available at provsql.rv_mc_samples = 0. Any shape mismatch (a Boolean or gate_cmp evidence factor, a latent reaching the leaf through gate_arith, a registry miss, an out-of-support datum...) declines with std::nullopt and the caller falls back to importance sampling unchanged.

Definition in file ConjugatePosterior.h.