Likelihood
The methods described below implement the computation of the source-plane and the image-plane log-likelihoods.
There are three techniques for computing the (log-)likelihood, with increasing level of complexity
Source-plane approximation: in this case the log-likelihood function takes as first parameter the
LensSystemdescribing the lens configuration; nogridparameter is present.Simplified image-plane: the log-likelihood function takes as first parameter the
LensSystem; agridparameter is also present.Image-plane: the likelihood takes as parameters directly the observed and predicted images; therefore, no
LensSystemis passed as parameter.
Gravity.loglikelihood — Function
loglikelihood(sys::LensSystem, ς::SourceCoeff, family::ImageFamily [, options])Compute the log-likelihood in the source-plane.
This function computes the source-plane log-likelihood associated to a given LensSystem and to an ImageFamily of SingleImageMeasurements with associated SourceCoeff.
Options
The algorithm used can be changed by passing an NamedTuple with the following names:
bayesianfactor: if true (the default), the computation of the likelihood includes the normalizing constant; otherwise, the Gaussian likelihood only includes the exponential term: in this case, the likelihood is essentially just -χ² / 2. Note that for the source-plane likelihood,bayesianfactor=truealso implies that the returned likelihood is marginalized with respect to the source position.
loglikelihood(sys::LensSystem, plane::SourcePlane [, options])Compute the log-likelihood in the source-plane.
This function computes the source-plane log-likelihood associated to a given LensSystem and to an entire SourcePlane. The computation is carried out by repeatedly calling loglikelihood(::LensSystem, ::SourceCoeff, ::ImageFamily) for all families belonging to the plane.
Options
The algorithm used can be changed by passing an NamedTuple with the following name:
bayesianfactor: if true (the default), the computation of the likelihood includes the normalizing constant; otherwise, the Gaussian likelihood only includes the exponential term: in this case, the likelihood is essentially just -χ² / 2.
loglikelihood(sys, ς, images, grid::AbstractGrid [, options [, mapped_corners]])Compute an image-plane likelihood with fast approximations.
The procedure takes as input parameters a LensSystem, a SourceCoeff, an ImageFamily of source measurements (for example, PointImageMeasurement), and a AbstractGrid; optionally, one can also pass the mapped corners of the grid trough the lens, which should be computed effectively as
mapped_corners = lensmap.(sys, ς, imagegrid.corners)This procedure uses Gravity.sourceimage to find the likely position of the source generating the observed images; then it inverts the lens equation using Gravity.lensunmap to find the predicted images, and computes the associated image-plane likelihood associated. It then optimizes the source position.
The options parameter is a NamedTupleused to set options affecting the computation. The only recognized option, for this implementation, isbayesianfactor`. If set to false, this procedure just returns the maximum value of the likelihood: this choice is OK if one is performing a maximum-likelihood analysis of the various free parameters of a lens model.
If, instead, bayesianfactor = true (the default), the procedure returns the likelihood marginalized over the source position. This quantity is computed using the Laplace approximation, and is generally fairly accurate under normal situations. This setting is suitable for the more usual case of a Bayesian inference.
Other options are directly passed to the source-plane likelihood procedure.
loglikelihood(sys, plane, grid [, options [, mapped_corners]])Log-likelihood in the image-plane using Laplace's approximation.
This function computes the source-plane log-likelihood associated to a given LensSystem and to an entire SourcePlane. The computation is carried out by repeadly calling loglikelihood(::LensSystem, ::SourceCoeff, ::ImageFamily, ::AbstractGrid) for all families belonging to the plane.
All options are directly passed to the likelihood functions for the various image families.
Gravity.loglikelihoodgrad — Function
loglikelihoodgrad(observations, predictions [, options])Compute the image-plane log-likelihood and its grandient.
Arguments
images: anImageFamilyofPointImageMeasurements with the measured image data.predictions: a vector ofSPointDiff, storing the prediction positions of all images and the jacobian of the lens-mapping (distortion) at the same position. These quantities can be obtained fromGravity.lensunmapdistortion.
Options
The algorithm used can be changed by passing an NamedTuple with the following names:
matches: a symbol used to specify the matching method between the images and the predictions. Can be one of the following::direct. Each image is matched to each prediction in order: that is, the algorithm presumes that the images have been sorted in a way, so that the first image is matched to the first prediction, the second image to the second prediction, and so forth. It is presumed that the number of images is identical to the number of predictions.:best. The best possible association between images and predictions is found and used. Essentially, the association is guarateed to maximize the final result: no other arrangement of images and predictions would result in a larger likelihood.:fast. It is identical to:bestwithduplicates = true, but uses a fast algorithm that avoids allocations and improves the execution by more than one order of magnitude.:all. All possible associations are taken into account in the computation of the log-likelihood. This corresponds to the idea that we have a missing datum, the image-prediction association, and we are essentially marginalizing over all arrangements. This is the default.
duplicates: a boolean indication if we are accepting associations of multiple images to the same prediction. A change of this keyword influences the results for the:bestand:allmatching modes. The defaul istrue.bayesianfactor: if true (the default), the computation of the likelihood includes the normalizing constant; otherwise, the Gaussian likelihood only includes the exponential term: in this case, the likelihood is essentially just -χ² / 2.missedpredictionspenalty: if true (the default), the log-likelihood for the:allmatching method includes a term that takes into account the number of possible arrangements images-predictions considered. This term, in practice, reduces the likelihood value in case we miss predicted images.
Return value
This function returns a SScalarPoint, representing both the log-likelihood value (scalar part) and its gradient with respect to the source position (point part).
This function can be defined only for an ImageFamily of PointImageMeasurement, since a LuminousImageMeasurement would require the knowledge of the second order derivatives of the lens mapping.
Gravity.sourceimage — Function
sourceimage(sys::LensSystem, ς::SourceCoeff, images::ImageFamily)Infer the source image associated to a set of observed images.
This function returns a suitable image measurement (depending on the input) representing the most likely source that can generate the observed data, given the provided LensSystem and SourceCoeff.
This is a critical step for the computation of the source-plane loglikelihood.
sourceimage(sys::LensSystem, imageplane::SourcePlane)Infer the sources associated with a set of imagefamilies.
sourceimage(sys, imageplane, imagegrid [, options [, mapped_coorners]])Infer the sources associated with a set of image families.
This procedure uses image-plane minimization procedures.