%matplotlib inline
from pyprojroot import here
workspace_path = str(here())
%cd $workspace_path
print(f"Working Directory has been set to `{workspace_path}`")
from os import path
import autofit as af
import autolens as al
import autolens.plot as aplt
First, lets create a result via ultranest by repeating the simple model-fit that is performed in
the modeling/start_here.py
example.
dataset_name = "simple__no_lens_light"
search = af.UltraNest(path_prefix="plot", name="UltraNestPlotter")
dataset_path = path.join("dataset", "imaging", dataset_name)
dataset = al.Imaging.from_fits(
data_path=path.join(dataset_path, "data.fits"),
psf_path=path.join(dataset_path, "psf.fits"),
noise_map_path=path.join(dataset_path, "noise_map.fits"),
pixel_scales=0.1,
)
mask = al.Mask2D.circular(
shape_native=dataset.shape_native, pixel_scales=dataset.pixel_scales, radius=3.0
)
dataset = dataset.apply_mask(mask=mask)
# Lens:
mass = af.Model(al.mp.Isothermal)
shear = af.Model(al.mp.ExternalShear)
lens = af.Model(al.Galaxy, redshift=0.5, mass=mass, shear=shear)
# Source:
bulge = af.Model(al.lp.Sersic)
source = af.Model(al.Galaxy, redshift=1.0, bulge=bulge)
# Overall Lens Model:
model = af.Collection(galaxies=af.Collection(lens=lens, source=source))
analysis = al.AnalysisImaging(dataset=dataset)
result = search.fit(model=model, analysis=analysis)
We now pass the samples to a UltraNestPlotter
which will allow us to use ultranest's in-built plotting libraries to
make figures.
The ultranest readthedocs describes fully all of the methods used below
In all the examples below, we use the kwargs
of this function to pass in any of the input parameters that are
described in the API docs.
ultranest_plotter = aplt.UltraNestPlotter(samples=result.samples)
The cornerplot
method produces a triangle of 1D and 2D PDF's of every parameter in the model fit.
ultranest_plotter.cornerplot()
The runplot
method shows how the estimates of the log evidence and other quantities progress as a function of
iteration number during the ultranest model-fit.
ultranest_plotter.runplot(
span=None,
logplot=False,
kde=True,
nkde=1000,
color="blue",
plot_kwargs=None,
label_kwargs=None,
lnz_error=True,
lnz_truth=None,
truth_color="red",
truth_kwargs=None,
max_x_ticks=8,
max_y_ticks=3,
use_math_text=True,
mark_final_live=True,
fig=None,
)
The traceplot
method shows how the live points of each parameter converged alongside their PDF.
ultranest_plotter.traceplot(
span=None,
quantiles=[0.025, 0.5, 0.975],
smooth=0.02,
post_color="blue",
post_kwargs=None,
kde=True,
nkde=1000,
trace_cmap="plasma",
trace_color=None,
trace_kwargs=None,
connect=False,
connect_highlight=10,
connect_color="red",
connect_kwargs=None,
max_n_ticks=5,
use_math_text=False,
labels=None,
label_kwargs=None,
show_titles=False,
title_fmt=".2f",
title_kwargs=None,
truths=None,
truth_color="red",
truth_kwargs=None,
verbose=False,
fig=None,
)
Finish.