API

JuliaBUGS.Parser.@bugsMacro
@bugs(program::Expr)
@bugs(program::String; replace_period::Bool=true, no_enclosure::Bool=false)

Constructs a Julia Abstract Syntax Tree (AST) representation of a BUGS program. This macro supports two forms of input: a Julia expression or a string containing the BUGS program code.

  • When provided with a string, the macro parses it as a BUGS program, with optional arguments to control parsing behavior.
  • When given an expression, it performs syntactic checks to ensure compatibility with BUGS syntax.

Arguments for String Input

For the string input variant, the following optional arguments are available:

  • replace_period::Bool: When set to true, all periods (.) in the BUGS code are replaced. This is enabled by default.
  • no_enclosure::Bool: When true, the parser does not require the BUGS program to be enclosed within model{ ... } brackets. By default, this is set to false.
source
JuliaBUGS.compileFunction
compile(model_def[, data, initializations])

Compile a BUGS model into a log density problem.

Arguments

  • model_def::Expr: The BUGS model definition.
  • data::NamedTuple or AbstractDict: The data to be used in the model. If none is passed, the data will be assumed to be empty.
  • initializations::NamedTuple or AbstractDict: The initial values for the model parameters. If none is passed, the parameters will be assumed to be initialized to zero.
  • is_transformed::Bool=true: If true, the model parameters during inference will be transformed to the unconstrained space.

Returns

  • A BUGSModel object representing the compiled model.
source
JuliaBUGS.BUGSModelType
BUGSModel

The BUGSModel object is used for inference and represents the output of compilation. It fully implements the LogDensityProblems.jl interface.

Fields

  • transformed::Bool: Indicates whether the model parameters are in the transformed space.
  • untransformed_param_length::Int: The length of the parameters vector in the original space.
  • transformed_param_length::Int: The length of the parameters vector in the transformed space.
  • untransformed_var_lengths::Dict{VarName,Int}: A dictionary mapping the names of the variables to their lengths in the original space.
  • transformed_var_lengths::Dict{VarName,Int}: A dictionary mapping the names of the variables to their lengths in the transformed space.
  • varinfo::SimpleVarInfo: An instance of DynamicPPL.SimpleVarInfo, which is a dictionary-like data structure that maps both data and values of variables in the model to the corresponding values.
  • parameters::Vector{VarName}: A vector containing the names of the parameters in the model, defined as stochastic variables that are not observed. This vector should be consistent with sorted_nodes.
  • sorted_nodes::Vector{VarName}: A vector containing the names of all the variables in the model, sorted in topological order. In the case of a conditioned model, sorted_nodes include all the variables in parameters and the variables in the Markov blanket of parameters.
  • g::BUGSGraph: An instance of BUGSGraph, representing the dependency graph of the model.
  • base_model::Union{BUGSModel,Nothing}: If not Nothing, the model is a conditioned model; otherwise, it's the model returned by compile.
source
JuliaBUGS.ConcreteNodeInfoType
ConcreteNodeInfo

Defines the information stored in each node of the BUGS graph, encapsulating the essential characteristics and functions associated with a node within the BUGS model's dependency graph.

Fields

  • node_type::VariableTypes: Specifies whether the node is a stochastic or logical variable.
  • node_function_expr::Expr: The node function expression.
  • node_args::Vector{VarName}: A vector containing the names of the variables that are arguments to the node function.
source