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
6 changes: 5 additions & 1 deletion config/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ covariance: true # `covariance.csv`: The [free parameters x free parameters] cov
data: true # `data.json`: The value of every data point in the data.
noise_map: true # `noise_map.json`: The value of every RMS noise map value.

search_log: true # `search.log`: logging produced whilst running the fit method
search_log: true # `search.log`: logging produced whilst running the fit method

# `model.png`: the model figure drawn beside `model.info` (af.ModelPlotter). Opt-in until the
# model-figures epic's phase-3 acceptance renders pass. Unlike other keys an absent key means off.
model_figure: false
90 changes: 90 additions & 0 deletions notebooks/chapter_1_introduction/tutorial_1_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,39 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The same model can also be drawn, via `af.ModelPlotter`.\n",
"\n",
"The figure and the `info` are two views of the same object, and it is worth being precise about the division of\n",
"labour between them. The figure is the **map**: it shows the structure of the model, meaning which component owns\n",
"which parameter and, in the models we build later, which parameters are fixed, shared between components, related to\n",
"one another by an expression or constrained by an assertion. The `info` is the **legend**: it lists the priors and\n",
"values themselves, the numbers that the map has no room for.\n",
"\n",
"For this first model the map is about as simple as a map gets. There is a single card, titled `model` and `Gaussian`\n",
"after the class it was composed from, holding one pill per parameter: `centre`, `normalization` and `sigma`. The\n",
"footer counts them for you, `3 unique sampled scalars`, which is the same number the `total_free_parameters`\n",
"attribute printed above. Read the card as the answer to \"what is this model made of?\", and the `info` above it as the\n",
"answer to \"and what values may each of those parts take?\".\n",
"\n",
"Right now both views fit on one screen and the figure may look like a redundant restatement of the `info`. Draw it\n",
"anyway, because the two views scale very differently. By the end of this chapter our models have five components, in\n",
"chapter 3 they span five datasets at once, and at that point the `info` runs to hundreds of lines whilst the map\n",
"still fits in a glance."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -561,6 +594,25 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Drawing the model shows what a `Collection` does to the map. There are now two cards side by side,\n",
"`gaussian` and `exponential`, each titled with the class it was composed from and each owning its own pills, and the\n",
"footer counts `6 unique sampled scalars` across the pair. Components sit beside one another, and nothing yet joins\n",
"them: the two `centre` parameters are separate parameters that happen to share a name."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -596,6 +648,25 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The figure is identical to the previous one too, and that is the point worth taking from this example. The two ways\n",
"of writing the composition look different on the page, but they build the same structure, and structure is all the\n",
"map draws. Whenever you change how a model is written, draw it: if the map does not move then nothing about the model\n",
"moved either, and any difference between the two fits has to be hiding in the legend rather than in the model."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -764,6 +835,25 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The map shows how a tuple is handled. `centre` is still drawn as one pill, because it is one input argument of the\n",
"`Gaussian2D` class, but it now carries a `2D` badge marking it as a tuple, and the footer counts `4 unique sampled\n",
"scalars` rather than 3. The `paths` printed below unpack that badge into the two entries, one per coordinate, which\n",
"the input vector must supply."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,30 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As in tutorial 1, the model can also be drawn via `af.ModelPlotter`. The figure is the **map** of the model, showing\n",
"its structure, meaning which component owns which parameter, and the `info` above is its **legend**, listing the\n",
"prior placed on each of those parameters.\n",
"\n",
"The map here is the single card we drew in tutorial 1, with a pill for `centre`, `normalization` and `sigma` and a\n",
"footer counting `3 unique sampled scalars`. Those three scalars are exactly the three dimensions of the parameter\n",
"space that the non-linear search is about to explore, so the card is a picture of how large the search's job is. The\n",
"priors discussed below are the legend for that map: they do not change its shape, they set how far along each of its\n",
"three axes the search is allowed to wander."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,35 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Drawing the model makes the jump in complexity easier to see than counting lines of `info` does. The figure is the\n",
"**map** of the model, showing its structure, and the `info` above is the **legend**, listing the priors on every\n",
"parameter.\n",
"\n",
"The five `Gaussian`'s do not appear as five separate cards. Because they are the same component repeated with the\n",
"same priors, they collapse into a single dashed frame badged `5 components` and subtitled `gaussian_0 - gaussian_4`,\n",
"inside which `centre`, `normalization` and `sigma` are each drawn once and badged `independent`, meaning one prior per\n",
"member rather than one prior shared between the members. The legend line below the figure spells that convention\n",
"out, `independent = one prior per member` and `dashed frame = repeated components`, and the footer does the\n",
"arithmetic: `15 unique sampled scalars`, `0 shared priors` and `1 plate standing for 5 components`.\n",
"\n",
"That footer is the difficulty of this tutorial stated in one line. Tutorial 3 searched 3 dimensions; this search has\n",
"15 of them, and parameter space grows in volume so quickly with that number that the same search which comfortably\n",
"found the single `Gaussian` is about to struggle."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -764,6 +793,25 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The map is worth drawing again precisely because it has not changed: the same dashed frame badged `5 components`, the\n",
"same three `independent` pills, the same `15 unique sampled scalars` in the footer. Tuning the priors moved the\n",
"legend, not the map. We are still fitting the same 15 parameter model, we have simply told the search a smaller\n",
"region of it to look in."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -918,6 +966,28 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This time the map itself changes, and it changes in one pill. The `centre` pill inside the frame is now badged\n",
"`shared across group` instead of `independent`, the legend below gains the entry `blue badge = shared prior`, and the\n",
"footer reads `11 unique sampled scalars` and `1 shared prior` where before it read 15 and none.\n",
"\n",
"That is the difference between the two approaches drawn side by side. Tuning the priors left the map alone and\n",
"narrowed the legend; assuming a shared `centre` shrinks the map itself, because four of its parameters have stopped\n",
"existing."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1058,6 +1128,25 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The map is back where it started: one dashed frame badged `5 components`, three `independent` pills, no shared badge\n",
"anywhere and `15 unique sampled scalars` in the footer. Approaches 1 and 2 each changed something that the map or its\n",
"legend could show. This third approach changes neither, because searching parameter space more thoroughly is a\n",
"property of the search, not of the model."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
22 changes: 22 additions & 0 deletions notebooks/chapter_1_introduction/tutorial_7_the_details.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,28 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Draw the model and the problem is already on the page. The figure is the **map** of the model, showing its structure,\n",
"and the `info` above is the **legend**, listing the priors.\n",
"\n",
"The two `Gaussian`'s do not get a card each. Because they are the same component carrying identical priors, they\n",
"collapse into a single dashed frame badged `2 components` and subtitled `gaussian_0 - gaussian_1`, with one\n",
"`independent` pill per parameter. The figure is drawn that way because there is genuinely nothing in the model that\n",
"tells the two apart, which is exactly the property the next few cells are about to exploit."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,30 @@
"cell_type": "code",
"metadata": {},
"source": [
"print(model.info)\n",
"print(model.info)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The model can also be drawn, via `af.ModelPlotter`. The figure is the **map** of the model, showing its structure,\n",
"meaning which component owns which parameter, and the `info` above is the **legend**, naming the prior on each of\n",
"them.\n",
"\n",
"Read against the formalism of this tutorial the map has a precise meaning: the pills on the card are the entries of\n",
"the parameter vector, the footer's `3 unique sampled scalars` is its dimension, and the sum over j in the expression\n",
"above runs over exactly those pills. The prior is one distribution per pill, and the legend is where their names and\n",
"limits live."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(model).figure()\n",
"\n",
"print(\"Log prior of each parameter, theta = [50.0, 25.0, 10.0]:\")\n",
"print(model.log_prior_list_from_vector(vector=[50.0, 25.0, 10.0]))\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,35 @@
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Drawing this model next to tutorial 2's figure shows what the second shared parameter bought us. The figure is the\n",
"**map** of the model, showing which dataset gets which components and which parameters are shared between them, and\n",
"the `info` above is the **legend** of priors.\n",
"\n",
"Two things have changed. The hoisted card at the top is titled `shared across datasets` and subtitled `one value\n",
"across 5 datasets`, and it now holds two `centre` pills rather than one, because each of the two `Gaussian`'s has its\n",
"own shared `centre`. Below it, every dataset is drawn as its own card, `0` through `4`, each containing a\n",
"`gaussian_0` and a `gaussian_1`, and inside them the `centre` pill carries a blue `shared` badge with a line running\n",
"back up to the hoisted card. The `normalization` and `sigma` pills carry no badge and no line, because those\n",
"parameters belong to their own dataset alone.\n",
"\n",
"The footer draws the dimensionality claim made above rather than asserting it: `2 shared across datasets`,\n",
"`4 per dataset \u00d7 5 datasets`, `22 unique sampled scalars`. That is the N=22 of the text, and the map shows where each\n",
"of those numbers comes from."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"af.ModelPlotter(factor_graph.global_prior_model).figure()"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Loading
Loading