diff --git a/config/notation.yaml b/config/notation.yaml index c600b4fd..b88d6216 100644 --- a/config/notation.yaml +++ b/config/notation.yaml @@ -7,9 +7,10 @@ # For example, if `centre=x`, the plot axis will be labeled 'x'. -# superscript: the superscript used on certain plots that show the results of different model-components. +# superscript: the class abbreviation used for priors directly on an unnamed Model. +# Named components use their model path instead (for example lens.bulge or source.pix.reg). -# For example, if `Gaussian=g`, plots where the parameters of the Gaussian model-component have superscript `g`. +# For example, `Gaussian=g` labels an unnamed Gaussian Model with superscript `g`. label: label: diff --git a/config/output.yaml b/config/output.yaml index 5ae3c60b..7ad91863 100644 --- a/config/output.yaml +++ b/config/output.yaml @@ -86,12 +86,13 @@ start_point: true # manually after completing a successful model-fit. This will save computational run time by not computing latent # variables during a any model-fit which is unsuccessful. -latent_during_fit: false # Whether to output the `latent.csv`, `latent.results` and `latent_summary.json` files during the fit when it performs on-the-fly output. -latent_after_fit: true # If `latent_during_fit` is False, whether to output the `latent.csv`, `latent.results` and `latent_summary.json` files after the fit is complete. +latent_during_fit: false # Write configured latent output during fit updates; also make the latent corner plot during updates if corner_anesthetic_latent is enabled. +latent_after_fit: true # Write configured latent output after completion. Full-sample mode writes files/latent/samples.csv; summaries use latent.results and files/latent/latent_summary.json. latent_draw_via_pdf : true # Whether to draw latent variable values via the PDF of every sample, which uses fewer samples to estimate latent variable errors. If False, latent variable values are drawn from every sample. latent_draw_via_pdf_size : 100 # The number of samples drawn to estimate latent variable errors if `latent_draw_via_pdf` is True. latent_csv: true # Whether to ouptut the `latent.csv` file. latent_results: true # Whether to output the `latent.results` file. +latent_model_parameters: true # Include model-declared columns in configured latent output. Full-sample CSV: files/latent/samples.csv. Saved angles retain their conversion range; only plots recentre them. # Other Files: @@ -106,4 +107,3 @@ model_graph: false # `model.graph`: graphical-model factor graph summary. Only m # `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 -latent_model_parameters: true # Whether the latent parameters a model component declares (e.g. a shear's magnitude and angle for its gamma_1 / gamma_2) join the latent output (`latent.csv`, `latent.results`, `latent_summary.json`). An angle keeps the range its conversion gives it (the same in every fit); only the corner plots recentre it on the posterior. diff --git a/config/visualize/plots_search.yaml b/config/visualize/plots_search.yaml index 4a8fa365..e868ef10 100644 --- a/config/visualize/plots_search.yaml +++ b/config/visualize/plots_search.yaml @@ -1,4 +1,7 @@ nest: corner_anesthetic: true # Output corner figure (using anestetic) during a non-linear search fit? + corner_anesthetic_components: true # Also output one corner figure per top-level model component (e.g. per galaxy), each named corner_anesthetic_? Follows corner_anesthetic when absent. + corner_anesthetic_latent: false # Output corner_anesthetic_latent after completion for declared latent parameters; during the fit only if output.yaml's latent_during_fit is enabled. Independent of the ordinary corner switches. + corner_anesthetic_latent_components: true # With corner_anesthetic_latent, also output one latent corner figure per top-level component that has a latent parameter, each named corner_anesthetic_latent_? Follows corner_anesthetic_latent when absent. mcmc: corner_cornerpy: true # Output corner figure (using corner.py) during a non-linear search fit? diff --git a/notebooks/cookbooks/configs.ipynb b/notebooks/cookbooks/configs.ipynb index 23e8204c..a153d147 100644 --- a/notebooks/cookbooks/configs.ipynb +++ b/notebooks/cookbooks/configs.ipynb @@ -372,8 +372,9 @@ " parameter2: c\n", " rate: \\lambda\n", "\n", - "It also contains a `superscript` section which pairs every model-component label with a superscript, so that\n", - "models with the same parameter names (e.g. `centre` can be distinguished).\n", + "It also contains a `superscript` section which gives a model class a superscript for the case where a model is a\n", + "bare `af.Model` of that class and so has no name of its own. A component given a name in a `Collection` (e.g.\n", + "`gaussian`) is labelled with that name, so models with the same parameter names (e.g. `centre`) are distinguished.\n", "\n", "label:\n", " superscript:\n", diff --git a/notebooks/cookbooks/latent_variables.ipynb b/notebooks/cookbooks/latent_variables.ipynb index a8e64459..2d116c78 100644 --- a/notebooks/cookbooks/latent_variables.ipynb +++ b/notebooks/cookbooks/latent_variables.ipynb @@ -200,6 +200,20 @@ "latent computations cannot influence which models the search prefers \u2014 they only attach extra information to\n", "samples that have already been drawn.\n", "\n", + "A model component can also declare latent variables of its own, with no `Analysis` code at all. Many components are\n", + "sampled in one parameterisation but read in another (PyAutoGalaxy's shear is fit as `gamma_1` / `gamma_2` but read\n", + "as a magnitude and an angle). The class declares the conversion as a `latent_parameters` class attribute, keyed by\n", + "the names of the sampled parameters it replaces and valued by a function of every parameter of the component (the\n", + "sampled ones as arrays over the samples, the fixed ones as floats) returning the latent values by name; an angle is\n", + "returned as `af.Periodic(angle, period)` so a corner plot can recentre it on its circular mean rather than split\n", + "it at the branch cut. Saved latent values retain the conversion's original range. When `latent_model_parameters`\n", + "is enabled, these columns join the `Latent` class's variables under the output policy below: full-sample output\n", + "uses `files/latent/samples.csv`, with summaries in `latent.results` and `files/latent/latent_summary.json`.\n", + "The conversions are vectorised over samples without constructing model instances. The search also writes\n", + "`corner_anesthetic_latent.png` when `corner_anesthetic_latent`\n", + "is on in `config/visualize/plots_search.yaml`. That plot follows the latent rule below rather than the fit's update\n", + "cadence: it is made once the fit completes, and during the fit only if `latent_during_fit` is on.\n", + "\n", "__Two Output Modes__\n", "\n", "PyAutoFit supports two strategies for computing latent values after a fit, controlled by `output.yaml`. Both\n", diff --git a/notebooks/plot/dynesty_plotter.ipynb b/notebooks/plot/dynesty_plotter.ipynb index 9b770d24..06cd85e8 100644 --- a/notebooks/plot/dynesty_plotter.ipynb +++ b/notebooks/plot/dynesty_plotter.ipynb @@ -143,8 +143,9 @@ "The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file \n", "and can be customized.\n", "\n", - "Each label also has a superscript corresponding to the model component the parameter originates from. For example,\n", - "Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file.\n", + "This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript\n", + "`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as\n", + "`gaussian` for `af.Collection(gaussian=...)`.\n", "\n", "__Plotting__\n", "\n", diff --git a/notebooks/plot/emcee_plotter.ipynb b/notebooks/plot/emcee_plotter.ipynb index 04ecdab0..c66d3458 100644 --- a/notebooks/plot/emcee_plotter.ipynb +++ b/notebooks/plot/emcee_plotter.ipynb @@ -146,8 +146,9 @@ "The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file \n", "and can be customized.\n", "\n", - "Each label also has a superscript corresponding to the model component the parameter originates from. For example,\n", - "Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file.\n", + "This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript\n", + "`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as\n", + "`gaussian` for `af.Collection(gaussian=...)`.\n", "\n", "__Plotting__\n", "\n", diff --git a/notebooks/plot/nautilus_plotter.ipynb b/notebooks/plot/nautilus_plotter.ipynb index fb1fb30f..82ca7c0d 100644 --- a/notebooks/plot/nautilus_plotter.ipynb +++ b/notebooks/plot/nautilus_plotter.ipynb @@ -148,8 +148,9 @@ "The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file \n", "and can be customized.\n", "\n", - "Each label also has a superscript corresponding to the model component the parameter originates from. For example,\n", - "Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file.\n", + "This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript\n", + "`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as\n", + "`gaussian` for `af.Collection(gaussian=...)`.\n", "\n", "__Plotting__\n", "\n", @@ -173,7 +174,10 @@ "options, not nautilus's \u2014 `corner_cornerpy` wraps `corner.py`, so figure-geometry arguments from other plotting\n", "libraries (`panelsize`, `xticksize`, `yticksize`, \u2026) do not apply here.\n", "\n", - "The `corner_anesthetic` function produces a triangle of 1D and 2D PDF's of every parameter using the library `anesthetic`." + "The `corner_anesthetic` function produces a triangle of 1D and 2D PDF's of every parameter using the library `anesthetic`.\n", + "Its `parameter_indices` input plots a subset of the parameters (a search writes one such plot per top-level model\n", + "component, `corner_anesthetic_.png`) and `latent=True` plots a component's latent parameters where its\n", + "class declares them (none do in this example), both switched in `config/visualize/plots_search.yaml`." ] }, { diff --git a/notebooks/plot/zeus_plotter.ipynb b/notebooks/plot/zeus_plotter.ipynb index 992cde12..447a82ce 100644 --- a/notebooks/plot/zeus_plotter.ipynb +++ b/notebooks/plot/zeus_plotter.ipynb @@ -148,8 +148,9 @@ "The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file \n", "and can be customized.\n", "\n", - "Each label also has a superscript corresponding to the model component the parameter originates from. For example,\n", - "Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file.\n", + "This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript\n", + "`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as\n", + "`gaussian` for `af.Collection(gaussian=...)`.\n", "\n", "__Plotting__\n", "\n", diff --git a/scripts/cookbooks/configs.py b/scripts/cookbooks/configs.py index 189a187a..84d596a6 100644 --- a/scripts/cookbooks/configs.py +++ b/scripts/cookbooks/configs.py @@ -275,8 +275,9 @@ def model_data_from(self, xvalues: np.ndarray, xp=np) -> np.ndarray: parameter2: c rate: \lambda -It also contains a `superscript` section which pairs every model-component label with a superscript, so that -models with the same parameter names (e.g. `centre` can be distinguished). +It also contains a `superscript` section which gives a model class a superscript for the case where a model is a +bare `af.Model` of that class and so has no name of its own. A component given a name in a `Collection` (e.g. +`gaussian`) is labelled with that name, so models with the same parameter names (e.g. `centre`) are distinguished. label: superscript: diff --git a/scripts/cookbooks/latent_variables.py b/scripts/cookbooks/latent_variables.py index d566d7dd..ce5d94af 100644 --- a/scripts/cookbooks/latent_variables.py +++ b/scripts/cookbooks/latent_variables.py @@ -135,6 +135,20 @@ latent computations cannot influence which models the search prefers — they only attach extra information to samples that have already been drawn. +A model component can also declare latent variables of its own, with no `Analysis` code at all. Many components are +sampled in one parameterisation but read in another (PyAutoGalaxy's shear is fit as `gamma_1` / `gamma_2` but read +as a magnitude and an angle). The class declares the conversion as a `latent_parameters` class attribute, keyed by +the names of the sampled parameters it replaces and valued by a function of every parameter of the component (the +sampled ones as arrays over the samples, the fixed ones as floats) returning the latent values by name; an angle is +returned as `af.Periodic(angle, period)` so a corner plot can recentre it on its circular mean rather than split +it at the branch cut. Saved latent values retain the conversion's original range. When `latent_model_parameters` +is enabled, these columns join the `Latent` class's variables under the output policy below: full-sample output +uses `files/latent/samples.csv`, with summaries in `latent.results` and `files/latent/latent_summary.json`. +The conversions are vectorised over samples without constructing model instances. The search also writes +`corner_anesthetic_latent.png` when `corner_anesthetic_latent` +is on in `config/visualize/plots_search.yaml`. That plot follows the latent rule below rather than the fit's update +cadence: it is made once the fit completes, and during the fit only if `latent_during_fit` is on. + __Two Output Modes__ PyAutoFit supports two strategies for computing latent values after a fit, controlled by `output.yaml`. Both diff --git a/scripts/plot/dynesty_plotter.py b/scripts/plot/dynesty_plotter.py index 384dd2a4..dc0f6e8f 100644 --- a/scripts/plot/dynesty_plotter.py +++ b/scripts/plot/dynesty_plotter.py @@ -67,8 +67,9 @@ The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file and can be customized. -Each label also has a superscript corresponding to the model component the parameter originates from. For example, -Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file. +This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript +`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as +`gaussian` for `af.Collection(gaussian=...)`. __Plotting__ diff --git a/scripts/plot/emcee_plotter.py b/scripts/plot/emcee_plotter.py index 0dc0cdf3..4966762d 100644 --- a/scripts/plot/emcee_plotter.py +++ b/scripts/plot/emcee_plotter.py @@ -70,8 +70,9 @@ The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file and can be customized. -Each label also has a superscript corresponding to the model component the parameter originates from. For example, -Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file. +This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript +`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as +`gaussian` for `af.Collection(gaussian=...)`. __Plotting__ diff --git a/scripts/plot/nautilus_plotter.py b/scripts/plot/nautilus_plotter.py index 8db7dba6..ef7d8a5b 100644 --- a/scripts/plot/nautilus_plotter.py +++ b/scripts/plot/nautilus_plotter.py @@ -72,8 +72,9 @@ The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file and can be customized. -Each label also has a superscript corresponding to the model component the parameter originates from. For example, -Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file. +This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript +`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as +`gaussian` for `af.Collection(gaussian=...)`. __Plotting__ @@ -98,6 +99,9 @@ libraries (`panelsize`, `xticksize`, `yticksize`, …) do not apply here. The `corner_anesthetic` function produces a triangle of 1D and 2D PDF's of every parameter using the library `anesthetic`. +Its `parameter_indices` input plots a subset of the parameters (a search writes one such plot per top-level model +component, `corner_anesthetic_.png`) and `latent=True` plots a component's latent parameters where its +class declares them (none do in this example), both switched in `config/visualize/plots_search.yaml`. """ aplt.corner_anesthetic(samples=samples) diff --git a/scripts/plot/zeus_plotter.py b/scripts/plot/zeus_plotter.py index b66a25c0..6711419d 100644 --- a/scripts/plot/zeus_plotter.py +++ b/scripts/plot/zeus_plotter.py @@ -72,8 +72,9 @@ The mappings of every parameter to its shorthand symbol for plots is specified in the `config/notation.yaml` file and can be customized. -Each label also has a superscript corresponding to the model component the parameter originates from. For example, -Gaussians are given the superscript `g`. This can also be customized in the `config/notation.yaml` file. +This example uses a bare, unnamed `af.Model(af.ex.Gaussian)`, so its labels use the configured class superscript +`g` from `config/notation.yaml`. A component named in a `Collection` instead uses its path of names, such as +`gaussian` for `af.Collection(gaussian=...)`. __Plotting__