Soss.jl icon indicating copy to clipboard operation
Soss.jl copied to clipboard

Implement dummy types for distributions

Open kskyten opened this issue 5 years ago • 2 comments

Distributions.jl is not very flexible with respect to argument types. Implementing custom types, which are basically just wrappers for the arguments would allow more flexibility. For example, the following abuse of notation is not currently possible, since Poisson only allows scalar arguments (note that #14 is probably a better option for this)

simple_poisson = @model (α, β, traps) begin
    λ = α .+ β .* traps
    complaints ~ Poisson(λ)
end

These distribution types would also make it possible to separate the code generation for different back ends (Distributions.jl, Stan math, etc.) into different packages.

kskyten avatar Nov 08 '19 19:11 kskyten

Keep an eye out for stan-dev/stanc3#324 as well.

kskyten avatar Nov 08 '19 20:11 kskyten

Right, currently this requires a For. I like the idea of being able to express it more simply, But to keep things simple and lightweight, I try to lean as much as possible on other libraries. To be able to write this, I would need to implement Poisson(::Array). That's not to say that this is out of the question, rather that it wouldn't need to be a core part of Soss.

As you point out, there's also the option of broadcasting. Poisson.(λ::Array) already creates an Array{Poisson}, so adding support for .~ would allow us to write

complaints .~ Poisson.(λ)

I'll comment more on this in #14.

cscherrer avatar Nov 08 '19 23:11 cscherrer