Skip to content

@model interface #7

Open
Open

Description

@yebai

The current interface for StanBlocks

earn_height_model = StanBlocks.@slic begin 
    beta ~ flat(;n=2)
    sigma ~ flat(;lower=0.)
    earn ~ normal(beta[1]+beta[2]*to_vector(height), sigma)
end

What are your views on something closer to Stan syntax, i.e. passing parameters, data, etc, explicitly?

# `::Tparams` annotation is optional below
StanBlocks.@model function earn_height_model((;beta, sigma, earn)::Tparams) 
    beta ~ flat(;n=2)
    sigma ~ flat(;lower=0.)
    earn ~ normal(beta[1]+beta[2]*to_vector(height), sigma)
end

This has the advantage of clearer semantics but also inherits slicstan's type inference, i.e. types for variables beta, sigma, and earn can be inferred automatically if not specified. It would also enable sharing the (work-in-progress) of interface from Turing.jl to specify Tparams, although specifying Tparams manually is optional for StanBlocks since parameter types can be inferred safely here.

The downside is that users need to provide (;beta, sigma, earn), but that seems fairly reasonable given the clarity on the model's semantics: (1) model parameters are global within the model block, (2) models are functions of input arguments, including parameters and data, etc.

Note that you can keep both @slic and @model, so there is no dilemma here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions