Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample from mixture of VonMises distribution.(Ungiven Float64) #159

Open
sosuts opened this issue Nov 11, 2019 · 3 comments
Open

Sample from mixture of VonMises distribution.(Ungiven Float64) #159

sosuts opened this issue Nov 11, 2019 · 3 comments

Comments

@sosuts
Copy link

sosuts commented Nov 11, 2019

Hello, I’m a student majoring in biology in Japan.
I usually use Python so I'm very new to Julia...

I am trying to fit my experimental data(~400,000 angles, -pi ~ +pi bimodal) with mixture of von mises distribution.
I want to predict the parameters(mu, kappa, weights) and the number of components.

mydata
# Dict{Symbol,Any} with 1 entry:
  :angle => ....

Below is the model I want to describe.

kappa1 ~ Gamma(alpha=1., beta=1.0)
kappa2 ~ Gamma(alpha=1., beta=1.0)
mu1 ~ VonMises(mu=0, kappa=0.5)
mu2 ~ VonMises(mu=pi, kappa=0.5)
w ~ Dirichlet([0.5, 0.5])
y ~ w[1]*VonMIses(mu=mu1, kappa=kappa1) + w[2]*VonMises(mu=mu2, kappa=kappa2)

What I want is a posterior distribution of kappa, mu, and weights.
From the previous post : Incompatible Initial Value?, it looks like I'm specifying a wrong dimension to those parameters.
However, I can't figure out which code I must fix...

Any suggestions are welcomed.
I'm sorry for very basic qustion.
Thank you in advance.

The following is my code.

using Mamba
using Distributions

model = Model(
    kappa1 = Stochastic(1,
        () -> Gamma(1, 1), 
    ),
    kappa2 = Stochastic(1,
        () -> Gamma(1, 1),
    ), 
    mu1 = Stochastic(1,
        () -> VonMises(0, 0.5), 
    ),
    mu2 = Stochastic(1,
        () -> VonMises(π, 0.5),
    ), 
    w = Stochastic(1, 
        () -> Dirichlet(ones(2))
    ),
    y = Stochastic(1,
        (mu1, mu2, kappa1, kappa2) -> 
        MixtureModel([VonMises(mu1, kappa1), VonMises(mu2, kappa2)], w),
    false),
)
scheme = [NUTS([:y, :kappa1, :kappa2, :mu1, :mu2, :w])]
setsamplers!(model, scheme)

inits = [
  Dict{Symbol, Any}(
        :y => data[:angle],
        :kappa1 => rand(Gamma(1, 1)),
        :kappa2 => rand(Gamma(1, 1)),
        :mu1 => rand(VonMises(0, 0.5)), 
        :mu2 => rand(VonMises(π, 0.5)), 
        :w => [0.5, 0.5]
  )
]
## MCMC Simulations
nuts_inference = mcmc(model, data, inits, 5000, burnin=1000, thin=2, chains=1)

returns

ArgumentError: incompatible initial value for node : kappa2
@sosuts sosuts closed this as completed Nov 17, 2019
@sosuts
Copy link
Author

sosuts commented Nov 21, 2019

I've now encountered another error.
Details are in MCMC of mixture model using Mamba (Julia discourse).

@sosuts sosuts reopened this Nov 21, 2019
@sosuts sosuts changed the title Sample from mixture of VonMises distribution.(Incompatible Initial Value??) Sample from mixture of VonMises distribution.(Ungiven Float64) Nov 21, 2019
@bdeonovic
Copy link
Contributor

Sorry for the late response. This appears to be a problem with Distributions package (the VonMises distribution) and parameter checking. I will look into it today and file a pull request if I can fix it.

@sosuts
Copy link
Author

sosuts commented Dec 7, 2019

Thank you so much for your reply.
I'm sorry for the late response.
I'm glad if it's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants