Skip to content

Handler


final class Handler(delaySampling:Boolean, delayExpressions:Boolean)

Event handler.

  • delaySampling: Enable delayed sampling.
  • delayExpressions: Enable delayed expressions.

Events are triggered as code executes. Each event is handled via a call to the currently-installed event handler, which is an object of type Handler.

The events are:

Code Triggers
x ~ p handleAssume
x <~ p handleSimulate
x ~> p handleObserve
factor w handleFactor

After x ~ p, certain operations on x may further trigger events:

Code Triggers
x.value()/x.eval() handleDelaySimulate
x <- y handleDelayObserve

Finally, any manipulations of a Random x that is an interior node on the delayed sampling M-path will require pruning of the path, which will trigger handleDelayPrune.

Member Variables

Name Description
π:Expression<Real>? Log-posterior, if delayed expressions are enabled.
n:Integer Number of arguments.
w:Real Accumulated weight.
delaySampling:Boolean Is delayed sampling enabled?
delayExpressions:Boolean Are delayed expressions enabled?

Member Functions

Name Description
handleAssume Handle an assume event.
handleSimulate Handle a simulate event.
handleSimulate Handle a simulate event.
handleObserve Handle an observe event.
handleObserve Handle an observe event.
handleFactor Handle a factor event.
handleDelaySimulate Handle a delayed simulation event.
handleDelayObserve Handle a delayed observation event.
handleDelayPrune Handle a prune event.
handleDelayPrune Handle a prune event.
peek Evaluate the log-posterior.
args Get value of real arguments.
grad Compute the gradient.
move Move the expression.
label Label generations.
constant Prune generations.

Member Function Details

args

function args() -> Real[_]

Get value of real arguments.

constant

function constant(gen:Integer)

Prune generations.

See also: Expression

grad

function grad() -> Real[_]

Compute the gradient.

handleAssume

function handleAssume<Value>(x:Random<Value>, p:Distribution<Value>) -> Random<Value>

Handle an assume event.

  • x: Random.
  • p: Distribution.

Returns: x.

handleDelayObserve

function handleDelayObserve<Value>(x:Random<Value>)

Handle a delayed observation event.

  • x: Random.

handleDelayPrune

function handleDelayPrune<Value>(p:Distribution<Value>, x:Random<Value>) -> Delay

Handle a prune event.

  • p: Distribution.
  • x: Child of p on M-path.

Returns: Updated distribution.

function handleDelayPrune<Value>(p:Distribution<Value>, x:Value) -> Delay

Handle a prune event.

  • p: Distribution.
  • x: Child of p on M-path.

Returns: Updated distribution.

handleDelaySimulate

function handleDelaySimulate<Value>(x:Random<Value>)

Handle a delayed simulation event.

  • x: Random.

handleFactor

function handleFactor<Arg>(w:Arg)

Handle a factor event.

  • w: Log-weight.

A factor event is triggered by the factor statement.

handleObserve

function handleObserve<Value>(x:Random<Value>, p:Distribution<Value>) -> Random<Value>

Handle an observe event.

  • x: Random.
  • p: Distribution.

Returns: x.

function handleObserve<Value>(x:Value, p:Distribution<Value>) -> Value

Handle an observe event.

  • x: Random.
  • p: Distribution.

Returns: x.

handleSimulate

function handleSimulate<Value>(x:Random<Value>, p:Distribution<Value>) -> Random<Value>

Handle a simulate event.

  • x: Random.
  • p: Distribution.

Returns: x.

function handleSimulate<Value>(p:Distribution<Value>) -> Value

Handle a simulate event.

  • p: Distribution.

Returns: x.

label

function label(gen:Integer)

Label generations.

See also: Expression

move

function move(x:Real[_]) -> Real

Move the expression.

peek

function peek() -> Real

Evaluate the log-posterior.