prodigy.analysis.result¶
Analysis results (JSON format)¶
build_result() runs an AnalysisSession and turns
everything it recorded into an AnalysisResult. AnalysisResult.to_json()
is the exchange format between Prodigy and its front ends (prodigy analyze --json,
the web GUI, a language server). Its top-level keys:
schema, prodigy_version, status, error,
program variables, parameters, constants, functions, loops, queries
input distribution, engine, normalize, decisions
distribution closed_form, latex, variables, parameters, finite_support, mass,
error_probability, expectations, marginals
bounds kind, residual_mass, explanation
queries kind, expr, value, lower, upper, bound, line, data
loops id, line, cond, strategy, params, kind, residual_mass, certificates, ...
steps, warnings, log, timing
Exact values are strings in Prodigy’s notation; every exact value that is a number also
comes as ..._float.
Sound intervals¶
Each query carries lower and upper. What they mean depends on the strategies that
were used for the loops (bounds.kind):
exact: lower = upper = value.lower: the computed distribution μ_N lies coefficient-wise below the exact output distribution μ, and at most the residual mass r is unaccounted for (mass still inside a loop after the last iteration, summed over all loops). For an event φ, μ_N(φ) ≤ μ(φ) ≤ μ_N(φ) + r. With conditioning, Prodigy divides by D = 1 − (known violation mass); the residual is rescaled by 1/D at the same moment, and μ_N(φ)/D ≤ μ(φ)/(1 − err) ≤ (μ_N(φ) + r)/D still holds, whatever the unaccounted mass does later (terminate in φ, outside φ, violate an observation, or diverge). No termination assumption is involved. Expectations of monotone, non-negative expressions get the lower bound only (the upper bound is ∞ while r > 0).upper: the computed distribution lies coefficient-wise above μ (Park’s lemma); with conditioning the violation mass is over-approximated as well, so values are upper bounds.unknown: no guaranteed direction (e.g. lower and upper approximations were mixed, or a side condition could not be checked); values are reported without interval.
- prodigy_version()[source]¶
The version of prodigy-ppl, taken from the Git tag
v<version>when it was built or installed.It comes from the package metadata, or, when the sources run without being installed, from
prodigy/_version.py, which every build writes (see[tool.hatch.build.hooks.vcs]).- Return type:
- to_sympy(dist)[source]¶
- Parameters:
dist (
Distribution)- Return type:
- to_latex(dist)[source]¶
- Parameters:
dist (
Distribution)- Return type:
- univariate_table(dist, variable, limit, *, kind='exact', residual=0, max_finite_terms=2000)[source]¶
The first
limitcoefficients of the marginal ofvariable.Finite marginals are listed completely (up to
max_finite_termsstates); infinite ones by series expansion around 0.
- joint_table(dist, limit)[source]¶
All states of a finite distribution, sorted, if there are at most
limitof them.
- class QueryResult(kind, expr, value=None, value_float=None, lower=None, lower_float=None, upper=None, upper_float=None, bound='exact', note='', data=dict(), index=0, line=None, column=None)[source]¶
Bases:
objectThe answer to one query of the program (
?Pr,?Ex,!Print, …).- Parameters:
- is_monotone_nonnegative(expr, program=None)[source]¶
True if E[expr] can only grow when probability mass is added, i.e.
expris built from natural/boolean variables and non-negative literals with+,*,/(by a positive literal) and^(by a natural literal).- Parameters:
expr (
VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)- Return type:
- make_interval(value, kind, residual, *, monotone, probability)[source]¶
(lower, upper, bound, note) for a query value, see the module documentation.
- tighten_interval(lower, upper, bound, known)[source]¶
Intersects an interval with bounds known from elsewhere (
None: unknown side).
- finish_query(session, query, *, monotone, probability, known=None)[source]¶
Fills value_float and the interval of
queryfrom the session’s bound state, intersected withknownbounds (e.g. from the strategy of the loop right before the query).- Parameters:
session (
AnalysisSession)query (
QueryResult)monotone (
bool)probability (
bool)
- Return type:
- outline_program(program, source=None)[source]¶
Variables, parameters, loops and queries of
program(for editors and forms).
- type_name(typ)[source]¶
pGCL spelling of a declared type (
nat,nat [0, 5],bool,real, …).- Return type:
- class AnalysisResult(status='ok', error=None, program=None, input=dict(), distribution=None, error_probability=None, error_probability_float=None, bounds=dict(), queries=list(), loops=list(), steps=list(), warnings=list(), log='', timing=dict())[source]¶
Bases:
object- Parameters:
status (
str)queries (
List[QueryResult])log (
str)
- queries: List[QueryResult]¶
- build_result(session)[source]¶
Runs
sessionand collects the result; analysis errors end up in the result.- Parameters:
session (
AnalysisSession)- Return type: