Skip to content

Define MixedMultivariateDistribution type #27

@itsdfish

Description

@itsdfish

I would like to explore the possibility of defining a type for multialternative SSMs in hopes that this package plays well with Turing and other packages. The package currently works well in most cases. However, it does not work well with predict from Turing, as discussed here.

Here is one idea:

using Distributions
using Turing 
import Distributions: logpdf
import Distributions: loglikelihood
import Base: length

abstract type Mixed <: ValueSupport end 

const MixedMultivariateDistribution = Distribution{Multivariate, Mixed}

abstract type SSM1D <: ContinuousUnivariateDistribution end 

abstract type SSM2D <: MixedMultivariateDistribution end 

This defines MixedMultivariateDistribution which could potentially be used outside of SSMs. The type system is then split into 1D and 2D SSMs, which are abstract types.

The code below shows that this works for basic MCMC sampling. The question is how to get it to work with predict and friends.

# not really 2D, just for illustration
struct MyType{T<:Real} <: SSM2D
    n::Int
    x::T
end

logpdf(d::MyType,data::Int) = logpdf(Binomial(d.n, d.x), data)

loglikelihood(d::MyType,data::Int) = loglikelihood(Binomial(d.n, d.x), data)


@model function my_model(n, k)
    θ ~ Beta(1, 1)
    return k ~ MyType(n, θ)
end

chain = sample(my_model(10, 5), NUTS(), 3_000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions