![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
SQL function provsql.rv_histogram(token, bins). More...
#include "postgres.h"#include "fmgr.h"#include "utils/jsonb.h"#include "utils/fmgrprotos.h"#include "utils/uuid.h"#include "provsql_utils.h"#include "provsql_error.h"#include "CircuitFromMMap.h"#include "GenericCircuit.h"#include "MonteCarloSampler.h"#include "RandomVariable.h"#include "RangeCheck.h"#include "provsql_utils_cpp.h"#include <algorithm>#include <cmath>#include <iomanip>#include <optional>#include <sstream>#include <string>#include <utility>#include <vector>
Go to the source code of this file.
Functions | |
| Datum | rv_histogram (PG_FUNCTION_ARGS) |
SQL function provsql.rv_histogram(token, bins).
Returns an empirical histogram of the scalar values produced by the sub-circuit rooted at token, binned into bins equal-width intervals between the observed minimum and maximum. The sample count is taken from provsql.rv_mc_samples; pinning provsql.monte_carlo_seed makes the result reproducible.
Output: a jsonb array of objects {bin_lo, bin_hi, count}, one per non-empty bin (zero-count bins are still emitted so the client can draw a flat baseline). Returning jsonb rather than SETOF record keeps the C++ side free of SRF / FuncCallContext mechanics and matches the pattern used by simplified_circuit_subgraph.
Accepted root gate types:
gate_value: degenerate Dirac at the constant. Emits a single bin at (v, v) with count equal to the would-be sample count, so the client can normalise to a probability mass without a special case.gate_rv: sampled from the leaf's distribution.gate_arith: sampled by recursing through the arithmetic DAG, reusing gate_rv draws within an iteration so shared leaves are correctly correlated.gate_mixture: sampled by recursing through the mixture's Bernoulli (gate_input) wire and the selected scalar branch, reusing per-iteration caches so a shared p_token across the circuit produces coupled draws.Any other gate type raises: probability of a Boolean-valued gate is a scalar that the existing probability_evaluate dispatch covers, and aggregation roots have their own moment family in agg_raw_moment.
Definition in file RvHistogram.cpp.
| Datum rv_histogram | ( | PG_FUNCTION_ARGS | ) |