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
16 changes: 14 additions & 2 deletions notebooks/guides/results/_quick_fit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,23 @@
"\n",
"analysis = AnalysisLatent(dataset=dataset, use_jax=True)\n",
"\n",
"for i in range(2):\n",
"# Two fits are written to `results_folder/`:\n",
"#\n",
"# - The first uses the bare `dataset_name` as its `unique_tag`. This is the\n",
"# canonical fit that the single-result tutorials (`start_here.py`,\n",
"# `aggregator/galaxies_fits.py`, `aggregator/samples.py`) resume: they build\n",
"# the *same* model and search below, so `search.fit(...)` returns this\n",
"# completed fit instead of redoing the search.\n",
"# - The second (`_1`) gives the aggregator tutorials a second result to iterate\n",
"# over, demonstrating how the `Aggregator` loads many fits from one folder.\n",
"#\n",
"# Both share the model, search and analysis, so both retain the full samples\n",
"# (`samples_weight_threshold = None` above) needed for indexed sample access.\n",
"for unique_tag in [dataset_name, f\"{dataset_name}_1\"]:\n",
" search = af.Nautilus(\n",
" path_prefix=Path(\"results_folder\"),\n",
" name=\"results\",\n",
" unique_tag=f\"{dataset_name}_{i}\",\n",
" unique_tag=unique_tag,\n",
" n_live=100,\n",
" n_batch=50,\n",
" iterations_per_quick_update=10000,\n",
Expand Down
7 changes: 6 additions & 1 deletion notebooks/guides/results/aggregator/galaxies_fits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@
"\n",
"model = af.Collection(\n",
" galaxies=af.Collection(\n",
" lens=af.Model(al.Galaxy, redshift=0.5, mass=al.mp.Isothermal),\n",
" lens=af.Model(\n",
" al.Galaxy,\n",
" redshift=0.5,\n",
" mass=al.mp.Isothermal,\n",
" shear=al.mp.ExternalShear,\n",
" ),\n",
" source=af.Model(al.Galaxy, redshift=1.0, bulge=bulge, disk=None),\n",
" ),\n",
")\n",
Expand Down
26 changes: 19 additions & 7 deletions notebooks/guides/results/aggregator/samples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,22 @@
"\n",
"dataset = dataset.apply_mask(mask=mask)\n",
"\n",
"bulge = al.model_util.mge_model_from(\n",
" mask_radius=mask_radius,\n",
" total_gaussians=20,\n",
" gaussian_per_basis=1,\n",
" centre_prior_is_uniform=False,\n",
")\n",
"\n",
"model = af.Collection(\n",
" galaxies=af.Collection(\n",
" lens=af.Model(al.Galaxy, redshift=0.5, mass=al.mp.Isothermal),\n",
" source=af.Model(al.Galaxy, redshift=1.0, bulge=al.lp.Sersic),\n",
" lens=af.Model(\n",
" al.Galaxy,\n",
" redshift=0.5,\n",
" mass=al.mp.Isothermal,\n",
" shear=al.mp.ExternalShear,\n",
" ),\n",
" source=af.Model(al.Galaxy, redshift=1.0, bulge=bulge, disk=None),\n",
" ),\n",
")\n",
"\n",
Expand Down Expand Up @@ -860,19 +872,19 @@
"samples = samples.with_paths(\n",
" [\n",
" (\"galaxies\", \"lens\", \"mass\", \"einstein_radius\"),\n",
" (\"galaxies\", \"source\", \"bulge\", \"sersic_index\"),\n",
" (\"galaxies\", \"lens\", \"shear\", \"gamma_1\"),\n",
" ]\n",
")\n",
"\n",
"print(\n",
" \"All parameters of the very first sample (containing only the lens mass's einstein radius and \"\n",
" \"source bulge's sersic index).\"\n",
" \"the first component of the lens's external shear).\"\n",
")\n",
"print(samples.parameter_lists[0])\n",
"\n",
"print(\n",
" \"Maximum Log Likelihood Model Instances (containing only the lens mass's einstein radius and \"\n",
" \"source bulge's sersic index):\\n\"\n",
" \"the first component of the lens's external shear):\\n\"\n",
")\n",
"print(samples.max_log_likelihood(as_instance=False))"
],
Expand All @@ -898,12 +910,12 @@
"samples = result.samples\n",
"\n",
"samples = samples.with_paths(\n",
" [\"galaxies.lens.mass.einstein_radius\", \"galaxies.source.bulge.sersic_index\"]\n",
" [\"galaxies.lens.mass.einstein_radius\", \"galaxies.lens.shear.gamma_1\"]\n",
")\n",
"\n",
"print(\n",
" \"All parameters of the very first sample (containing only the lens mass's einstein radius and \"\n",
" \"source bulge's sersic index).\"\n",
" \"the first component of the lens's external shear).\"\n",
")"
],
"outputs": [],
Expand Down
7 changes: 6 additions & 1 deletion notebooks/guides/results/start_here.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@
"\n",
"model = af.Collection(\n",
" galaxies=af.Collection(\n",
" lens=af.Model(al.Galaxy, redshift=0.5, mass=al.mp.Isothermal),\n",
" lens=af.Model(\n",
" al.Galaxy,\n",
" redshift=0.5,\n",
" mass=al.mp.Isothermal,\n",
" shear=al.mp.ExternalShear,\n",
" ),\n",
" source=af.Model(al.Galaxy, redshift=1.0, bulge=bulge, disk=None),\n",
" ),\n",
")\n",
Expand Down
16 changes: 14 additions & 2 deletions scripts/guides/results/_quick_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,23 @@ class AnalysisLatent(al.AnalysisImaging):

