Trace Translators

Gen.@readMacro
@read(<source>, <annotation>)

Macro for reading the value of a random choice from an input trace in the Trace Transform DSL.

<source> is of the form <trace>[<addr>] where <trace> is an input trace, and <annotation> is either :discrete or :continuous.

source
Gen.@writeMacro
@write(<destination>, <value>, <annotation>)

Macro for writing the value of a random choice to an output trace in the Trace Transform DSL.

<destination> is of the form <trace>[<addr>] where <trace> is an input trace, and <annotation> is either :discrete or :continuous.

source
Gen.@copyMacro
@copy(<source>, <destination>)

Macro for copying the value of a random choice (or a whole namespace of random choices) from an input trace to an output trace in the Trace Transform DSL.

<destination> is of the form <trace>[<addr>] where <trace> is an input trace, and <annotation> is either :discrete or :continuous.

source
Gen.@tcallMacro
@tcall(ex)

A macro to call a transformation function from inside another transformation fuction.

source
Gen.inverseFunction
b::TraceTransformDSLProgram = inverse(a::TraceTransformDSLProgram)

Obtain the inverse of a bijection that was constructed with the Trace Transform DSL.

The inverse must have been associated with the bijection either via pair_bijections! or [is_involution!])(@ref).

source
Gen.DeterministicTraceTranslatorType
translator = DeterministicTraceTranslator(;
    p_new::GenerativeFunction, p_args::Tuple=();
    new_observations::ChoiceMap=EmptyChoiceMap()
    f::TraceTransformDSLProgram)

Constructor for a deterministic trace translator.

Run the translator with:

(output_trace, log_weight) = translator(input_trace)
source
Gen.GeneralTraceTranslatorType
translator = GeneralTraceTranslator(;
    p_new::GenerativeFunction,
    p_new_args::Tuple = (),
    new_observations::ChoiceMap = EmptyChoiceMap(),
    q_forward::GenerativeFunction,
    q_forward_args::Tuple  = (),
    q_backward::GenerativeFunction,
    q_backward_args::Tuple  = (),
    f::TraceTransformDSLProgram)

Constructor for a general trace translator.

Run the translator with:

(output_trace, log_weight) = translator(input_trace; check=false, prev_observations=EmptyChoiceMap())

Use check to enable a bijection check (this requires that the transform f has been paired with its inverse using `pair_bijections! or is_involution!).

If check is enabled, then prev_observations is a choice map containing the observed random choices in the previous trace.

source
Gen.SimpleExtendingTraceTranslatorType
translator = SimpleExtendingTraceTranslator(;
    p_new_args::Tuple = (),
    p_argdiffs::Tuple = (),
    new_observations::ChoiceMap = EmptyChoiceMap(),
    q_forward::GenerativeFunction,
    q_forward_args::Tuple  = ())

Constructor for a simple extending trace translator.

Run the translator with:

(output_trace, log_weight) = translator(input_trace)
source
Gen.SymmetricTraceTranslatorType
translator = SymmetricTraceTranslator(;
    q::GenerativeFunction,
    q_args::Tuple = (),
    involution::Union{TraceTransformDSLProgram,Function})

Constructor for a symmetric trace translator.

The involution is either constructed via the @transform macro (recommended), or can be provided as a Julia function.

Run the translator with:

(output_trace, log_weight) = translator(input_trace; check=false, observations=EmptyChoiceMap())

Use check to enable the involution check (this requires that the transform f has been marked with is_involution!).

If check is enabled, then observations is a choice map containing the observed random choices, and the check will additionally ensure they are not mutated by the involution.

source