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

[Feature Request] Show params in render_model() #1379

Closed
karm-patel opened this issue Mar 28, 2022 · 1 comment
Closed

[Feature Request] Show params in render_model() #1379

karm-patel opened this issue Mar 28, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@karm-patel
Copy link
Contributor

Hi @fehiepsi and team,

Prof. @nipunbatra explained the issue (in pyro) of rendering params in pyro.render_model() and then I added this feature in pyro (PR). I would like to add the same feature in numpyro.

I have tried to add this feature for numpyro and tested it on some examples. Consider the following model,

def model(data):
    m = numpyro.param("m", jnp.array(0))
    sd = numpyro.param("sd", jnp.array([1]),constraint=constraints.positive)
    lambd = numpyro.sample("lambda",dist.Normal(m,sd))
    with numpyro.plate("N", len(data)):
        numpyro.sample("obs", dist.Exponential(lambd), obs=data)

I have added sample_params and params_constraint keys in dictionary returned by contrib.render.get_model_relations(). I added Provenance Tracking for params in get_model_relations to add values in sample_param.

numpyro.contrib.render.get_model_relations(model,model_args=(data,))

image

data = jnp.ones(10)
numpyro.render_model(model, model_args=(data,), render_distributions=True))

image

I have added optional argument render_params in render_model() to show params in the plot. Also, render_distributions=True shows the constraints of params with distributions of the sample.

numpyro.render_model(model, model_args=(data,), render_params=True, render_distributions=True)

image

@fehiepsi, Can you please review this? if it meets your expectaion, then I would like to create a PR for the same.

@fehiepsi
Copy link
Member

Thanks @karm-patel! The enhancement looks great to me.

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