autolens.AnalysisInterferometer#
- class AnalysisInterferometer[source]#
Bases:
AnalysisDataset
Analysis classes are used by PyAutoFit to fit a model to a dataset via a non-linear search.
An 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. The Analysis class 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 using PyAutoFit’s database tools.
This Analysis class is used for all model-fits which fit galaxies (or objects containing galaxies like a Tracer) to an interferometer dataset.
This class stores the settings used to perform the model-fit for certain components of the model (e.g. a pixelization or inversion), the Cosmology used for the analysis and hyper datasets used for certain model classes.
- Parameters
dataset – The interferometer dataset that the model is fitted too.
positions_likelihood (
Union
[PositionsLHResample
,PositionsLHPenalty
,None
]) – An object which alters the likelihood function to include a term which accounts for whether image-pixel coordinates in arc-seconds corresponding to the multiple images of the lensed source galaxy trace close to one another in the source-plane.hyper_dataset_result – The hyper-model image and hyper galaxies images of a previous result in a model-fitting pipeline, which are used by certain classes for adapting the analysis to the properties of the dataset.
cosmology (
LensingCosmology
) – The Cosmology assumed for this analysis.settings_pixelization (
Optional
[SettingsPixelization
]) – settings controlling how a pixelization is fitted for example if a border is used when creating the pixelization.settings_inversion (
Optional
[SettingsInversion
]) – Settings controlling how an inversion is fitted, for example which linear algebra formalism is used.settings_lens (
Optional
[SettingsLens
]) – Settings controlling the lens calculation, for example how close the lensed source’s multiple images have to trace within one another in the source plane for the model to not be discarded.raise_inversion_positions_likelihood_exception (
bool
) – If an inversion is used without the positions_likelihood it is likely a systematic solution will be inferred, in which case an Exception is raised before the model-fit begins to inform the user of this. This exception is not raised if this input is False, allowing the user to perform the model-fit anyway.
Methods
check_and_replace_hyper_images
Using a the result of a previous model-fit, a hyper-dataset can be set up which adapts aspects of the model (e.g.
Given a model instance create a FitInterferometer object.
Given a Tracer, which the analysis constructs from a model instance, create a FitInterferometer object.
hyper_background_noise_via_instance_from
If the model instance contains a HyperBackgroundNoise attribute, which adds a free parameter to the model that scales the background noise, return this attribute.
hyper_image_sky_via_instance_from
If the model instance contains a HyperImageSky attribute, which adds a free parameter to the model that scales the background sky, return this attribute.
instance_with_associated_hyper_images_from
Using the model image and galaxy images that were set up as the hyper dataset, associate the galaxy images of that result with the galaxies in this model fit.
Using the model visibilities that were set up as the hyper dataset, associate the galaxy images of that result with the galaxies in this model fit.
log_likelihood_cap_from
Certain Inversion's have stochasticity in their log likelihood estimate (e.g.
Given an instance of the model, where the model parameters are set via a non-linear search, fit the model instance to the interferometer dataset.
log_likelihood_positions_overwrite_from
Call the positions overwrite log likelihood function, which add a penalty term to the likelihood if the positions of the multiple images of the lensed source do not trace close to one another in the source plane.
After the non-linear search is complete create its Result, which includes:
modify_after_fit
Call functions that perform tasks after a model-fit is completed, for example ensuring the figure of merit has not changed from previous estimates and resetting preloads.
PyAutoFit calls this function immediately before the non-linear search begins, therefore it can be used to perform tasks using the final model parameterization.
modify_model
output_or_check_figure_of_merit_sanity
Changes to the PyAutoGalaxy source code may inadvertantly change the numerics of how a log likelihood is computed.
plane_via_instance_from
Create a Plane from the galaxies contained in a model instance.
profile_log_likelihood_function
Overwrite this function for profiling of the log likelihood function to be performed every update of a non-linear search.
raise_exceptions
Before the non-linear search begins, this routine saves attributes of the Analysis object to the pickles
save_results_for_aggregator
At the end of a model-fit, this routine saves attributes of the Analysis object to the pickles folder such that they can be loaded after the analysis using PyAutoFit's database and aggregator tools.
save_stochastic_outputs
Certain Inversion's have stochasticity in their log likelihood estimate (e.g.
Using a the result of a previous model-fit, set the hyper-dataset for this analysis.
set_preloads
It is common for the model to have components whose parameters are all fixed, and thus the way that component fits the data does not change.
Certain Inversion's have stochasticity in their log likelihood estimate.
tracer_via_instance_from
Create a Tracer from the galaxies contained in a model instance.
Outputs images of the maximum log likelihood model inferred by the model-fit.
with_model
Associate an explicit model with this analysis.
Attributes
fit_func
fit_maker_cls
interferometer
preloads_cls
- modify_before_fit(paths, model)[source]#
PyAutoFit calls this function immediately before the non-linear search begins, therefore it can be used to perform tasks using the final model parameterization.
This function checks that the hyper-dataset is consistent with previous hyper-datasets if the model-fit is being resumed from a previous run, and it visualizes objects which do not change throughout the model fit like the dataset.
- Parameters
paths (
DirectoryPaths
) – The PyAutoFit 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.model (
Collection
) – The PyAutoFit model object, which includes model components representing the galaxies that are fitted to the imaging data.
- set_hyper_dataset(result)[source]#
Using a the result of a previous model-fit, set the hyper-dataset for this analysis. This is used to adapt aspects of the model (e.g. the pixelization, regularization scheme) to the properties of the dataset being fitted.
This passes the hyper model image and hyper galaxy images of the previous fit. These represent where different galaxies in the dataset are located and thus allows the fit to adapt different aspects of the model to different galaxies in the data.
It also passes hyper visibilities, which are used to scale the noise of a visibility dataset.
- Parameters
result – The result of a previous model-fit which contains the model image and model galaxy images of a fit to the dataset, which set up the hyper dataset. These are used by certain classes for adapting the analysis to the properties of the dataset.
- instance_with_associated_hyper_visibilities_from(instance)[source]#
Using the model visibilities that were set up as the hyper dataset, associate the galaxy images of that result with the galaxies in this model fit.
Association is performed based on galaxy names, whereby if the name of a galaxy in this search matches the full-path name of galaxies in the hyper dataset the galaxy image is passed.
If the galaxy collection has a different name then an association is not made.
- For example, galaxies.lens will match with:
galaxies.lens
- but not with:
galaxies.source
- 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), which has 0 or more galaxies in its tree.- Returns
The input instance with visibilities associated with galaxies where possible.
- Return type
instance
- 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 interferometer 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:
If the analysis has a hyper dataset, associated the model galaxy images of this dataset to the galaxies in the model instance.
Extract attributes which model aspects of the data reductions, like the scaling the background sky and background noise.
Extracts all galaxies from the model instance and set up a Tracer, which includes ordering the galaxies by redshift to set up each Plane.
Use the Tracer and other attributes to create a FitInterferometer object, which performs steps such as creating model images of every galaxy in the plane, transforming them to the uv-plane via a Fourier transform and computing residuals, a chi-squared statistic and the log likelihood.
Certain models will fail to fit the dataset and raise an exception. For example if an Inversion is used, the linear algebra calculation may be invalid 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 – 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 interferometer data.
- Return type
- fit_interferometer_via_instance_from(instance, use_hyper_scaling=True, preload_overwrite=None)[source]#
Given a model instance create a FitInterferometer object.
This function is used in the log_likelihood_function to fit the model to the interferometer data and compute the log likelihood.
- 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_hyper_scaling (
bool
) – If false, the scaling of the background sky and noise are not performed irrespective of the model components themselves.preload_overwrite (
Optional
[Preloads
]) – If a Preload object is input this is used instead of the preloads stored as an attribute in the analysis.check_positions – Whether the multiple image positions of the lensed source should be checked, i.e. whether they trace within the position threshold of one another in the source plane.
profiling_dict – A dictionary which times functions called to fit the model to data, for profiling.
- Returns
The fit of the plane to the interferometer dataset, which includes the log likelihood.
- Return type
- fit_interferometer_via_tracer_from(tracer, hyper_background_noise, use_hyper_scaling=True, preload_overwrite=None)[source]#
Given a Tracer, which the analysis constructs from a model instance, create a FitInterferometer object.
This function is used in the log_likelihood_function to fit the model to the imaging data and compute the log likelihood.
- Parameters
tracer (
Tracer
) – The tracer of galaxies whose ray-traced model images are used to fit the imaging data.hyper_image_sky – A model component which scales the background sky level of the data before computing the log likelihood.
hyper_background_noise (
Optional
[HyperBackgroundNoise
]) – A model component which scales the background noise level of the data before computing the log likelihood.use_hyper_scaling (
bool
) – If false, the scaling of the background sky and noise are not performed irrespective of the model components themselves.preload_overwrite (
Optional
[Preloads
]) – If a Preload object is input this is used instead of the preloads stored as an attribute in the analysis.profiling_dict – A dictionary which times functions called to fit the model to data, for profiling.
- Returns
The fit of the plane to the imaging dataset, which includes the log likelihood.
- Return type
- stochastic_log_likelihoods_via_instance_from(instance)[source]#
Certain Inversion’s have stochasticity in their log likelihood estimate.
For example, the VoronoiBrightnessImage pixelization, which changes the likelihood depending on how different KMeans seeds change the pixel-grid.
A log likelihood cap can be applied to model-fits performed using these Inversion’s to improve error and posterior estimates. This log likelihood cap is estimated from a list of stochastic log likelihoods, where these log likelihoods are computed using the same model but with different KMeans seeds.
This function computes these stochastic log likelihoods by iterating over many model-fits using different KMeans seeds.
- Parameters
- instance
The maximum log likelihood instance of a model that is has finished being fitted to the dataset.
- Returns
- float
A log likelihood cap which is applied in a stochastic model-fit to give improved error and posterior estimates.
- visualize(paths, instance, during_analysis)[source]#
Outputs images of the maximum log likelihood model inferred by the model-fit. This function is called throughout the non-linear search at input intervals, and therefore provides on-the-fly visualization of how well the model-fit is going.
The visualization performed by this function includes:
Images of the best-fit Tracer, including the images of each of its galaxies.
Images of the best-fit FitInterferometer, including the model-image, residuals and chi-squared of its fit to the imaging data.
The hyper-images of the model-fit showing how the hyper galaxies are used to represent different galaxies in the dataset.
If hyper features are used to scale the noise, a FitInterferometer with these features turned off may be output, to indicate how much these features are altering the dataset.
The images output by this function are customized using the file config/visualize/plots.ini.
- Parameters
paths (
DirectoryPaths
) – The PyAutoFit 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.instance – 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).
during_analysis – If True the visualization is being performed midway through the non-linear search before it is finished, which may change which images are output.
- make_result(samples, model, sigma=1.0, use_errors=True, use_widths=False)[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 ResultInterferometer object contains a number of methods which use the above objects to create the max log likelihood Plane, FitInterferometer, hyper-galaxy images,etc.
- Parameters
samples (
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.model (
Collection
) – The PyAutoFit model object, which includes model components representing the galaxies that are fitted to the imaging data.
- Returns
The result of fitting the model to the imaging dataset, via a non-linear search.
- Return type
ResultImaging
- save_attributes_for_aggregator(paths)[source]#
Before the non-linear search begins, this routine saves attributes of the Analysis object to the pickles folder such that they can be load 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 dataset’s data.
The dataset’s noise-map.
The settings associated with the dataset.
The settings associated with the inversion.
The settings associated with the pixelization.
The Cosmology.
The hyper dataset’s model image and galaxy images, if used.
This function also outputs attributes specific to an imaging dataset:
Its uv-wavelengths
Its real space mask.
The positions of the brightest pixels in the lensed source which are used to discard mass models.
The preloaded image-plane source plane pixelization if used by the analysis. This ensures that differences in
the scikit-learn library do not lead to different pixelizations being computed if results are transferred from a HPC to laptop.
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 PyAutoFit 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.