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

Error initializing model parameters as constants in GMM #314

Open
mhidalgoaraya opened this issue Jun 4, 2024 · 1 comment
Open

Error initializing model parameters as constants in GMM #314

mhidalgoaraya opened this issue Jun 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mhidalgoaraya
Copy link
Contributor

mhidalgoaraya commented Jun 4, 2024

Hello, I am trying to initialize a simple toy model with the parameters of a GMM (m_s and τ_s ) as point masses, however I get an error
_ERROR: The number of means and precisions in NormalMixture must be at least 2. Got 1 means and 1 precisions._

@model function lGMM_model(y, μx0, τx0)
    
    # Switch 
    θ  = 0.5
    m_s= [0.0, 0.0]
    τ_s = [0.01, 0.001]

    xprior ~ Normal(mean = μx0, precision = τx0)

    c ~ Bernoulli(θ)
    s ~ NormalMixture(switch=c, m=m_s, p=τ_s) 

    x ~ Normal(mean = xprior, precision = 0.01) 
    w  := x + s 
    y ~ Normal(mean = w, precision = 0.01)
end

What is is strange is that the initializantion works if I define the parameters as tuples

m_s= (0.0, 0.0) τ_s = (0.01, 0.001)

@mhidalgoaraya mhidalgoaraya added the bug Something isn't working label Jun 4, 2024
@bvdmitri
Copy link
Member

bvdmitri commented Jun 4, 2024

@wouterwln, the @model macro creates a single constant for m_s instead of an array of individual constants. I'm unsure of the best approach to fix this. Additionally, I'm not certain why it works for tuples. I recommend double-checking if it functions correctly or if it produces arbitrary inference results due to some Julia dispatch magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants