ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
CollapsedAggMoment.h
Go to the documentation of this file.
1/**
2 * @file CollapsedAggMoment.h
3 * @brief Rao-Blackwellised (collapsed) evaluation of a correlated COUNT / SUM
4 * and of a latent conditioned on such a count.
5 *
6 * The recurring latent-variable relational shape is an aggregate over
7 * probabilistically-selected rows whose selection events are coupled by ONE
8 * shared continuous latent. Conditional on that latent the row indicators are
9 * independent, so the aggregate's moments -- and the posterior of a latent
10 * conditioned on the aggregate -- collapse to a 1-D quadrature over the shared
11 * latent instead of an @c n^k tuple enumeration or a degenerating importance
12 * sampler. See @c CollapsedAggMoment.cpp for the recognised shape.
13 */
14#ifndef PROVSQL_COLLAPSED_AGG_MOMENT_H
15#define PROVSQL_COLLAPSED_AGG_MOMENT_H
16
17#include <optional>
18
19#include "GenericCircuit.h"
20
21namespace provsql {
22
23/**
24 * @brief Collapsed raw moment @c E[C^k] of a correlated COUNT / SUM @p agg,
25 * or @c std::nullopt when the circuit does not match the shared-latent
26 * shape. @c k in @c {1, 2}.
27 */
28std::optional<double>
29aggCollapsedRawMoment(const GenericCircuit &gc, gate_t agg, unsigned k);
30
31/**
32 * @brief Collapsed exact posterior raw moment @c E[R^k | Y = C] for a latent
33 * @p target R conditioned (through the equality event @p event) on a
34 * discrete rv @c Y -- parametrised by @p target -- equalling a
35 * correlated COUNT @c C.
36 *
37 * @p event must be a @c gate_cmp with the @c = operator whose operands are a
38 * parametric discrete @c gate_rv over @p target and a @c gate_agg count. The
39 * count's pmf @c P(C=j) is obtained by the collapse; the posterior is then the
40 * 1-D quadrature
41 * @f$E[R^k|C] = \int r^k f_R(r) L(r)\,dr / \int f_R(r) L(r)\,dr@f$ with
42 * likelihood @f$L(r) = \sum_j P(C=j)\,\mathrm{pmf}_Y(j;\theta(r))@f$ -- exact
43 * up to quadrature, @c O(n^2 + G K). @c std::nullopt on any shape mismatch
44 * (the caller then falls back to importance sampling). @c k in @c {1, 2}.
45 */
46std::optional<double>
47collapsedConditionalMoment(const GenericCircuit &gc, gate_t target,
48 gate_t event, unsigned k);
49
50} // namespace provsql
51
52#endif // PROVSQL_COLLAPSED_AGG_MOMENT_H
gate_t
Strongly-typed gate identifier.
Definition Circuit.h:49
Semiring-agnostic in-memory provenance circuit.
std::optional< double > aggCollapsedRawMoment(const GenericCircuit &gc, gate_t agg, unsigned k)
Collapsed raw moment E[C^k] of a correlated COUNT / SUM agg, or std::nullopt when the circuit does no...
std::optional< double > collapsedConditionalMoment(const GenericCircuit &gc, gate_t target, gate_t event, unsigned k)
Collapsed exact posterior raw moment E[R^k | Y = C] for a latent target R conditioned (through the eq...