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
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@

aplt.subplot_fit_imaging(fit=fit)

"""
r"""
__Likelihood Function__

The likelihood function for linear light profiles includes the same terms as the standard parametric case:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@

aplt.plot_array(array=convolved_image_2d, title="Convolved Image")

"""
r"""
__Likelihood Function__

We now quantify the goodness-of-fit of our group-scale lens model.
Expand Down
4 changes: 2 additions & 2 deletions scripts/group/likelihood_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
f"(y,x) coordinates of first ten unmasked image-pixels {masked_dataset.grid[0:9]}"
)

"""
r"""
__Lens Galaxy Light (Setup)__

To perform a likelihood evaluation we now compose our lens model.
Expand Down Expand Up @@ -388,7 +388,7 @@

aplt.plot_array(array=convolved_image_2d, title="Convolved Image")

"""
r"""
__Likelihood Function__

We now quantify the goodness-of-fit of our group-scale lens model.
Expand Down
2 changes: 1 addition & 1 deletion scripts/guides/galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"""
aplt.plot_array(array=tracer.image_2d_from(grid=grid), title="Image")

"""
r"""
__Log10__

The light distributions of galaxies are closer to a log10 distribution than a linear one.
Expand Down
2 changes: 1 addition & 1 deletion scripts/guides/results/aggregator/data_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@

aplt.subplot_fit_imaging(fit=fit)

"""
r"""
__Visualization Customization__

The benefit of inspecting fits using the aggregator, rather than the files outputs to the hard-disk, is that we can
Expand Down
2 changes: 1 addition & 1 deletion scripts/guides/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
array=tracer.image_2d_from(grid=grid), title="Image of Strong Lens System"
)

"""
r"""
__Log10__

The light and masss distributions of galaxies are closer to a log10 distribution than a linear one.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
__Log Likelihood Function: Potential Correction (Gravitational Imaging)__

This script provides a step-by-step guide of the **PyAutoLens** potential-correction `log_likelihood_function`
Expand Down Expand Up @@ -70,7 +70,7 @@
import autolens as al
import autolens.plot as aplt

"""
r"""
__Dataset__

We simulate the dataset in-memory (seeded, so this script is fully reproducible): an `IsothermalSph` lens whose
Expand Down Expand Up @@ -104,7 +104,7 @@
tracer=al.Tracer(galaxies=[lens_true, source_true]), grid=grid
)

"""
r"""
__Arc Mask__

The corrections respond to the data only through the source's brightness gradients, which vanish away from the
Expand All @@ -124,7 +124,7 @@
n_data = int(np.count_nonzero(~mask_array))
print(f"unmasked data pixels: n_data = {n_data}")

"""
r"""
__Smooth Starting Model__

Potential corrections perturb a smooth starting model — in a real analysis, the maximum-likelihood result of a
Expand All @@ -136,7 +136,7 @@
lens_smooth = al.Galaxy(redshift=0.2, mass=lens_true.mass)
source_start = al.pc.AnalyticSrcFactory(source_galaxy=source_true)

"""
r"""
__Dpsi Mesh__

The corrections are defined on a rectangular mesh a factor coarser than the data grid (here factor 2).
Expand All @@ -160,7 +160,7 @@
f"itp_mat shape = {pair.itp_mat.shape}, row sums all 1: {np.allclose(pair.itp_mat.sum(axis=1), 1.0)}"
)

"""
r"""
__Dpsi Gradient Operator__

The correction $\delta\psi$ deflects rays by its gradient: $\delta\alpha = \nabla \delta\psi$. The sparse operator
Expand All @@ -175,7 +175,7 @@
)
print(f"D_psi shape = {dpsi_gradient_matrix.shape}")

"""
r"""
__Source Gradients__

A small extra deflection $\delta\alpha$ at an image pixel re-samples the source at a position shifted
Expand Down Expand Up @@ -207,7 +207,7 @@
)
print(f"B shape = {psf_matrix.shape}")

"""
r"""
__Dpsi Mapping Matrix__

Combining the three operators gives the linear response of the observed image to the mesh corrections
Expand All @@ -222,7 +222,7 @@
)
print(f"dpsi mapping matrix shape = {dpsi_mapping_matrix.shape}")

"""
r"""
__Source Inversion Blocks__

The joint inversion reconstructs the source simultaneously. Its source blocks come from the standard pixelized
Expand All @@ -248,7 +248,7 @@
n_src = src_regularization_matrix.shape[0]
print(f"F_src shape = {src_mapping_matrix.shape}, n_src = {n_src}")

"""
r"""
__Joint System__

The joint linear system stacks the two blocks:
Expand All @@ -274,7 +274,7 @@
)
print(f"joint mapping matrix shape = {mapping_matrix.shape}")

"""
r"""
__Solve__

With diagonal noise covariance $C^{-1} = \rm{diag}(1/\sigma_i^2)$, the maximum-evidence solution of the joint
Expand All @@ -298,7 +298,7 @@
dpsi_solution = solution[n_src:]
model_image = mapping_matrix @ solution

"""
r"""
__Dkappa Map__

The corrections' physical meaning is clearest as a convergence correction,
Expand All @@ -325,7 +325,7 @@
plt.show()
plt.close()

"""
r"""
__Evidence Terms__

The Bayesian evidence of the joint inversion has five terms (Suyu et al. 2006 eq. 19; Cao et al. 2025):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
Potential Correction: Start Here
================================

Expand Down Expand Up @@ -68,7 +68,7 @@
import autolens as al
import autolens.plot as aplt

"""
r"""
__Simulate__

We simulate imaging of a strong lens whose mass model is an `Isothermal` plus a $10^{10} \, M_\odot$ NFW dark
Expand Down Expand Up @@ -198,7 +198,7 @@

print(f"joint source + dpsi log evidence = {fit.log_evidence:.4e}")

"""
r"""
__Dkappa Map__

The reconstructed corrections live on the coarse dpsi mesh (`fit.best_fit_dpsi`). Their physical meaning is clearest
Expand All @@ -224,7 +224,7 @@
fit, output=path.join("output", "potential_correction_joint_fit.png")
)

"""
r"""
__Iterative Fit__

The joint fit above linearizes the corrections around the smooth model once. The iterative engine
Expand Down Expand Up @@ -261,7 +261,7 @@
f"{iter_fit.pair_dpsi_data_obj.xgrid_dpsi_1d[peak]:.2f})"
)

"""
r"""
__Evidence Sampling__

In a real analysis the regularization hyper-parameters (the coefficients and scales above) are not known. They are
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
__Log Likelihood Function: Linear Light Profile__

This script provides a step-by-step guide of the `log_likelihood_function` which is used to fit `Imaging` data with
Expand Down Expand Up @@ -389,7 +389,7 @@
f"Mapping between image pixel 0 and linear light profile pixel 1 = {mapping_matrix[0, 1]}"
)

"""
r"""
__Data Vector (D)__

To solve for the linear light profile intensities we now pose the problem as a linear inversion.
Expand Down Expand Up @@ -443,7 +443,7 @@
print(data_vector)
print(data_vector.shape)

"""
r"""
__Curvature Matrix (F)__

The `curvature_matrix` $F$ is the second matrix and it has
Expand Down Expand Up @@ -475,7 +475,7 @@
plt.close()


"""
r"""
__Reconstruction (Positive-Negative)__

The following chi-squared is minimized when we perform the inversion and reconstruct the galaxy:
Expand Down Expand Up @@ -559,7 +559,7 @@
aplt.plot_array(array=mapped_reconstructed_operated_data, title="")


"""
r"""
__Likelihood Function__

We now quantify the goodness-of-fit of our galaxy model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
__Log Likelihood Function: Multi Gaussian Expansion__

This script provides a step-by-step guide of the `log_likelihood_function` which is used to fit `Imaging` data with
Expand Down Expand Up @@ -472,7 +472,7 @@
f"Mapping between image pixel 0 and Gaussian linear light profile pixel 1 = {mapping_matrix[0, 1]}"
)

"""
r"""
__Data Vector (D)__

To solve for the linear light profile intensities we now pose the problem as a linear inversion.
Expand Down Expand Up @@ -526,7 +526,7 @@
print(data_vector)
print(data_vector.shape)

"""
r"""
__Curvature Matrix (F)__

The `curvature_matrix` $F$ is the second matrix and it has
Expand Down Expand Up @@ -558,7 +558,7 @@
plt.close()


"""
r"""
__Reconstruction (Positive-Negative)__

The following chi-squared is minimized when we perform the inversion and reconstruct the galaxy:
Expand Down Expand Up @@ -683,7 +683,7 @@
aplt.plot_array(array=mapped_reconstructed_operated_data, title="")


"""
r"""
__Likelihood Function__

We now quantify the goodness-of-fit of our galaxy model.
Expand Down
18 changes: 9 additions & 9 deletions scripts/imaging/features/pixelization/likelihood_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
__Log Likelihood Function: Pixelization__

This script provides a step-by-step guide of the **PyAutoLens** `log_likelihood_function` which is used to fit
Expand Down Expand Up @@ -267,7 +267,7 @@

aplt.plot_array(array=lens_subtracted_image, title="")

"""
r"""
__Ray Tracing__

To perform lensing calculations we ray-trace every 2d (y,x) coordinate $\theta$ from the image-plane to its (y,x)
Expand Down Expand Up @@ -578,7 +578,7 @@
"""
print(f"Mapping between image pixel 0 and source pixel 2 = {mapping_matrix[0, 2]}")

