I am trying to use TransformReparam in order to develop a non-centered version of my model. The relevant code is:
with numpyro.handlers.reparam(config={"user_prefs": TransformReparam()}):
user_prefs = numpyro.sample(
"user_prefs",
dist.TransformedDistribution(
dist.Normal(jnp.zeros((n_users, n_categories)), 1.0),
transforms=[
dist.transforms.AffineTransform(user_mus, user_sigmas),
dist.transforms.ExpTransform(),
],
).to_event(1),
)
and I got the error:
File "/Users/fwilhelm/.miniconda3/envs/cf-model/lib/python3.8/site-packages/numpyro/handlers.py", line 497, in process_message
new_fn, value = reparam(msg["name"], msg["fn"], msg["value"])
File "/Users/fwilhelm/.miniconda3/envs/cf-model/lib/python3.8/site-packages/numpyro/infer/reparam.py", line 131, in __call__
assert isinstance(fn, dist.TransformedDistribution)
AssertionError
which is due to the fact that to_event converts the TransformedDistribution into distribution.Independent. The thing is that I need to call to_event on the transformed distribution due to the plate I am using. Reformulating everything without the with numpyro.handlers.reparam context works. Am I doing something wrong here or is this a conceptional error? Could I somehow apply the to_event right after the context is left?
I hope to fix your issue before that.