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
31 changes: 14 additions & 17 deletions notebooks/chapter_2_lens_modeling/tutorial_10_prior_passing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This is the same model as the first search of the previous tutorial, so it is the same map: greyed `centre` and\n",
"`sersic_index` pills for the parameters fixed to values, the blue `shared \u00d72` and `\u2197 bulge.ell_comps` pair\n",
"joining the mass's ellipticity to the bulge's, dashed `intensity \u00b7 solved` pills on both linear light profiles,\n",
"and a footer of `11 unique sampled scalars`.\n",
"The same model can also be visualized as a figure, making its structure easier to understand at a glance.\n",
"\n",
"Hold this map in mind as you read the second model below. This tutorial is about what changes between the two \u2014\n",
"and, more importantly, about what does not."
"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",
"This is the same model as the first search of the previous tutorial. Keep it in mind as you read the second\n",
"model below: this tutorial is about what prior passing changes between the two and, more importantly, about what\n",
"it does not."
]
},
{
Expand Down Expand Up @@ -402,18 +405,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Here is the lesson of this tutorial, drawn. Prior passing moves the **legend** and leaves the **map** alone:\n",
"almost every number in the `info` above has been replaced by a narrow prior centred on search 1's result, and\n",
"not one of those replacements shows up in the figure, because a prior is a number and numbers are not structure.\n",
"\n",
"What the map *does* show are the two changes we made deliberately, and separately from the passing itself: the\n",
"`centre` and `sersic_index` pills are white rather than grey (we chose not to pass those, so they are free\n",
"again, and the blue bracket between bulge and mass is gone with them), and the source's card is now\n",
"`bulge \u00b7 Sersic` rather than `bulge \u00b7 ExponentialCore` \u2014 the upgrade `take_attributes` exists to make possible.\n",
"The footer moves from `11 unique sampled scalars` to `19`.\n",
"Prior passing replaces almost every number in the `info` above with a narrow prior centred on search 1's result,\n",
"but it changes nothing about the model's structure, because a prior is a number and numbers are not structure.\n",
"\n",
"This is a good habit when chaining searches: draw both models. Every difference you see on the map is a\n",
"structural decision you made on purpose; everything else the chain did for you is in the legend."
"The two changes we made deliberately, and separately from the passing itself, are structural: `centre` and\n",
"`sersic_index` are free again, because we chose not to pass those, and the source is now a `Sersic` rather than\n",
"an `ExponentialCore` \u2014 the upgrade `take_attributes` exists to make possible."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,29 +436,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The same model can also be drawn as a figure, via `af.ModelPlotter`.\n",
"\n",
"The figure and the `info` are two views of the same model, 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 galaxy owns\n",
"which profile, which profile owns which parameter, and what state every parameter is in \u2014 free, fixed to a\n",
"value, shared with another parameter, related to one by an expression, or solved for during the fit rather than\n",
"sampled. The `info` printed above is the **legend**: it lists the priors and values themselves, the numbers the\n",
"map has no room for.\n",
"\n",
"Read this first map from the outside in. The outer frame is titled `galaxies`, after the `Collection` we just\n",
"composed. Inside it sit two cards, `lens \u00b7 Galaxy` and `source \u00b7 Galaxy`, each labelled underneath with its\n",
"redshift, `redshift = 0.5` and `redshift = 1.0` \u2014 which is how **PyAutoLens** knows which galaxy does the\n",
"lensing and which one is lensed. Inside the lens card is a single profile card, `mass \u00b7 IsothermalSph`, holding\n",
"the pills `centre` (carrying a `2D` badge, because a centre is a tuple of two coordinates) and `einstein_radius`.\n",
"Inside the source card is `bulge \u00b7 ExponentialCoreSph`, whose greyed-out `radius_break`, `gamma` and `alpha`\n",
"pills mark parameters fixed to default values, and whose dashed `intensity \u00b7 solved` pill marks the one\n",
"parameter that is not sampled at all: because this is a linear light profile, its `intensity` is solved for by\n",
"linear algebra at every likelihood evaluation. The footer totals the model up as `6 unique sampled scalars`,\n",
"`5 fixed leaf slots` and `1 parameter solved during fitting`.\n",
"\n",
"Draw the map every time you compose a model. It fits on one screen now and may look like a redundant restatement\n",
"of the `info`, but the two views scale very differently: by chapter 4 our models hold fifteen galaxies and their\n",
"`info` runs to hundreds of lines, whilst the map 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.\n",
"\n",
"Each galaxy is labelled with its redshift, `redshift = 0.5` for the lens and `redshift = 1.0` for the source.\n",
"That is how **PyAutoLens** knows which galaxy does the lensing and which one is lensed."
]
},
{
Expand Down Expand Up @@ -550,12 +536,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Drawing the model again makes the point sharply: the map is identical to the one above. Priors live in the\n",
"legend, not on the map, so customizing them changes many numbers in the `info` and nothing at all in the figure.\n",
"\n",
"That is exactly what you want from the two views. When you tune priors you are changing where the search looks,\n",
"not what it is looking for, and an unchanged map is the visual confirmation that you have not accidentally\n",
"changed the model itself whilst editing it."
"Customizing priors changes many numbers in the `info` and nothing at all about the model itself. When you tune\n",
"priors you are changing where the search looks, not what it is looking for."
]
},
{
Expand Down
18 changes: 8 additions & 10 deletions notebooks/chapter_2_lens_modeling/tutorial_2_practicalities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As in the previous tutorial we also draw the model, remembering the division of labour between the two views:\n",
"the figure is the **map**, showing the structure of the model \u2014 which galaxy owns which profile and parameter,\n",
"and whether each parameter is free, fixed or solved \u2014 and the `info` is the **legend**, holding the priors and\n",
"values themselves.\n",
"\n",
"Because this is the same model as tutorial 1, it is the same map: the `galaxies` frame holding a\n",
"`lens \u00b7 Galaxy` card at `redshift = 0.5` with its `mass \u00b7 IsothermalSph` profile, a `source \u00b7 Galaxy` card at\n",
"`redshift = 1.0` with its `bulge \u00b7 ExponentialCoreSph` and its dashed `intensity \u00b7 solved` pill, and a footer\n",
"reading `6 unique sampled scalars`. Nothing in this tutorial changes the model \u2014 every setting we discuss\n",
"below belongs to the search, and the search is not drawn on this map."
"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",
"Nothing in this tutorial changes the model \u2014 every setting we discuss below belongs to the search."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Drawing the model makes plain why this fit is so much harder than the one in tutorial 1. The figure is the\n",
"**map** of the model, showing its structure and the state of every parameter, whilst the `info` above is the\n",
"**legend**, holding the priors we just customized.\n",
"\n",
"The `lens \u00b7 Galaxy` card now holds three profile cards rather than one: `bulge \u00b7 Sersic`, `mass \u00b7 Isothermal`\n",
"and `shear \u00b7 ExternalShear`. Every pill is white, meaning every parameter is free, and the footer counts\n",
"`20 unique sampled scalars` against the six of tutorial 1. Note also that these are *ordinary* light profiles\n",
"rather than the linear ones we have been using: `intensity` appears as a plain free pill on both `bulge` cards\n",
"instead of the dashed `intensity \u00b7 solved` we saw before, so the search has to sample it. Tutorial 5 will take\n",
"those two dimensions back.\n",
"\n",
"The priors we tightened above are nowhere on this map, because a prior is a number and numbers belong to the\n",
"legend. The map's job here is to show you the *size* of the problem the priors are helping with."
"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",
"This model has twenty free parameters against the six of tutorial 1, which is why this fit is so much harder.\n",
"Note also that it uses *ordinary* light profiles rather than the linear ones we have been using, so the search\n",
"has to sample each `intensity` itself. Tutorial 5 will take those two dimensions back."
]
},
{
Expand Down Expand Up @@ -644,15 +641,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the map earns its keep. On the `mass \u00b7 Isothermal` card the `centre` and `ell_comps` pills are no longer\n",
"free parameters of their own: each carries a blue reference badge reading `\u2197 bulge.centre` and\n",
"`\u2197 bulge.ell_comps`, and a blue bracket runs down the side of the figure joining them to the matching\n",
"`shared \u00d72` badges on the `bulge \u00b7 Sersic` card. That bracket *is* the light-traces-mass assumption, drawn.\n",
"The footer confirms the saving: `16 unique sampled scalars` and `4 shared priors`, down from the twenty of the\n",
"previous model.\n",
"The `mass \u00b7 Isothermal`'s `centre` and `ell_comps` are no longer free parameters of their own: each is tied to\n",
"the matching parameter of the `bulge \u00b7 Sersic`. That pairing *is* the light-traces-mass assumption, and it takes\n",
"the model from twenty free parameters down to sixteen.\n",
"\n",
"Pairing parameters is easy to get subtly wrong and hard to spot in a long `info` listing, but trivial to check\n",
"on the map. Whenever you pair parameters, draw the model and confirm the brackets land where you meant them to."
"Pairing parameters is easy to get subtly wrong and hard to spot in a long `info` listing."
]
},
{
Expand Down
32 changes: 11 additions & 21 deletions notebooks/chapter_2_lens_modeling/tutorial_5_linear_profiles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The figure shows the linear light profiles in a way the `info` cannot. On both `bulge` cards \u2014 the lens's\n",
"`Sersic` and the source's `ExponentialCore` \u2014 the final pill is drawn with a dashed outline and reads\n",
"`intensity \u00b7 solved`, and the figure's legend line spells the dash out as *solved during fitting*. The footer\n",
"then separates the two kinds of quantity for you: `18 unique sampled scalars`, the dimensions the search\n",
"actually explores, and `2 parameters solved during fitting`, the intensities the inversion computes exactly at\n",
"every likelihood evaluation.\n",
"\n",
"This is precisely the distinction the section above is making. In the `info` the `intensity` is simply absent,\n",
"and an absence is a hard thing to notice; on the map it is present but visibly marked as belonging to a\n",
"different machine."
"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."
]
},
{
Expand Down Expand Up @@ -731,18 +727,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The `info` for this model is enormous \u2014 forty-five Gaussians, each with its own block of parameters. The map is\n",
"not, because it collapses repetition into **plates**. Each `bulge \u00b7 Basis` card holds a `profile_list` frame\n",
"containing one dashed plate: a single `Gaussian` card badged `30 components` on the lens and `15 components` on\n",
"the source, with the index range (`0 - 29`, `0 - 14`) printed beneath the title. A plate says \"this one card\n",
"stands for all of these components\", and its pills describe what every member of the plate has in common:\n",
"`centre` and `ell_comps` carry blue `shared across group` badges, `sigma` reads `fixed, varies by member`, and\n",
"`intensity` is the familiar dashed `intensity \u00b7 solved`. The caption under the plate repeats it in words,\n",
"`Gaussian with priors centre \u21c4 shared, ell_comps \u21c4 shared, sigma fixed (varies by member), intensity solved`.\n",
"The `info` for this model is enormous \u2014 forty-five Gaussians, each with its own block of parameters \u2014 but the\n",
"model itself is small. Each `bulge \u00b7 Basis` holds a single `Gaussian` repeated thirty times on the lens and\n",
"fifteen times on the source, and every member of a basis shares one `centre` and one `ell_comps`, has its own\n",
"fixed `sigma`, and has its `intensity` solved by the inversion.\n",
"\n",
"That is the whole MGE trick in one line of the figure, and the footer proves the arithmetic: `13 unique sampled\n",
"scalars` alongside `47 fixed leaf slots`, `45 parameters solved during fitting` and `2 plates standing for 45\n",
"components`. Forty-five Gaussians, thirteen dimensions \u2014 the N=13 quoted above."
"That is the whole MGE trick: forty-five Gaussians, thirteen dimensions \u2014 the N=13 quoted above."
]
},
{
Expand Down
23 changes: 11 additions & 12 deletions notebooks/chapter_2_lens_modeling/tutorial_9_search_chaining.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The map of `model_1` shows the three kinds of simplification we just made, each drawn differently. The `centre`\n",
"pills on `bulge \u00b7 Sersic` and `mass \u00b7 Isothermal` are greyed out, as is `sersic_index`: grey means fixed to a\n",
"value and removed from the search. `ell_comps` carries a blue `shared \u00d72` badge on the bulge and an\n",
"`\u2197 bulge.ell_comps` reference on the mass, with a bracket joining them \u2014 the pairing. And `intensity \u00b7 solved`\n",
"sits dashed on both linear light profiles. The footer adds it all up: `11 unique sampled scalars`, `10 fixed\n",
"leaf slots`, `2 shared priors` and `2 parameters solved during fitting`.\n",
"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",
"Eleven dimensions is a deliberately crude model, and that is exactly what the first search in a chain wants: it\n",
"needs only to be good enough to locate the lens roughly, and to do so quickly."
Expand Down Expand Up @@ -588,13 +588,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The second model's map is the comparison worth making. Every grey pill has turned white \u2014 the centres and the\n",
"`sersic_index` are free again \u2014 the blue bracket between `bulge` and `mass` has gone with them, and the source's\n",
"card is now a `Sersic` carrying a `sersic_index` pill of its own. The footer reads `19 unique sampled scalars`\n",
"against the eleven of `model_1`.\n",
"The second model is the comparison worth making. The centres and the `sersic_index` are free again, the pairing\n",
"between `bulge` and `mass` has gone with them, and the source is now a `Sersic` with a `sersic_index` of its\n",
"own: nineteen free parameters against the eleven of `model_1`.\n",
"\n",
"That is search chaining drawn as a picture: search 1 fits the small map, and what it learns buys us the priors\n",
"that make the large map affordable."
"That is search chaining: search 1 fits the small model, and what it learns buys us the priors that make the\n",
"large model affordable."
]
},
{
Expand Down
Loading
Loading