"""
r"""
__Data Vector (D)__

To solve for the source pixel fluxes we now pose the problem as a linear inversion.
Expand Down Expand Up @@ -622,7 +622,7 @@
plt.show()
plt.close()

"""
r"""
__Curvature Matrix (F)__

The `curvature_matrix` $F$ is the second matrix and it has dimensions `(total_source_pixels, total_source_pixels)`.
Expand Down Expand Up @@ -672,7 +672,7 @@

aplt.plot_array(array=array_2d, title="")

"""
r"""
The following chi-squared is minimized when we perform the inversion and reconstruct the source:

$\chi^2 = \sum_{\rm j=1}^{J} \bigg[ \frac{(\sum_{\rm i=1}^{I} s_{i} f_{ij}) + b_{j} - d_{j}}{\sigma_{j}} \bigg]$
Expand Down Expand Up @@ -706,7 +706,7 @@

aplt.plot_grid(grid=mapper.source_plane_mesh_grid, title="Source-Plane Mesh Grid")

"""
r"""
__Regularization Matrix (H)__

Regularization adds a linear regularization term $G_{\rm L}$ to the $\chi^2$ we solve for giving us a new merit
Expand Down Expand Up @@ -802,7 +802,7 @@

aplt.plot_array(array=mapped_reconstructed_operated_data, title="")

"""
r"""
__Likelihood Function__

We now quantify the goodness-of-fit of our lens model and source reconstruction.
Expand Down Expand Up @@ -851,7 +851,7 @@
aplt.plot_array(array=chi_squared_map, title="")


"""
r"""
__Regularization Term__

The second term, $s^{T} H s$, corresponds to the $\lambda $G_{\rm L}$ regularization term we added to our merit
Expand All @@ -870,7 +870,7 @@

print(regularization_term)

"""
r"""
__Complexity Terms__

Up to this point, it is unclear why we chose a value of `regularization_coefficient=1.0`.
Expand Down
Loading
Loading