diff --git a/notebooks/chapter_1_introduction/tutorial_1_models.ipynb b/notebooks/chapter_1_introduction/tutorial_1_models.ipynb index 334d5e5..d1af121 100644 --- a/notebooks/chapter_1_introduction/tutorial_1_models.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_1_models.ipynb @@ -331,24 +331,12 @@ "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", - "the advanced chapter 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." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter." ] }, { @@ -598,10 +586,9 @@ "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." + "A `Collection` holds the `gaussian` and the `exponential` side by side, giving 6 free parameters across the pair.\n", + "Nothing yet joins the two components: their two `centre` parameters are separate parameters that happen to share a\n", + "name." ] }, { @@ -652,10 +639,8 @@ "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." + "The two ways of writing the composition look different on the page, but they build exactly the same model, with the\n", + "same components and the same free parameters." ] }, { @@ -839,10 +824,9 @@ "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." + "`centre` is one input argument of the `Gaussian2D` class, but because it is a tuple it contributes two free\n", + "parameters rather than one, so this model has 4 free parameters rather than 3. The `paths` printed below unpack the\n", + "tuple into its two entries, one per coordinate, which the input vector must supply." ] }, { diff --git a/notebooks/chapter_1_introduction/tutorial_3_non_linear_search.ipynb b/notebooks/chapter_1_introduction/tutorial_3_non_linear_search.ipynb index bfe0963..1b57dad 100644 --- a/notebooks/chapter_1_introduction/tutorial_3_non_linear_search.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_3_non_linear_search.ipynb @@ -362,15 +362,16 @@ "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." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter.\n", + "\n", + "The model's three free parameters are the three dimensions of the parameter space that the non-linear search is\n", + "about to explore, which is a measure of how large the search's job is. The priors discussed below do not change that\n", + "dimensionality, they set how far along each of those three axes the search is allowed to wander." ] }, { diff --git a/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb b/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb index 997d266..8d28320 100644 --- a/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb @@ -438,20 +438,15 @@ "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", + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\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", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter.\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." + "Tutorial 3 searched 3 dimensions, whereas this model has 15 of them. Parameter space grows in volume so quickly with\n", + "that number that the same search which comfortably found the single `Gaussian` is about to struggle." ] }, { @@ -797,10 +792,8 @@ "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." + "Tuning the priors changed no part of the model itself: it is still the same 5 `Gaussian`'s and the same 15 free\n", + "parameters. We have simply told the search a smaller region of parameter space to look in." ] }, { @@ -970,13 +963,11 @@ "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", + "This time the model itself changes. The `centre` is now shared across the five `Gaussian`'s instead of being\n", + "independent, so there are 11 free parameters and 1 shared prior where before there were 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." + "That is the difference between the two approaches. Tuning the priors narrowed where the search looks, whereas\n", + "assuming a shared `centre` shrinks the model itself, because four of its parameters have stopped existing." ] }, { @@ -1132,10 +1123,9 @@ "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." + "The model is back where it started: five `Gaussian`'s with independent parameters and 15 free parameters.\n", + "Approaches 1 and 2 each changed the model or its priors, whereas this third approach changes neither, because\n", + "searching parameter space more thoroughly is a property of the search and not of the model." ] }, { diff --git a/notebooks/chapter_1_introduction/tutorial_7_the_details.ipynb b/notebooks/chapter_1_introduction/tutorial_7_the_details.ipynb index 3a87180..f9c61b0 100644 --- a/notebooks/chapter_1_introduction/tutorial_7_the_details.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_7_the_details.ipynb @@ -379,13 +379,12 @@ "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", + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\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." + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter." ] }, { diff --git a/notebooks/chapter_1_introduction/tutorial_optional_bayesian_formalism.ipynb b/notebooks/chapter_1_introduction/tutorial_optional_bayesian_formalism.ipynb index 6c27411..ba26409 100644 --- a/notebooks/chapter_1_introduction/tutorial_optional_bayesian_formalism.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_optional_bayesian_formalism.ipynb @@ -401,14 +401,15 @@ "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." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter.\n", + "\n", + "The three free parameters are the entries of the parameter vector, their number is its dimension, and the sum over j\n", + "in the expression above runs over exactly those parameters, with one prior distribution for each of them." ] }, { diff --git a/notebooks/chapter_advanced/tutorial_2_graphical_model.ipynb b/notebooks/chapter_advanced/tutorial_2_graphical_model.ipynb index 0bc39a3..e24ae01 100644 --- a/notebooks/chapter_advanced/tutorial_2_graphical_model.ipynb +++ b/notebooks/chapter_advanced/tutorial_2_graphical_model.ipynb @@ -367,23 +367,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can also draw the model, via `af.ModelPlotter`. The figure is the **map** of the model and the `info` printed above\n", - "is its **legend**: the map shows the structure, meaning which dataset gets which component and which parameters are\n", - "shared between them, whereas the `info` lists the priors and values themselves.\n", - "\n", - "Look for three things in the figure. The five datasets do not appear as five repeated cards: because every dataset is\n", - "fitted by the same `Gaussian` model they collapse into one dashed plate badged with the number of datasets, which is\n", - "the picture of \"this structure repeats\". The shared `centre` is lifted out of that plate into its own card above it,\n", - "with the plate linked back to it, so the single shared parameter is drawn once rather than five times. The observed\n", - "data enters as its own pill, coloured as an observation and therefore distinguishable at a glance from the free\n", - "priors beside it.\n", - "\n", - "This is worth dwelling on, because it is exactly the claim the text struggles to make. Written down, \"a shared\n", - "`centre`\" and \"a `centre` per dataset\" are three words apart, and in the `info` above the whole distinction is carried\n", - "by an index range, the shared `centre` being printed once under a `0 - 4` heading instead of once per dataset. In the\n", - "figure they are two different pictures: a hoisted card the plate points back at, or a `centre` pill sitting inside the\n", - "plate exactly as `normalization` and `sigma` do. If you can read that difference off the map, you can read a\n", - "graphical model." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter.\n", + "\n", + "In the `info` above, the whole distinction between a `centre` shared by every dataset and a `centre` per dataset is\n", + "carried by an index range, the shared `centre` being printed once under a `0 - 4` heading instead of once per\n", + "dataset." ] }, { diff --git a/notebooks/chapter_advanced/tutorial_3_graphical_benefits.ipynb b/notebooks/chapter_advanced/tutorial_3_graphical_benefits.ipynb index 6265db0..0df29b3 100644 --- a/notebooks/chapter_advanced/tutorial_3_graphical_benefits.ipynb +++ b/notebooks/chapter_advanced/tutorial_3_graphical_benefits.ipynb @@ -549,20 +549,12 @@ "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." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter." ] }, { diff --git a/notebooks/chapter_advanced/tutorial_4_hierachical_models.ipynb b/notebooks/chapter_advanced/tutorial_4_hierachical_models.ipynb index c61afc6..255bc23 100644 --- a/notebooks/chapter_advanced/tutorial_4_hierachical_models.ipynb +++ b/notebooks/chapter_advanced/tutorial_4_hierachical_models.ipynb @@ -378,19 +378,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Drawing this model with `af.ModelPlotter` and putting it next to the figure from tutorial 2 is the fastest way to see\n", - "what changed, because the two models say opposite things with almost the same words.\n", - "\n", - "In tutorial 2 the `centre` was hoisted into a card of its own and the plate pointed back at it: one prior object, one\n", - "number, shared. Here every dataset keeps its own `centre`, so it stays inside the plate as a `drawn` pill badged with\n", - "the hierarchical factor it came from, and the violet arrow comes from that factor's card and lands on the pill. There\n", - "is no shared badge anywhere on this figure. The arrow is making the weaker and more realistic claim: these centres\n", - "were drawn from a common population, they are not the same number.\n", - "\n", - "The footer makes the accounting explicit too, counting the parent distribution's `mean` and `sigma` as\n", - "hyper-parameters separately from the parameters belonging to each dataset. That is the split that matters when you\n", - "ask what a hierarchical model actually buys you: the hyper-parameters are the handful of numbers the whole sample\n", - "informs, and the figure is where you can see how few of them there are." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter.\n", + "\n", + "The hierarchical model says something different from tutorial 2's shared model, in almost the same words. In\n", + "tutorial 2 the `centre` was a single shared prior: one object, one number, common to every dataset. Here every\n", + "dataset keeps its own `centre`, and those centres are drawn from a parent distribution whose `mean` and `sigma` are\n", + "themselves parameters of the fit. That is the weaker and more realistic claim: these centres came from a common\n", + "population, they are not the same number.\n", + "\n", + "Those two hyper-parameters are counted separately from the parameters belonging to each dataset, and that split is\n", + "what a hierarchical model buys you: the hyper-parameters are the handful of numbers the whole sample informs." ] }, { diff --git a/notebooks/chapter_advanced/tutorial_5_expectation_propagation.ipynb b/notebooks/chapter_advanced/tutorial_5_expectation_propagation.ipynb index fd4224f..3081c09 100644 --- a/notebooks/chapter_advanced/tutorial_5_expectation_propagation.ipynb +++ b/notebooks/chapter_advanced/tutorial_5_expectation_propagation.ipynb @@ -363,18 +363,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Drawing the model shows the graph that EP is about to sweep. The figure is the **map**, showing which dataset gets\n", - "which components and what joins them, and the `info` above is the **legend** of priors.\n", - "\n", - "There are four cards. The first three, `0` to `2`, are the `AnalysisFactor`'s, one per dataset, each holding a\n", - "`gaussian` card with its `centre`, `normalization` and `sigma` pills. The fourth card, numbered `3`, is the\n", - "`linear_regression` factor, and its pills are drawn in orange rather than as plain free priors because they are not\n", - "free parameters at all: each one shows the expression it is computed from, a constant times that dataset's\n", - "`gaussian.sigma`, which is the FWHM we built out of `fwhm_list` above. The legend names this kind of pill,\n", - "`relation (expression shown)`, and a line runs from each dataset's `sigma` into the relation built on it.\n", - "\n", - "Those lines are the thing to hold on to for the rest of the tutorial. EP never fits this whole map in one go. It\n", - "visits one card at a time, and the lines drawn here are the paths its messages travel along." + "The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n", + "\n", + "The figure shows how the model is organized: which parameters belong to each component, and whether they are free,\n", + "fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the\n", + "corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed\n", + "parameter.\n", + "\n", + "EP never fits this whole model in one go. It visits one factor at a time, passing messages along the links between\n", + "the factors, and those messages are what the rest of this tutorial follows." ] }, { @@ -479,8 +476,8 @@ "Until that `info` exists, the figure is how we read an EP fit back. `af.EPPlotter` draws the same factor graph as\n", "before, but now with the state of the run painted onto it.\n", "\n", - "The graph it draws is not the map we drew earlier, it is the factor graph itself, and its legend says how to read\n", - "it: `box = factor`, `pill = variable`, `dashed frame = repeated structure`. Every `AnalysisFactor` is a box, every\n", + "The graph it draws is not the model figure we drew earlier, it is the factor graph itself, and its legend says how\n", + "to read it: `box = factor`, `pill = variable`, `dashed frame = repeated structure`. Every `AnalysisFactor` is a box, every\n", "parameter it touches is a pill, and an edge between them means \"this factor has something to say about this\n", "variable\". That is the picture the message passing above lives on: a message leaves a box, arrives at a pill, and is\n", "read by every other box attached to it. The three datasets sit inside a dashed plate badged `3 datasets`, drawn once\n", diff --git a/scripts/chapter_1_introduction/tutorial_1_models.py b/scripts/chapter_1_introduction/tutorial_1_models.py index 541ec02..e7e8758 100644 --- a/scripts/chapter_1_introduction/tutorial_1_models.py +++ b/scripts/chapter_1_introduction/tutorial_1_models.py @@ -234,24 +234,12 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: print(model.info) """ -The same model can also be drawn, via `af.ModelPlotter`. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. -The figure and the `info` are two views of the same object, and it is worth being precise about the division of -labour between them. The figure is the **map**: it shows the structure of the model, meaning which component owns -which parameter and, in the models we build later, which parameters are fixed, shared between components, related to -one another by an expression or constrained by an assertion. The `info` is the **legend**: it lists the priors and -values themselves, the numbers that the map has no room for. - -For this first model the map is about as simple as a map gets. There is a single card, titled `model` and `Gaussian` -after the class it was composed from, holding one pill per parameter: `centre`, `normalization` and `sigma`. The -footer counts them for you, `3 unique sampled scalars`, which is the same number the `total_free_parameters` -attribute printed above. Read the card as the answer to "what is this model made of?", and the `info` above it as the -answer to "and what values may each of those parts take?". - -Right now both views fit on one screen and the figure may look like a redundant restatement of the `info`. Draw it -anyway, because the two views scale very differently. By the end of this chapter our models have five components, in -the advanced chapter they span five datasets at once, and at that point the `info` runs to hundreds of lines whilst the map -still fits in a glance. +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. """ af.ModelPlotter(model).figure() @@ -403,10 +391,9 @@ def model_data_from(self, xvalues: np.ndarray): print(model.info) """ -Drawing the model shows what a `Collection` does to the map. There are now two cards side by side, -`gaussian` and `exponential`, each titled with the class it was composed from and each owning its own pills, and the -footer counts `6 unique sampled scalars` across the pair. Components sit beside one another, and nothing yet joins -them: the two `centre` parameters are separate parameters that happen to share a name. +A `Collection` holds the `gaussian` and the `exponential` side by side, giving 6 free parameters across the pair. +Nothing yet joins the two components: their two `centre` parameters are separate parameters that happen to share a +name. """ af.ModelPlotter(model).figure() @@ -424,10 +411,8 @@ def model_data_from(self, xvalues: np.ndarray): print(model.info) """ -The figure is identical to the previous one too, and that is the point worth taking from this example. The two ways -of writing the composition look different on the page, but they build the same structure, and structure is all the -map draws. Whenever you change how a model is written, draw it: if the map does not move then nothing about the model -moved either, and any difference between the two fits has to be hiding in the legend rather than in the model. +The two ways of writing the composition look different on the page, but they build exactly the same model, with the +same components and the same free parameters. """ af.ModelPlotter(model).figure() @@ -524,10 +509,9 @@ def __init__( print(model.info) """ -The map shows how a tuple is handled. `centre` is still drawn as one pill, because it is one input argument of the -`Gaussian2D` class, but it now carries a `2D` badge marking it as a tuple, and the footer counts `4 unique sampled -scalars` rather than 3. The `paths` printed below unpack that badge into the two entries, one per coordinate, which -the input vector must supply. +`centre` is one input argument of the `Gaussian2D` class, but because it is a tuple it contributes two free +parameters rather than one, so this model has 4 free parameters rather than 3. The `paths` printed below unpack the +tuple into its two entries, one per coordinate, which the input vector must supply. """ af.ModelPlotter(model).figure() diff --git a/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py b/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py index 58af460..7d79d3d 100644 --- a/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py +++ b/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py @@ -265,15 +265,16 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: print(model.info) """ -As in tutorial 1, the model can also be drawn via `af.ModelPlotter`. The figure is the **map** of the model, showing -its structure, meaning which component owns which parameter, and the `info` above is its **legend**, listing the -prior placed on each of those parameters. - -The map here is the single card we drew in tutorial 1, with a pill for `centre`, `normalization` and `sigma` and a -footer counting `3 unique sampled scalars`. Those three scalars are exactly the three dimensions of the parameter -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 -priors discussed below are the legend for that map: they do not change its shape, they set how far along each of its -three axes the search is allowed to wander. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. + +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. + +The model's three free parameters are the three dimensions of the parameter space that the non-linear search is +about to explore, which is a measure of how large the search's job is. The priors discussed below do not change that +dimensionality, they set how far along each of those three axes the search is allowed to wander. """ af.ModelPlotter(model).figure() diff --git a/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py b/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py index 6b6b98a..39a0b34 100644 --- a/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py +++ b/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py @@ -309,20 +309,15 @@ def model_data_from_instance(self, instance): print(model.info) """ -Drawing the model makes the jump in complexity easier to see than counting lines of `info` does. The figure is the -**map** of the model, showing its structure, and the `info` above is the **legend**, listing the priors on every -parameter. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. -The five `Gaussian`'s do not appear as five separate cards. Because they are the same component repeated with the -same priors, they collapse into a single dashed frame badged `5 components` and subtitled `gaussian_0 - gaussian_4`, -inside which `centre`, `normalization` and `sigma` are each drawn once and badged `independent`, meaning one prior per -member rather than one prior shared between the members. The legend line below the figure spells that convention -out, `independent = one prior per member` and `dashed frame = repeated components`, and the footer does the -arithmetic: `15 unique sampled scalars`, `0 shared priors` and `1 plate standing for 5 components`. +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. -That footer is the difficulty of this tutorial stated in one line. Tutorial 3 searched 3 dimensions; this search has -15 of them, and parameter space grows in volume so quickly with that number that the same search which comfortably -found the single `Gaussian` is about to struggle. +Tutorial 3 searched 3 dimensions, whereas this model has 15 of them. Parameter space grows in volume so quickly with +that number that the same search which comfortably found the single `Gaussian` is about to struggle. """ af.ModelPlotter(model).figure() @@ -569,10 +564,8 @@ def model_data_from_instance(self, instance): print(model.info) """ -The map is worth drawing again precisely because it has not changed: the same dashed frame badged `5 components`, the -same three `independent` pills, the same `15 unique sampled scalars` in the footer. Tuning the priors moved the -legend, not the map. We are still fitting the same 15 parameter model, we have simply told the search a smaller -region of it to look in. +Tuning the priors changed no part of the model itself: it is still the same 5 `Gaussian`'s and the same 15 free +parameters. We have simply told the search a smaller region of parameter space to look in. """ af.ModelPlotter(model).figure() @@ -687,13 +680,11 @@ def model_data_from_instance(self, instance): print(model.info) """ -This time the map itself changes, and it changes in one pill. The `centre` pill inside the frame is now badged -`shared across group` instead of `independent`, the legend below gains the entry `blue badge = shared prior`, and the -footer reads `11 unique sampled scalars` and `1 shared prior` where before it read 15 and none. +This time the model itself changes. The `centre` is now shared across the five `Gaussian`'s instead of being +independent, so there are 11 free parameters and 1 shared prior where before there were 15 and none. -That is the difference between the two approaches drawn side by side. Tuning the priors left the map alone and -narrowed the legend; assuming a shared `centre` shrinks the map itself, because four of its parameters have stopped -existing. +That is the difference between the two approaches. Tuning the priors narrowed where the search looks, whereas +assuming a shared `centre` shrinks the model itself, because four of its parameters have stopped existing. """ af.ModelPlotter(model).figure() @@ -794,10 +785,9 @@ def model_data_from_instance(self, instance): print(model.info) """ -The map is back where it started: one dashed frame badged `5 components`, three `independent` pills, no shared badge -anywhere and `15 unique sampled scalars` in the footer. Approaches 1 and 2 each changed something that the map or its -legend could show. This third approach changes neither, because searching parameter space more thoroughly is a -property of the search, not of the model. +The model is back where it started: five `Gaussian`'s with independent parameters and 15 free parameters. +Approaches 1 and 2 each changed the model or its priors, whereas this third approach changes neither, because +searching parameter space more thoroughly is a property of the search and not of the model. """ af.ModelPlotter(model).figure() diff --git a/scripts/chapter_1_introduction/tutorial_7_the_details.py b/scripts/chapter_1_introduction/tutorial_7_the_details.py index 2258498..e0acb92 100644 --- a/scripts/chapter_1_introduction/tutorial_7_the_details.py +++ b/scripts/chapter_1_introduction/tutorial_7_the_details.py @@ -271,13 +271,12 @@ def log_likelihood_function(self, instance) -> float: print(model.info) """ -Draw the model and the problem is already on the page. The figure is the **map** of the model, showing its structure, -and the `info` above is the **legend**, listing the priors. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. -The two `Gaussian`'s do not get a card each. Because they are the same component carrying identical priors, they -collapse into a single dashed frame badged `2 components` and subtitled `gaussian_0 - gaussian_1`, with one -`independent` pill per parameter. The figure is drawn that way because there is genuinely nothing in the model that -tells the two apart, which is exactly the property the next few cells are about to exploit. +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. """ af.ModelPlotter(model).figure() diff --git a/scripts/chapter_1_introduction/tutorial_optional_bayesian_formalism.py b/scripts/chapter_1_introduction/tutorial_optional_bayesian_formalism.py index 64ac91f..dc1a819 100644 --- a/scripts/chapter_1_introduction/tutorial_optional_bayesian_formalism.py +++ b/scripts/chapter_1_introduction/tutorial_optional_bayesian_formalism.py @@ -271,14 +271,15 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: print(model.info) """ -The model can also be drawn, via `af.ModelPlotter`. The figure is the **map** of the model, showing its structure, -meaning which component owns which parameter, and the `info` above is the **legend**, naming the prior on each of -them. - -Read against the formalism of this tutorial the map has a precise meaning: the pills on the card are the entries of -the parameter vector, the footer's `3 unique sampled scalars` is its dimension, and the sum over j in the expression -above runs over exactly those pills. The prior is one distribution per pill, and the legend is where their names and -limits live. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. + +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. + +The three free parameters are the entries of the parameter vector, their number is its dimension, and the sum over j +in the expression above runs over exactly those parameters, with one prior distribution for each of them. """ af.ModelPlotter(model).figure() diff --git a/scripts/chapter_advanced/tutorial_2_graphical_model.py b/scripts/chapter_advanced/tutorial_2_graphical_model.py index 0a7a102..48c00f1 100644 --- a/scripts/chapter_advanced/tutorial_2_graphical_model.py +++ b/scripts/chapter_advanced/tutorial_2_graphical_model.py @@ -214,23 +214,16 @@ print(factor_graph.global_prior_model.info) """ -We can also draw the model, via `af.ModelPlotter`. The figure is the **map** of the model and the `info` printed above -is its **legend**: the map shows the structure, meaning which dataset gets which component and which parameters are -shared between them, whereas the `info` lists the priors and values themselves. - -Look for three things in the figure. The five datasets do not appear as five repeated cards: because every dataset is -fitted by the same `Gaussian` model they collapse into one dashed plate badged with the number of datasets, which is -the picture of "this structure repeats". The shared `centre` is lifted out of that plate into its own card above it, -with the plate linked back to it, so the single shared parameter is drawn once rather than five times. The observed -data enters as its own pill, coloured as an observation and therefore distinguishable at a glance from the free -priors beside it. - -This is worth dwelling on, because it is exactly the claim the text struggles to make. Written down, "a shared -`centre`" and "a `centre` per dataset" are three words apart, and in the `info` above the whole distinction is carried -by an index range, the shared `centre` being printed once under a `0 - 4` heading instead of once per dataset. In the -figure they are two different pictures: a hoisted card the plate points back at, or a `centre` pill sitting inside the -plate exactly as `normalization` and `sigma` do. If you can read that difference off the map, you can read a -graphical model. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. + +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. + +In the `info` above, the whole distinction between a `centre` shared by every dataset and a `centre` per dataset is +carried by an index range, the shared `centre` being printed once under a `0 - 4` heading instead of once per +dataset. """ af.ModelPlotter(factor_graph.global_prior_model).figure() diff --git a/scripts/chapter_advanced/tutorial_3_graphical_benefits.py b/scripts/chapter_advanced/tutorial_3_graphical_benefits.py index bab98f8..00c9437 100644 --- a/scripts/chapter_advanced/tutorial_3_graphical_benefits.py +++ b/scripts/chapter_advanced/tutorial_3_graphical_benefits.py @@ -352,20 +352,12 @@ print(factor_graph.global_prior_model.info) """ -Drawing this model next to tutorial 2's figure shows what the second shared parameter bought us. The figure is the -**map** of the model, showing which dataset gets which components and which parameters are shared between them, and -the `info` above is the **legend** of priors. - -Two things have changed. The hoisted card at the top is titled `shared across datasets` and subtitled `one value -across 5 datasets`, and it now holds two `centre` pills rather than one, because each of the two `Gaussian`'s has its -own shared `centre`. Below it, every dataset is drawn as its own card, `0` through `4`, each containing a -`gaussian_0` and a `gaussian_1`, and inside them the `centre` pill carries a blue `shared` badge with a line running -back up to the hoisted card. The `normalization` and `sigma` pills carry no badge and no line, because those -parameters belong to their own dataset alone. - -The footer draws the dimensionality claim made above rather than asserting it: `2 shared across datasets`, -`4 per dataset × 5 datasets`, `22 unique sampled scalars`. That is the N=22 of the text, and the map shows where each -of those numbers comes from. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. + +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. """ af.ModelPlotter(factor_graph.global_prior_model).figure() diff --git a/scripts/chapter_advanced/tutorial_4_hierachical_models.py b/scripts/chapter_advanced/tutorial_4_hierachical_models.py index b10a865..3c7aaf7 100644 --- a/scripts/chapter_advanced/tutorial_4_hierachical_models.py +++ b/scripts/chapter_advanced/tutorial_4_hierachical_models.py @@ -215,19 +215,21 @@ print(factor_graph.global_prior_model.info) """ -Drawing this model with `af.ModelPlotter` and putting it next to the figure from tutorial 2 is the fastest way to see -what changed, because the two models say opposite things with almost the same words. - -In tutorial 2 the `centre` was hoisted into a card of its own and the plate pointed back at it: one prior object, one -number, shared. Here every dataset keeps its own `centre`, so it stays inside the plate as a `drawn` pill badged with -the hierarchical factor it came from, and the violet arrow comes from that factor's card and lands on the pill. There -is no shared badge anywhere on this figure. The arrow is making the weaker and more realistic claim: these centres -were drawn from a common population, they are not the same number. - -The footer makes the accounting explicit too, counting the parent distribution's `mean` and `sigma` as -hyper-parameters separately from the parameters belonging to each dataset. That is the split that matters when you -ask what a hierarchical model actually buys you: the hyper-parameters are the handful of numbers the whole sample -informs, and the figure is where you can see how few of them there are. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. + +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. + +The hierarchical model says something different from tutorial 2's shared model, in almost the same words. In +tutorial 2 the `centre` was a single shared prior: one object, one number, common to every dataset. Here every +dataset keeps its own `centre`, and those centres are drawn from a parent distribution whose `mean` and `sigma` are +themselves parameters of the fit. That is the weaker and more realistic claim: these centres came from a common +population, they are not the same number. + +Those two hyper-parameters are counted separately from the parameters belonging to each dataset, and that split is +what a hierarchical model buys you: the hyper-parameters are the handful of numbers the whole sample informs. """ af.ModelPlotter(factor_graph.global_prior_model).figure() diff --git a/scripts/chapter_advanced/tutorial_5_expectation_propagation.py b/scripts/chapter_advanced/tutorial_5_expectation_propagation.py index 0eac482..4d263ed 100644 --- a/scripts/chapter_advanced/tutorial_5_expectation_propagation.py +++ b/scripts/chapter_advanced/tutorial_5_expectation_propagation.py @@ -221,18 +221,15 @@ def log_likelihood_function(self, instance, xp=np): print(factor_graph.global_prior_model.info) """ -Drawing the model shows the graph that EP is about to sweep. The figure is the **map**, showing which dataset gets -which components and what joins them, and the `info` above is the **legend** of priors. +The same model can also be visualized as a figure, making its structure easier to understand at a glance. -There are four cards. The first three, `0` to `2`, are the `AnalysisFactor`'s, one per dataset, each holding a -`gaussian` card with its `centre`, `normalization` and `sigma` pills. The fourth card, numbered `3`, is the -`linear_regression` factor, and its pills are drawn in orange rather than as plain free priors because they are not -free parameters at all: each one shows the expression it is computed from, a constant times that dataset's -`gaussian.sigma`, which is the FWHM we built out of `fwhm_list` above. The legend names this kind of pill, -`relation (expression shown)`, and a line runs from each dataset's `sigma` into the relation built on it. +The figure shows how the model is organized: which parameters belong to each component, and whether they are free, +fixed, shared, linked by an expression, solved during the fit, or not configured. `model.info` provides the +corresponding numerical details, including the prior assigned to each free parameter and the value of each fixed +parameter. -Those lines are the thing to hold on to for the rest of the tutorial. EP never fits this whole map in one go. It -visits one card at a time, and the lines drawn here are the paths its messages travel along. +EP never fits this whole model in one go. It visits one factor at a time, passing messages along the links between +the factors, and those messages are what the rest of this tutorial follows. """ af.ModelPlotter(factor_graph.global_prior_model).figure() @@ -304,8 +301,8 @@ def log_likelihood_function(self, instance, xp=np): Until that `info` exists, the figure is how we read an EP fit back. `af.EPPlotter` draws the same factor graph as before, but now with the state of the run painted onto it. -The graph it draws is not the map we drew earlier, it is the factor graph itself, and its legend says how to read -it: `box = factor`, `pill = variable`, `dashed frame = repeated structure`. Every `AnalysisFactor` is a box, every +The graph it draws is not the model figure we drew earlier, it is the factor graph itself, and its legend says how +to read it: `box = factor`, `pill = variable`, `dashed frame = repeated structure`. Every `AnalysisFactor` is a box, every parameter it touches is a pill, and an edge between them means "this factor has something to say about this variable". That is the picture the message passing above lives on: a message leaves a box, arrives at a pill, and is read by every other box attached to it. The three datasets sit inside a dashed plate badged `3 datasets`, drawn once