From d944a1d48d3032491ceef0f5978fac1189f92cc5 Mon Sep 17 00:00:00 2001 From: Elizaveta Semenova Date: Wed, 20 Nov 2024 21:14:20 +0000 Subject: [PATCH] custom distribution with --- 09_intro_to_Numpyro.ipynb | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/09_intro_to_Numpyro.ipynb b/09_intro_to_Numpyro.ipynb index eb64f5e..6f00b22 100644 --- a/09_intro_to_Numpyro.ipynb +++ b/09_intro_to_Numpyro.ipynb @@ -392,16 +392,9 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "sample: 100%|██████████| 1500/1500 [00:01<00:00, 1422.24it/s, 7 steps of size 7.31e-01. acc. prob=0.89]" - ] - }, { "name": "stdout", "output_type": "stream", @@ -413,13 +406,6 @@ "\n", "Number of divergences: 0\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\n" - ] } ], "source": [ @@ -442,7 +428,7 @@ "\n", "\n", "nuts_kernel = NUTS(model)\n", - "mcmc = MCMC(nuts_kernel, num_warmup=500, num_samples=1000)\n", + "mcmc = MCMC(nuts_kernel, num_warmup=500, num_samples=1000, progress_bar=False)\n", "mcmc.run(jax.random.PRNGKey(0), data = data)\n", "\n", "mcmc.print_summary()" @@ -456,14 +442,13 @@ "\n", "The typical elements that we will need to write are model in Numpyro are as follows:\n", "\n", - "- parameters sampled with `numpyro.sample`\n", - "- parameters sampled from any of the available distributsions using, e.g. `dist.Beta(alpha, beta)` \n", - "- likelihood constructed by adding `obs=...` to the sampling statement: `numpyro.sample('obs', dist.Binomial(n, p), obs=h)`\n", - "- the sampling algorithm which we would like to use. NUTS is a good default oprtion: `kernel = NUTS(model)` ,\n", - "- number of warm-up steps, number of iterations, number of chains, e.g. `MCMC(kernel, num_warmup=1000, num_samples=2000, num_chains=4)`,\n", - "- using `Predictive` class we can generate predictions.\n", - "\n", - "\n" + "- sample parameters with `numpyro.sample`,\n", + "- sample parameters from any of the built-in distributsions using, e.g. `dist.Beta(alpha, beta)`,\n", + "- specify likelihood by adding `obs=...` to the sampling statement: `numpyro.sample('obs', dist.Binomial(n, p), obs=h)`,\n", + "- specify a sampling algorithm. NUTS is a good default option: `kernel = NUTS(model)` ,\n", + "- specify number of warm-up steps, number of iterations, number of chains, e.g. `MCMC(kernel, num_warmup=1000, num_samples=2000, num_chains=4)`,\n", + "- use `Predictive` class we can generate predictions,\n", + "- use `numpyro.factor` to implement custom distributions." ] }, {