Skip to content

Latest commit

 

History

History
58 lines (50 loc) · 1.93 KB

File metadata and controls

58 lines (50 loc) · 1.93 KB

Selections

A selection represents a set of addresses of random choices. Selections allow users to specify to which subset of the random choices in a trace a given inference operation should apply.

An address that is added to a selection indicates that either the random choice at that address should be included in the selection, or that all random choices made by a generative function traced at that address should be included. For example, consider the following selection:

selection = select(:x, :y)

If we use this selection in the context of a trace of the function baz below, we are selecting two random choices, at addresses :x and :y:

@gen function baz()
    @trace(bernoulli(0.5), :x)
    @trace(bernoulli(0.5), :y)
end

If we use this selection in the context of a trace of the function bar below, we are actually selecting three random choices---the one random choice made by bar at address :x and the two random choices made by foo at addresses :y => :z and :y => :w`:

@gen function foo()
    @trace(normal(0, 1), :z)
    @trace(normal(0, 1), :w)
end
end

@gen function bar()
    @trace(bernoulli(0.5), :x)
    @trace(foo(), :y)
end

There is an abstract type for selections:

Selection

There are various concrete types for selections, each of which is a subtype of Selection. Users can construct selections with the following methods:

select
selectall
complement

The select method returns a selection with concrete type DynamicSelection. The selectall method returns a selection with concrete type AllSelection. The full list of concrete types of selections is shown below. Most users need not worry about these types. Note that only selections of type DynamicSelection are mutable (using push! and set_subselection!).

EmptySelection
AllSelection
HierarchicalSelection
DynamicSelection
StaticSelection