analysis = AnalysisLatent(dataset=dataset, use_jax=True)

for i in range(2):
# Two fits are written to `results_folder/`:
#
# - The first uses the bare `dataset_name` as its `unique_tag`. This is the
# canonical fit that the single-result tutorials (`start_here.py`,
# `aggregator/galaxies_fits.py`, `aggregator/samples.py`) resume: they build
# the *same* model and search below, so `search.fit(...)` returns this
# completed fit instead of redoing the search.
# - The second (`_1`) gives the aggregator tutorials a second result to iterate
# over, demonstrating how the `Aggregator` loads many fits from one folder.
#
# Both share the model, search and analysis, so both retain the full samples
# (`samples_weight_threshold = None` above) needed for indexed sample access.
for unique_tag in [dataset_name, f"{dataset_name}_1"]:
search = af.Nautilus(
path_prefix=Path("results_folder"),
name="results",
unique_tag=f"{dataset_name}_{i}",
unique_tag=unique_tag,
n_live=100,
n_batch=50,
iterations_per_quick_update=10000,
Expand Down
7 changes: 6 additions & 1 deletion scripts/guides/results/aggregator/galaxies_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@

model = af.Collection(
galaxies=af.Collection(
lens=af.Model(al.Galaxy, redshift=0.5, mass=al.mp.Isothermal),
lens=af.Model(
al.Galaxy,
redshift=0.5,
mass=al.mp.Isothermal,
shear=al.mp.ExternalShear,
),
source=af.Model(al.Galaxy, redshift=1.0, bulge=bulge, disk=None),
),
)
Expand Down
26 changes: 19 additions & 7 deletions scripts/guides/results/aggregator/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,22 @@

dataset = dataset.apply_mask(mask=mask)

bulge = al.model_util.mge_model_from(
mask_radius=mask_radius,
total_gaussians=20,
gaussian_per_basis=1,
centre_prior_is_uniform=False,
)

model = af.Collection(
galaxies=af.Collection(
lens=af.Model(al.Galaxy, redshift=0.5, mass=al.mp.Isothermal),
source=af.Model(al.Galaxy, redshift=1.0, bulge=al.lp.Sersic),
lens=af.Model(
al.Galaxy,
redshift=0.5,
mass=al.mp.Isothermal,
shear=al.mp.ExternalShear,
),
source=af.Model(al.Galaxy, redshift=1.0, bulge=bulge, disk=None),
),
)

Expand Down Expand Up @@ -517,19 +529,19 @@
samples = samples.with_paths(
[
("galaxies", "lens", "mass", "einstein_radius"),
("galaxies", "source", "bulge", "sersic_index"),
("galaxies", "lens", "shear", "gamma_1"),
]
)

print(
"All parameters of the very first sample (containing only the lens mass's einstein radius and "
"source bulge's sersic index)."
"the first component of the lens's external shear)."
)
print(samples.parameter_lists[0])

print(
"Maximum Log Likelihood Model Instances (containing only the lens mass's einstein radius and "
"source bulge's sersic index):\n"
"the first component of the lens's external shear):\n"
)
print(samples.max_log_likelihood(as_instance=False))

Expand All @@ -544,12 +556,12 @@
samples = result.samples

samples = samples.with_paths(
["galaxies.lens.mass.einstein_radius", "galaxies.source.bulge.sersic_index"]
["galaxies.lens.mass.einstein_radius", "galaxies.lens.shear.gamma_1"]
)

print(
"All parameters of the very first sample (containing only the lens mass's einstein radius and "
"source bulge's sersic index)."
"the first component of the lens's external shear)."
)

"""
Expand Down
7 changes: 6 additions & 1 deletion scripts/guides/results/start_here.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@

model = af.Collection(
galaxies=af.Collection(
lens=af.Model(al.Galaxy, redshift=0.5, mass=al.mp.Isothermal),
lens=af.Model(
al.Galaxy,
redshift=0.5,
mass=al.mp.Isothermal,
shear=al.mp.ExternalShear,
),
source=af.Model(al.Galaxy, redshift=1.0, bulge=bulge, disk=None),
),
)
Expand Down
Loading