autogalaxy.AnalysisEllipse#
- class AnalysisEllipse[source]#
Bases:
AnalysisFits a model made of ellipses to an imaging dataset via a non-linear search.
The Analysis class defines the log_likelihood_function which fits the model to the dataset and returns the log likelihood value defining how well the model fitted the data.
It handles many other tasks, such as visualization, outputting results to hard-disk and storing results in a format that can be loaded after the model-fit is complete.
This class is used for model-fits which fit ellipses to an imaging dataset.
- Parameters:
dataset (
Imaging) – The Imaging dataset that the model containing ellipses is fitted to.title_prefix (
str) – A string that is added before the title of all figures output by visualization, for example to put the name of the dataset and galaxy in the title.use_jax (
bool) – If True, the JAX-traceable fit path is enabled. Fit-related pytrees are registered on the firstfit_fromcall. DefaultTruemirrorsAnalysisImaging.
Methods
compute_latent_samplesCompute latent variables from a model instance.
compute_latent_variablesOverride to compute latent variables from the instance.
fit_for_visualizationBuild the fit used by the visualizer.
Given a model instance create a
FitEllipseSummedaggregating oneFitEllipseper ellipse in the instance.Given a model instance create a list of FitEllipse objects.
Given an instance of the model, where the model parameters are set via a non-linear search, fit the model instance to the imaging dataset.
After the non-linear search is complete create its Result, which includes:
modify_after_fitOverwrite this method to modify the attributes of the Analysis class before the non-linear search begins.
modify_before_fitOverwrite this method to modify the attributes of the Analysis class before the non-linear search begins.
modify_modelperform_quick_updateprint_vram_usePrint JAX VRAM use for a given batch size.
Before the non-linear search begins, this routine saves attributes of the Analysis object to the files
save_resultssave_results_combinedwith_modelAssociate an explicit model with this analysis.
Attributes
LATENT_BATCH_MODELATENT_KEYSsupports_background_updateWhether this analysis supports background quick updates.
supports_jax_visualizationWhether the visualizer can work directly with JAX arrays.
- Result#
alias of
ResultEllipse
- Visualizer#
alias of
VisualizerEllipse
- log_likelihood_function(instance)[source]#
Given an instance of the model, where the model parameters are set via a non-linear search, fit the model instance to the imaging dataset.
This function returns a log likelihood which is used by the non-linear search to guide the model-fit.
For this analysis class, this function performs the following steps:
Extract all ellipses from the model instance.
2) Use the ellipses to create a list of FitEllipse objects, which fits each ellipse to the data and noise-map via interpolation and subtracts these values from their mean values in order to quantify how well the ellipse traces around the data.
Certain models will fail to fit the dataset and raise an exception. For example the ellipse parameters may be ill defined and raise an Exception. In such circumstances the model is discarded and its likelihood value is passed to the non-linear search in a way that it ignores it (for example, using a value of -1.0e99).
- Parameters:
instance (
ModelInstance) – An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search).- Returns:
The log likelihood indicating how well this model instance fitted the imaging data.
- Return type:
- fit_from(instance)[source]#
Given a model instance create a
FitEllipseSummedaggregating oneFitEllipseper ellipse in the instance.This function is used in log_likelihood_function to fit the model containing ellipses to the imaging data and compute the figure of merit. It registers ellipse/multipole/fit pytrees on the first call when
use_jaxis True so the return value can cross thejax.jitboundary.Mirrors
AnalysisImaging.fit_from.- Parameters:
instance (
ModelInstance) – An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search).- Returns:
The aggregated fit of all ellipses to the imaging dataset.
- Return type:
FitEllipseSummed
- fit_list_from(instance, use_jax=False)[source]#
Given a model instance create a list of FitEllipse objects.
This function unpacks the instance, specifically the ellipses and (in input) the multipoles and uses them to create a list of FitEllipse objects that are used to fit the model to the imaging data.
This function is used in the fit_from to fit the model containing ellipses to the imaging data and compute the log likelihood. It is also called by VisualizerEllipse.visualize, which passes the default use_jax=False to get numpy-backed arrays suitable for matplotlib.
- Parameters:
instance (
ModelInstance) – An instance of the model that is being fitted to the data by this analysis (whose parameters have been set via a non-linear search).use_jax (
bool) – If True, each FitEllipse is constructed with use_jax=True so that all internal array operations usejax.numpyand results are JAX arrays. DefaultFalsepreserves the numpy path for visualization and other non-JIT callers.
- Return type:
The fit of the ellipses to the imaging dataset, which includes the log likelihood.
- make_result(samples_summary, paths, samples=None, search_internal=None, analysis=None)[source]#
After the non-linear search is complete create its Result, which includes:
The samples of the non-linear search (E.g. MCMC chains, nested sampling samples) which are used to compute the maximum likelihood model, posteriors and other properties.
The model used to fit the data, which uses the samples to create specific instances of the model (e.g. an instance of the maximum log likelihood model).
The non-linear search used to perform the model fit.
The ResultEllipse object contains a number of methods which use the above objects to create the max log likelihood galaxies FitEllipse, etc.
- Parameters:
samples (
Optional[SamplesPDF]) – A PyAutoFit object which contains the samples of the non-linear search, for example the chains of an MCMC run of samples of the nested sampler.search – The non-linear search used to perform this model-fit.
- Returns:
The result of fitting the ellipse model to the imaging dataset, via a non-linear search.
- Return type:
ResultImaging
- save_attributes(paths)[source]#
Before the non-linear search begins, this routine saves attributes of the Analysis object to the files folder such that they can be loaded after the analysis using PyAutoFit’s database and aggregator tools.
For this analysis, it uses the AnalysisDataset object’s method to output the following:
The imaging dataset (data / noise-map / etc.).
The mask applied to the dataset.
The Cosmology.
This function also outputs attributes specific to an imaging dataset:
Its mask.
It is common for these attributes to be loaded by many of the template aggregator functions given in the aggregator modules. For example, when using the database tools to perform a fit, the default behaviour is for the dataset, settings and other attributes necessary to perform the fit to be loaded via the pickle files output by this function.
- Parameters:
- paths
The paths object which manages all paths, e.g. where the non-linear search outputs are stored, visualization, and the pickled objects used by the aggregator output by this function.