Skip to content

Commit

Permalink
improve sensitivity plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Oct 31, 2024
1 parent 89d7b09 commit f9a9bc2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
30 changes: 30 additions & 0 deletions autolens/analysis/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ def positions_likelihood_from(
use_resample=False,
positions: Optional[aa.Grid2DIrregular] = None,
) -> Union[PositionsLHPenalty, PositionsLHResample]:
"""
Returns a `PositionsLH` object from the result of a lens model-fit, where the maximum log likelihood mass
and source models are used to determine the multiple image positions in the image-plane and source-plane
and ray-trace them to the source-plane to determine the threshold.
In chained fits, for example the SLaM pipelines, this means that a simple initial fit (e.g. SIE mass model,
parametric source) can be used to determine the multiple image positions and threshold for a more complex
subsequent fit (e.g. power-law mass model, pixelized source).
Parameters
----------
factor
The value the computed threshold is multiplied by to make the position threshold larger or smaller than the
maximum log likelihood model's threshold.
minimum_threshold
The output threshold is rounded up to this value if it is below it, to avoid extremely small threshold
values.
use_resample
If `False` the `PositionsLH` object is created using the `PositionsLHPenalty` class, which uses the
threshold to apply a penalty term to the likelihood. If `True` the `PositionsLH` object is created using
the `PositionsLHResample` class, which resamples the positions to the threshold.
positions
If input, these positions are used instead of the computed multiple image positions from the lens mass
model.
Returns
-------
The `PositionsLH` object used to apply a likelihood penalty or resample the positions.
"""

if os.environ.get("PYAUTOFIT_TEST_MODE") == "1":
return None

Expand Down
32 changes: 27 additions & 5 deletions autolens/lens/sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,22 @@ def subplot_sensitivity(self):
except TypeError:
log_evidences = np.zeros_like(log_likelihoods)

self.open_subplot_figure(number_subplots=4, subplot_shape=(1,4))
self.open_subplot_figure(number_subplots=8, subplot_shape=(2,4))

plotter = aplt.Array2DPlotter(
array=self.data_subtracted,
mat_plot_2d=self.mat_plot_2d,
)

max_value = np.round(np.nanmax(log_likelihoods), 2)
plotter.set_title(label=f"Sensitivity Map {max_value}")
plotter.figure_2d()

self.mat_plot_2d.plot_array(
array=log_evidences,
visuals_2d=self.visuals_2d,
auto_labels=AutoLabels(title="Increase in Log Evidence"),
)

self.mat_plot_2d.plot_array(
array=log_likelihoods,
visuals_2d=self.visuals_2d,
Expand All @@ -398,7 +403,6 @@ def subplot_sensitivity(self):
values=above_threshold,
mask=log_likelihoods.mask
)
plotter.set_title(label=None)

self.mat_plot_2d.plot_array(
array=above_threshold,
Expand All @@ -407,9 +411,27 @@ def subplot_sensitivity(self):
)

self.mat_plot_2d.plot_array(
array=log_evidences,
array=self.result._array_2d_from(self.result.log_evidences_base),
visuals_2d=self.visuals_2d,
auto_labels=AutoLabels(title="Increase in Log Evidence"),
auto_labels=AutoLabels(title="Log Evidence Base"),
)

self.mat_plot_2d.plot_array(
array=self.result._array_2d_from(self.result.log_evidences_perturbed),
visuals_2d=self.visuals_2d,
auto_labels=AutoLabels(title="Log Evidence Perturb"),
)

self.mat_plot_2d.plot_array(
array=self.result._array_2d_from(self.result.log_likelihoods_base),
visuals_2d=self.visuals_2d,
auto_labels=AutoLabels(title="Log Likelihood Base"),
)

self.mat_plot_2d.plot_array(
array=self.result._array_2d_from(self.result.log_likelihoods_perturbed),
visuals_2d=self.visuals_2d,
auto_labels=AutoLabels(title="Log Likelihood Perturb"),
)

self.mat_plot_2d.output.subplot_to_figure(auto_filename="subplot_sensitivity")
Expand Down

0 comments on commit f9a9bc2

Please sign in to comment.