Skip to content

The reveal game

probability_flow.reveal answers a question the rest of the library does not ask: if somebody has been shown only part of a graph, what does that part warrant?

It is an application built on the library, not part of the formalism. Nothing else in probability_flow imports it, and a graph that will never be revealed piecemeal never needs anything on this page.

from probability_flow import reveal
Call What it does
reveal.induce(graph, revealed) The graph somebody has been shown, as an ordinary CausalGraph. revealed is a set of variables or ids.
reveal.composite_baseline(variable) What a node is worth before anything is revealed, in bits.
reveal.project(variable, revealed) Its log-odds in bits given what is revealed so far.
reveal.implicit_distribution(variable) What an unrevealed parent contributes, as a distribution over its states.
reveal.implicit_prior(variable) The same thing as one number, which is the mass not on the first state.
reveal.sigmoid2(bits) Bits of log-odds back to a probability. Here because reaching for 1/(1+exp(-x)) on a number in bits gives a wrong answer that looks plausible.

What induce returns

An ordinary CausalGraph, so observations, virtual evidence and every engine work on it with no second API.

Here is the whole graph, and then the same graph as somebody shown four of its nodes sees it:

The whole graph

The same graph induced on four revealed nodes

The nodes nobody mentioned are not faded out. They are gone, and what they contributed has been folded into the baselines of the nodes that remain. The camera's edge is grey in the second figure because the gate that set its weight was not revealed, so it rests at the weight it would carry with no gate at all.

Virtual evidence rides along with the variable it hangs off. Naming one in revealed on its own is refused rather than silently ignored.

Implicit priors

An implicit prior is what an unrevealed parent contributes. A node states its own in metadata["implicit_prior"], the default is uniform, and the source of a gating edge contributes nothing whatever it says.

It is a distribution over the parent's states, one number per state, exactly as a prior over a three-state variable is three numbers. A binary parent may give a single number instead, which means P(not the first state):

import probability_flow as pf

h = pf.CausalGraph("priors")
binary = h.add_variable("It rained")
weather = h.add_variable("Weather", states=("clear", "rain", "storm"))

binary.metadata["implicit_prior"] = 0.3              # the same as (0.7, 0.3)
weather.metadata["implicit_prior"] = (0.5, 0.3, 0.2)

A single number on a multi-state parent is refused rather than spread, because there is no honest way to divide one number over three states. The additive family reads a vector as the mass that is not on the first state, which is what its indicator means: a parent's weight is added whenever that parent is in any state but its first, so there is no third option to represent.

Two things about it matter more than they look.

It is a stopping condition, not an estimate. It truncates the graph at depth one. An accurate value is not merely undesirable, it is unavailable, because accuracy would mean the parent's true marginal, and computing that needs exactly the traversal the game forbids.

A gate rests at zero, not at one half. At one half an unrevealed gate is already doing half its work, so an edge nobody has mentioned sits at neither its own weight nor its gated one. At zero the gated edge reads exactly as it would with no gate at all.

Two constants say what an unrevealed parent is worth when nothing states it: reveal.DEFAULT_IMPLICIT_PRIOR is 0.5, and reveal.GATE_SOURCE_IMPLICIT_PRIOR is 0.0.

What a partial reveal does to a CPD

A revealed node keeps its real CPD only if all of its parents are revealed too. Otherwise it gets a partially revealed one, with the unrevealed parents folded in at their implicit priors, and which way that fold goes depends on the family rather than on preference.

Additive nodes interpolate in log-odds: substitute the implicit prior into the weight sum. This is exact, because the family is linear in log-odds.

Noisy and logical nodes marginalise in probability space. An unrevealed parent behaves like a present parent of reduced strength. A cause that would fire eighty percent of the time, unrevealed at one half, acts like a present cause firing forty percent.

These are different operations and they do not agree. Which one applies is fixed by the shape of the CPD, not chosen.

Composite baseline

Fold every parent's implicit prior into the baseline and you get one number: what a node is worth before anything about it is revealed.

It is in BITS, not a probability. reveal.composite_baseline(variable) is logit2(baseline) plus the sum over all parents of the implicit prior times the weight, and reveal.sigmoid2 turns it into a credence. On a node with a baseline of 0.5 and two parents at weights 2.0 and 1.4, the composite baseline is 0.7 bits, which is a credence of 0.618976. Reading 0.7 as a probability is the mistake the separate function exists to stop.

It is a constant of the node. It does not move as reveals accumulate. And the number of parents folded into it is not recoverable from it, which is the point: a reader handed that number learns nothing about how much they have not been shown.