API
JuliaBUGS.Parser.@bugs
— Macro@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 totrue
, all periods (.
) in the BUGS code are replaced. This is enabled by default.no_enclosure::Bool
: Whentrue
, the parser does not require the BUGS program to be enclosed withinmodel{ ... }
brackets. By default, this is set tofalse
.
JuliaBUGS.compile
— Functioncompile(model_def[, data, initializations])
Compile a BUGS model into a log density problem.
Arguments
model_def::Expr
: The BUGS model definition.data::NamedTuple
orAbstractDict
: The data to be used in the model. If none is passed, the data will be assumed to be empty.initializations::NamedTuple
orAbstractDict
: 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.
JuliaBUGS.BUGSModel
— TypeBUGSModel
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 ofDynamicPPL.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 withsorted_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 inparameters
and the variables in the Markov blanket ofparameters
.g::BUGSGraph
: An instance ofBUGSGraph
, representing the dependency graph of the model.base_model::Union{BUGSModel,Nothing}
: If notNothing
, the model is a conditioned model; otherwise, it's the model returned bycompile
.
JuliaBUGS.ConcreteNodeInfo
— TypeConcreteNodeInfo
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.
JuliaBUGS.BUGSGraph
— TypeBUGSGraph
The BUGSGraph
object represents the graph structure for a BUGS model. It is a type alias for MetaGraphsNext.MetaGraph
with node type specified to ConcreteNodeInfo
.