-
Couldn't load subscription status.
- Fork 15
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Currently, model definition in JuliaBUGS is inconsistent:
- Models defined with
@bugsor@bugs_strrequire an explicit call tocompile(...). - Models defined with
@modelare directly callable and return aBUGSModel.
This inconsistency can be confusing and complicates the implementation.
# @bugs macro
model1 = @bugs begin
x[1:2] ~ dmnorm(mu[:], sigma[:, :])
x[3] ~ dnorm(0, 1)
y = x[1] + x[3]
end
# @bugs_str macro
model2 = @bugs"""
model {
x[1:2] ~ dmnorm(mu[:], sigma[:, :])
x[3] ~ dnorm(0, 1)
y = x[1] + x[3]
}
"""
# @model macro
@model function model3((;x), mu, sigma)
x[1:2] ~ dmnorm(mu[:], sigma[:, :])
x[3] ~ dnorm(0, 1)
y = x[1] + x[3]
endUsage:
# Requires compile(...)
compile(model1, (;mu=[0,0], sigma=[1 0; 0 1]))
compile(model2, (;mu=[0,0], sigma=[1 0; 0 1]))
# Directly callable
model3((;), [0,0], [1 0; 0 1])Unify the API so that all models—whether defined via @bugs, @bugs_str, or @model—return a callable function of the form
model(data::NamedTuple) -> BUGSModel That is, let @bugs and @bugs_str return an anonymous function instead of a static object.
# unified behaviour
m1 = model1((;mu=[0,0], sigma=[1 0; 0 1])) # --> `compile(model1, (;mu=[0,0], sigma=[1 0; 0 1]))`
m2 = model2((;mu=[0,0], sigma=[1 0; 0 1])) # --> `compile(model2, (;mu=[0,0], sigma=[1 0; 0 1]))`
# The current `@model` generated constructor would still work.
# But, this is not available for models defined via `@bugs` and `@bugs_str`
m3 = model3((;), [0,0], [1 0; 0 1])
# all models can be initialised via
initialize!(::BUGSModel, initial_params::NamedTuple)Then, we can remove compile from the export list and keep it only as an internal utility.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request