Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions notebooks/chapter_1_introduction/tutorial_7_the_details.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,8 @@
"run, that is almost never a statement about which search is better. It is a statement about your parameter space,\n",
"and the degeneracies and flat regions you have accidentally put in it.\n",
"\n",
"Running more than one search tells you about your model, not just your searches!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Running more than one search tells you about your model, not just your searches!\n",
"\n",
"__Clipping__\n",
"\n",
"So far every model has been computable everywhere: any combination of values inside the priors gave a number.\n",
Expand Down Expand Up @@ -1446,13 +1441,8 @@
"the value, because by the time it runs the damage to the derivative is already recorded. Safety has to live where\n",
"the `nan` is created, not where it is detected.\n",
"\n",
"A good likelihood value does not mean a good gradient!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A good likelihood value does not mean a good gradient!\n",
"\n",
"__Hamiltonian Diagnostics__\n",
"\n",
"Tutorial 6 introduced `BlackJAXNUTS`, the Hamiltonian sampler which follows the gradient along a trajectory instead\n",
Expand Down Expand Up @@ -1544,13 +1534,8 @@
"acceptance rate falls, on a model whose parameter space has one of the pathologies we have studied. A degeneracy\n",
"like the flip creates a long narrow ridge, and a trajectory following a ridge whose width changes along its length\n",
"is exactly what makes a trajectory diverge. The diagnostics do not tell you the model is badly parameterized, but\n",
"they are often the first sign of it, and unlike the result itself they do not quietly look fine."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"they are often the first sign of it, and unlike the result itself they do not quietly look fine.\n",
"\n",
"__Unit Cube Vs Physical__\n",
"\n",
"The last detail is the most fundamental, and it changes how you think about every prior you have written.\n",
Expand Down
12 changes: 3 additions & 9 deletions scripts/chapter_1_introduction/tutorial_7_the_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def log_likelihood_function(self, instance) -> float:

print(result_adam.info)

"""
r"""
Put the results side by side. I want to separate two things carefully here: what these particular short runs
actually showed, and what we know about the mechanisms independently of them.

Expand Down Expand Up @@ -838,9 +838,7 @@ def log_likelihood_function(self, instance) -> float:
and the degeneracies and flat regions you have accidentally put in it.

Running more than one search tells you about your model, not just your searches!
"""

r"""
__Clipping__

So far every model has been computable everywhere: any combination of values inside the priors gave a number.
Expand Down Expand Up @@ -1054,17 +1052,15 @@ def model_data_from_instance(self, instance):
print(f"value = {safe(-1.0)}")
print(f"gradient = {jax.grad(safe)(-1.0)}")

"""
r"""
Same value, and now a finite gradient.

The lesson generalizes far beyond this function. A guard that checks the result of a calculation can only protect
the value, because by the time it runs the damage to the derivative is already recorded. Safety has to live where
the `nan` is created, not where it is detected.

A good likelihood value does not mean a good gradient!
"""

r"""
__Hamiltonian Diagnostics__

Tutorial 6 introduced `BlackJAXNUTS`, the Hamiltonian sampler which follows the gradient along a trajectory instead
Expand Down Expand Up @@ -1126,7 +1122,7 @@ def model_data_from_instance(self, instance):
f"Mean acceptance rate = {samples_nuts.samples_info.get('mean_acceptance')}"
)

"""
r"""
On this dataset you should see few or no divergences, an effective sample size which is a decent fraction of the 300
samples drawn, and an acceptance rate near 0.8. That is what a healthy gradient sampler looks like.

Expand All @@ -1135,9 +1131,7 @@ def model_data_from_instance(self, instance):
like the flip creates a long narrow ridge, and a trajectory following a ridge whose width changes along its length
is exactly what makes a trajectory diverge. The diagnostics do not tell you the model is badly parameterized, but
they are often the first sign of it, and unlike the result itself they do not quietly look fine.
"""

"""
__Unit Cube Vs Physical__

The last detail is the most fundamental, and it changes how you think about every prior you have written.
Expand Down
Loading