Skip to content

API reference

Everything a consumer calls, grouped by what you are doing rather than by which module it lives in. Weights are in bits throughout. States are referenced by value, never by position.

import probability_flow as pf
from probability_flow import logical, noisy, reveal

Graphs and CPDs builds one and gives it numbers: variables, both kinds of edge, gates, the four CPD families, and the objects the library hands back rather than asks you to construct.

Asking questions is posteriors, observations, virtual evidence, and the three engines you do not normally choose between.

Saving and loading is the interchange format and what a reader does with a version it does not recognise.

Drawing a graph is the figures and the text renderer.

Generating graphs is making them at random with stated properties.

The reveal game is the reveal module: showing somebody part of a graph and asking what the rest is worth. It is an application built on the library rather than part of the formalism, and nothing else here depends on it.

Looking at a graph

Two functions rather than methods on the graph, because they belong to the reader rather than to the model.

Call What it does
pf.to_text(graph, observations=None) Structure, every CPD row and the current beliefs, as text. No dependencies.
pf.render(graph, observations=None, *, styles=None, style=None, ax=None, title=None, dpi=None, **kwargs) A matplotlib figure. Needs the viz extra. Every style keyword goes through **kwargs.

g.render() happens to exist as well. g.to_text() does not. The style keywords, all thirty-five of them, are on Drawing a graph.

The modules

import probability_flow as pf gives you these, and the convention is that you reach through them rather than importing their contents:

Module What is in it
pf.logical And, Or, AtLeast, Exactly, AtMost
pf.noisy Or, And
pf.reveal the reveal game
pf.generation the graph generator
pf.eliminate variable elimination, and cost
pf.junction the junction tree behind marginals
pf.engines engine names and the per-graph ceilings
pf.__version__ the installed version, which is also the schema version