Instruction Reference

Summary:

[assume symbol expression]
[observe expression value]
[predict expression]
[forget directive_id]
[freeze directive_id]
[report directive_id]
[force expression value]
[sample expression]
[infer expression]
[start_continuous_inference expression]
[stop_continuous_inference]
[continuous_inference_status]
[clear]
[list_directives]

Directives

The assume, observe, and predict instructions, also called directives, make up the core modeling language of Venture. Each directive contains a modeling expression to be evaluated. At any time, the probabilistic execution trace consists of all directives that have been evaluated and not forgotten. Venture maintains an index of unique identifiers for directives so they can be referred to by other instructions.

  • [assume symbol expression]: declare and initialize a variable.

    Assume evaluates the expression and binds the result to symbol in the global environment.

  • [observe expression value]: condition on observed data.

    The condition constrains the result of expression to be equal to value.

    An expression can only be constrained by an observe directive if its outermost procedure application is the result of a stochastic computation, rather than a deterministic one. For example, [observe (normal 0 1) 0] is valid, but [observe (+ 1 (normal 0 1)) 0] is not, because + is a deterministic function of its arguments.

    observe has no effect on the distribution of values obtained by running the Venture program until the next time infer is invoked.

  • [predict expression]: register a persitent prediction.

    Predict tracks the expression, allowing its value to be reported before or after inference.

    A predict instruction is persistent, in the sense that it becomes part of the program history and will be maintained and potentially resampled during inference. A predict`ed expression may affect the evaluation of later expressions that are correlated or conditionally dependent.  To evaluate an expression non-persistently, use `sample.

Directive manipulation instructions

In addition to the directives themselves, there are instructions forget, freeze, and report which manipulate directives.

  • [forget directive_id]: remove a directive from the program history.

    Further inference will behave as if that directive had never been executed.

    Be careful forget`ting an `assume directive: any functions referring to the symbol that assume had bound will fail with “Symbol not found” errors if executed after the forget.

  • [freeze directive_id]: fix a directive’s current value.

    Freeze removes the directive’s random choices from the program history and fixes the directive to its current value. This instruction is used to gain efficiency for inference strategies in the Sequential Monte Carlo style.

  • [report directive_id]: report the current value of a directive.

    Report does not re-evaluate the expression or otherwise change the program history.

Pseudo-Directives

The force and sample instructions are “pseudo-directives” which have temporary effects on the current program history.

  • [force expression value]: set an expression to a value momentarily.

    Force is a temporary version of observe which is immediately forgotten after incorporating the observation. This has the effect of initializing expression to value without introducing a lasting constraint. In typical use, the expression is just a single variable, which sets that variable to the given value.

  • [sample expression]: make a transient prediction.

    Sample is a temporary version of predict which is immediately forgotten. This has the effect of evaluating expression once, without adding it to the program trace. Therefore, unlike predict, a sample instruction will not be maintained during inference, and sample d expressions will be independent of one another (conditioned on the rest of the program history).

Inference Instructions

By themselves, the modeling directives do not perform any inference. When the directives are initially evaluated, their values will be drawn from the prior, ignoring any observations that have been made. To move from the prior to the posterior, it is necessary to invoke some inference program.

Venture inference is available in two modes: batch (with the infer instruction) and continuous (with start_continuous_inference and stop_continuous_inference).

Both infer and start_continuous_inference take an inference program, which is an expression that specifies what inference strategy to use. In simple cases, this will just amount to a transition count and some parameter settings for some generic inference strategy. For more complex cases, Venture supports user-programmable inference that can capture arbitrarily complex problem-specific insights. The inference expressions are described [below](#inference-expressions).

  • [infer expression]: execute batch inference.

    Infer evaluates an inference expression and executes the specified inference program over the current program trace.

  • [start_continuous_inference expression]: begin inferring continuously.

    Start_continuous_inference is deprecated in favor of the equivalent [infer (loop ...)] idiom.

    Start_continuous_inference evaluates an inference expression and starts repeatedly executing the specified inference strategy continuously in the background. Values can be queried (e.g. with report) while inference is in progress.

  • [stop_continuous_inference]: stop any ongoing continuous inference.

    Stop_continuous_inference is safe to invoke even if continuous inference is not running.

  • [continuous_inference_status]: report the status of continuous inference.

    The continuous_inference_status instruction reports whether continuous inference is currently running, and if so with what inference program.

  • [define symbol expression]: define a reusable inference subroutine.

    A typical use case would be:

    [define proc (lambda (a b)
      (do
        (some inference commmand)
        (some other inference commmand)
        ...))]
    

    whereupon a later infer instruction can invoke proc like any other inference procedure:

    [infer (proc 1 4)]
    

Miscellaneous Instructions

  • [clear]: reset Venture to an empty state.
  • [list_directives]: return a description of all extant directives.