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

init_strategy does not work with CircularReparam #1614

Open
19MM97 opened this issue Jun 23, 2023 · 1 comment
Open

init_strategy does not work with CircularReparam #1614

19MM97 opened this issue Jun 23, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@19MM97
Copy link

19MM97 commented Jun 23, 2023

Hi!

I am having an issue with initialising a model with the init_by_median() strategy for my MCMC NUTS model.
I am drawing the location parameter of a VonMises distribution from a VonMises prior and I reparam this parameter with CircularReparam().

Working example:

import numpyro
from numpyro import sample, plate
from numpyro.infer import NUTS, MCMC, init_to_median
from numpyro.distributions import VonMises
from numpyro.handlers import reparam
from jax.random import PRNGKey
import jax.numpy as jnp

@numpyro.handlers.reparam(
    config={"loc_1": numpyro.infer.reparam.CircularReparam()}
)
def tst(x):
    loc_1 = sample("loc_1", VonMises(0, 100))
    conc = 2
    
    with plate("plate", len(x)):
        y = sample("y", VonMises(loc_1, conc), obs=x)
    return loc_1

if __name__ == "__main__":
    kernel = NUTS(tst, init_strategy=init_to_median(num_samples=1000))
    mcmc = MCMC(kernel, num_warmup=1, num_samples=10)

    mcmc.warmup(PRNGKey(42), collect_warmup=True, x=jnp.array([1, 2, 3]))

    print(mcmc.get_samples())

Output:

{'loc_1': Array([1.7704213], dtype=float32), 'loc_1_unwrapped': Array([1.7704215], dtype=float32)}

This should be the median of VonMises(0, 100), which is 0. If you remove the reparameterisation, you get exactly this value.

@fehiepsi fehiepsi added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Jun 24, 2023
@fehiepsi
Copy link
Member

As a context, we have a Pyro thread tracking the issue pyro-ppl/pyro#2878

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

No branches or pull requests

2 participants