Skip to content

Instantly share code, notes, and snippets.

@O957
Last active May 21, 2024 17:52
Show Gist options
  • Select an option

  • Save O957/9d530e2b19b629e765b3f290723c6c05 to your computer and use it in GitHub Desktop.

Select an option

Save O957/9d530e2b19b629e765b3f290723c6c05 to your computer and use it in GitHub Desktop.
Example for imperative use of Numpyro to retrieve posterior samples and simulate data.

NOTE: This is nearly the same description as given in AFg6K7h4fhy2/declarative_numpyro_example.py

Given observations $$x_i \sim \mathcal{N}(\mu=0, \sigma=3) \quad i=1,2,\dotsc,500$$ and priors $\mu \sim \mathcal{U}(0,3)$ and $\sigma \sim \mathcal{U}(0, 9)$, produce 1000 samples from the posterior distribution.

The output from inferring parameter values from observations:

                mean       std    median      5.0%     95.0%     n_eff     r_hat
        mu      0.15      0.14      0.15     -0.06      0.40    533.38      1.01
     sigma      3.03      0.10      3.03      2.84      3.18    757.94      1.00

Number of divergences: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment