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

Implementation of the analytical expectation / variance / moment evaluator over scalar RV sub-circuits. More...

#include "Expectation.h"
#include "AnalyticEvaluator.h"
#include "BooleanCircuit.h"
#include "Circuit.h"
#include "CircuitFromMMap.h"
#include "MonteCarloSampler.h"
#include "RandomVariable.h"
#include "RangeCheck.h"
#include "provsql_utils_cpp.h"
#include "semiring/BoolExpr.h"
#include "postgres.h"
#include "fmgr.h"
#include "utils/uuid.h"
#include "provsql_utils.h"
#include "provsql_error.h"
#include <cmath>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
Include dependency graph for Expectation.cpp:

Go to the source code of this file.

Namespaces

namespace  provsql

Functions

double provsql::evaluateBooleanProbability (const GenericCircuit &gc, gate_t boolRoot)
 Probability that the Boolean subcircuit rooted at boolRoot evaluates to true under the tuple-independent probabilistic-database model.
double provsql::compute_expectation (const GenericCircuit &gc, gate_t root, std::optional< gate_t > event_root=std::nullopt)
 Compute \(E[X]\) (or \(E[X \mid A]\) if event_root is set) over the scalar sub-circuit rooted at root.
double provsql::compute_variance (const GenericCircuit &gc, gate_t root, std::optional< gate_t > event_root=std::nullopt)
 Compute \(\mathrm{Var}[X]\) (or \(\mathrm{Var}[X \mid A]\) if event_root is set) over the scalar sub-circuit rooted at root.
double provsql::compute_raw_moment (const GenericCircuit &gc, gate_t root, unsigned k, std::optional< gate_t > event_root=std::nullopt)
 Compute the raw moment \(E[X^k]\) (or \(E[X^k \mid A]\) if event_root is set) for k >= 0.
double provsql::compute_central_moment (const GenericCircuit &gc, gate_t root, unsigned k, std::optional< gate_t > event_root=std::nullopt)
 Compute the central moment \(E[(X - E[X])^k]\) (or \(E[(X - E[X \mid A])^k \mid A]\) if event_root is set).
Datum rv_moment (PG_FUNCTION_ARGS)
 SQL: rv_moment(token uuid, k integer, central boolean, prov uuid DEFAULT gate_one()) -> float8.

Detailed Description

Implementation of the analytical expectation / variance / moment evaluator over scalar RV sub-circuits.

Definition in file Expectation.cpp.

Function Documentation

◆ rv_moment()

Datum rv_moment ( PG_FUNCTION_ARGS )

SQL: rv_moment(token uuid, k integer, central boolean, prov uuid DEFAULT gate_one()) -> float8.

Single C entry point shared by the expected / variance / moment / central_moment SQL functions. The SQL wrappers select the (k, central) pair that matches their semantics:

  • expected(rv, prov): k=1, central=false.
  • variance(rv, prov): k=2, central=true.
  • moment(rv, k, prov): central=false.
  • central_moment(rv, k, prov): central=true.

The prov argument carries the conditioning event: typically the row's provenance() gate after a WHERE predicate folded a gate_cmp into it. When prov resolves to gate_one (the default, or the load-time simplification of any always-true sub-circuit) the unconditional path runs unchanged. Otherwise we load a JOINT circuit reaching both roots, so shared gate_rv leaves collapse to a single gate_t – the property the conditional MC sampler relies on to couple the indicator's draw with the value's draw.

Definition at line 956 of file Expectation.cpp.

Here is the call graph for this function: