hierarc.Likelihood.LensLikelihood package

Submodules

hierarc.Likelihood.LensLikelihood.base_lens_likelihood module

class hierarc.Likelihood.LensLikelihood.base_lens_likelihood.LensLikelihoodBase(z_lens, z_source, likelihood_type, z_source2=None, name='name', normalized=False, kwargs_lens_properties=None, **kwargs_likelihood)[source]

Bases: object

Master class containing the likelihood definitions of different analysis.

beta_dsp(cosmo)[source]

Model prediction of ratio of Einstein radii theta_E_1 / theta_E_2 or scaled deflection angles. Only computes it when likelihood is DSP.

Parameters:

cosmo – ~astropy.cosmology instance

Returns:

beta

ddt_measurement()[source]

Inferred Ddt from a lens model (i.e. power-law fit) and time-delay, without lambda correction (excludes also the external convergence contribution)

Returns:

ddt measurement median, 1-sigma (without lambda correction factor)

log_likelihood(ddt, dd, beta_dsp=None, kin_scaling=None, sigma_v_sys_error=None, mu_intrinsic=None, gamma_pl=None, lambda_mst=None)[source]
Parameters:
  • ddt – time-delay distance [physical Mpc]

  • dd – angular diameter distance to the lens [physical Mpc]

  • beta_dsp – ratio of reduced deflection angles between first and second source redshift, dds1 / ds1 * ds2 / dds2

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

  • sigma_v_sys_error – unaccounted uncertainty in the velocity dispersion measurement

  • mu_intrinsic – float, intrinsic source brightness (in magnitude)

  • gamma_pl – power-law density slope of main deflector (=2 being isothermal) (only used for DSP likelihood)

  • lambda_mst – mass-sheet transform at the main deflector (only used for DSP likelihood)

Returns:

natural logarithm of the likelihood of the data given the model

num_data()[source]

Number of data points across the lens sample.

Returns:

integer

sigma_v_measurement(sigma_v_sys_error=None)[source]
Returns:

data vector, measurement covariance matrix for velocity dispersion

sigma_v_prediction(ddt, dd, kin_scaling=None)[source]
Parameters:
  • ddt – ddt in physical Mpc

  • dd – dd in physical Mpc

  • kin_scaling – anisotropy scaling in J

Returns:

model predicted velocity dispersion (vector) and model covariance matrix thereof

hierarc.Likelihood.LensLikelihood.ddt_dd_gauss_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_dd_gauss_likelihood.DdtDdGaussian(z_lens, z_source, ddt_mean, ddt_sigma, dd_mean, dd_sigma)[source]

Bases: object

Class for joint kinematics and time delay likelihood assuming independent Gaussian likelihoods in Ddt and Dd.

Attention: Gaussian errors in the velocity dispersion do not translate into Gaussian uncertainties in Dd.

ddt_measurement()[source]
Returns:

mean, 1-sigma of the ddt inference/model measurement

log_likelihood(ddt, dd, kin_scaling=None)[source]
Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

Returns:

log likelihood given the single lens analysis

hierarc.Likelihood.LensLikelihood.ddt_dd_kde_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_dd_kde_likelihood.DdtDdKDELikelihood(z_lens, z_source, dd_samples, ddt_samples, kde_type='scipy_gaussian', bandwidth=1, interpol=False, num_interp_grid=100)[source]

Bases: object

Class for evaluating the 2-d posterior of Ddt vs Dd coming from a lens with time delays and kinematics measurement.

log_likelihood(ddt, dd, kin_scaling=None)[source]
Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

Returns:

log likelihood given the single lens analysis

hierarc.Likelihood.LensLikelihood.ddt_gauss_kin_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_gauss_kin_likelihood.DdtGaussKinLikelihood(z_lens, z_source, ddt_mean, ddt_sigma, sigma_v_measurement, j_model, error_cov_measurement, error_cov_j_sqrt, sigma_sys_error_include=False, normalized=True)[source]

Bases: object

Class for joint kinematics and time delay likelihood assuming that they are independent Uses KinLikelihood and DdtHistLikelihood combined.

ddt_measurement()[source]
Returns:

mean, 1-sigma of the ddt inference/model measurement

log_likelihood(ddt, dd, kin_scaling=None, sigma_v_sys_error=None, sigma_v_sys_offset=None)[source]
Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

  • sigma_v_sys_error – float (optional) added error on the velocity dispersion measurement in quadrature

  • sigma_v_sys_offset – float (optional) for a fractional systematic offset in the kinematic measurement such that sigma_v = sigma_v_measured * (1 + sigma_v_sys_offset)

Returns:

log likelihood given the single lens analysis

sigma_v_measurement(sigma_v_sys_error=None, sigma_v_sys_offset=None)[source]
Parameters:
  • sigma_v_sys_error – float (optional) added error on the velocity dispersion measurement in quadrature

  • sigma_v_sys_offset – float (optional) for a fractional systematic offset in the kinematic measurement such that sigma_v = sigma_v_measured * (1 + sigma_v_sys_offset)

Returns:

measurement mean (vector), measurement covariance matrix

sigma_v_prediction(ddt, dd, kin_scaling=1)[source]

Model prediction mean velocity dispersion vector and model prediction covariance matrix.

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

Returns:

model prediction mean velocity dispersion vector and model prediction covariance matrix

hierarc.Likelihood.LensLikelihood.ddt_gauss_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_gauss_likelihood.DdtGaussianLikelihood(z_lens, z_source, ddt_mean, ddt_sigma)[source]

Bases: object

Class to handle cosmographic likelihood coming from modeling lenses with imaging and kinematic data but no time delays. Thus Ddt is not constrained but the kinematics can constrain Ds/Dds.

The current version includes a Gaussian in Ds/Dds but can be extended.

ddt_measurement()[source]
Returns:

mean, 1-sigma of the ddt inference/model measurement

log_likelihood(ddt, dd=None)[source]
Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

Returns:

log likelihood given the single lens analysis

hierarc.Likelihood.LensLikelihood.ddt_hist_kin_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_hist_kin_likelihood.DdtHistKinLikelihood(z_lens, z_source, ddt_samples, sigma_v_measurement, j_model, error_cov_measurement, error_cov_j_sqrt, ddt_weights=None, kde_kernel='gaussian', bandwidth=20, nbins_hist=200, sigma_sys_error_include=False, normalized=True)[source]

Bases: object

Class for joint kinematics and time delay likelihood assuming that they are independent Uses KinLikelihood and DdtHistLikelihood combined.

ddt_measurement()[source]
Returns:

mean, 1-sigma of the ddt inference/model measurement

log_likelihood(ddt, dd, kin_scaling=None, sigma_v_sys_error=None)[source]
Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – numpy array of anisotropy scaling on prediction of Ds/Dds

Returns:

log likelihood given the single lens analysis

sigma_v_measurement(sigma_v_sys_error=None, sigma_v_sys_offset=None)[source]
Parameters:
  • sigma_v_sys_error – float (optional) added error on the velocity dispersion measurement in quadrature

  • sigma_v_sys_offset – float (optional) for a fractional systematic offset in the kinematic measurement such that sigma_v = sigma_v_measured * (1 + sigma_v_sys_offset)

Returns:

measurement mean (vector), measurement covariance matrix

sigma_v_prediction(ddt, dd, kin_scaling=1)[source]

Model prediction mean velocity dispersion vector and model prediction covariance matrix.

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

Returns:

model prediction mean velocity dispersion vector and model prediction covariance matrix

hierarc.Likelihood.LensLikelihood.ddt_hist_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_hist_likelihood.DdtHistKDELikelihood(z_lens, z_source, ddt_samples, kde_kernel='gaussian', ddt_weights=None, bandwidth=20, nbins_hist=200, normalized=False)[source]

Bases: object

Evaluates the likelihood of a time-delay distance ddt (in Mpc) against the model predictions, using a loglikelihood sampled from a Kernel Density Estimator. the KDE is constructed using a binned version of the full samples. Greatly improves speed at the cost of a (tiny) loss in precision.

__warning:: you should adjust bandwidth and nbins_hist to the spacing and size of your samples chain!

original source: https://github.com/shsuyu/H0LiCOW-public/blob/master/H0_inference_code/lensutils.py credits to Martin Millon, Aymeric Galan

ddt_measurement()[source]
Returns:

mean, 1-sigma of the ddt inference/model measurement

log_likelihood(ddt, dd=None)[source]

Note: kinematics + imaging data can constrain Ds/Dds. The input of Ddt, Dd is transformed here to match Ds/Dds

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

Returns:

log likelihood given the single lens analysis

class hierarc.Likelihood.LensLikelihood.ddt_hist_likelihood.DdtHistLikelihood(z_lens, z_source, ddt_samples, ddt_weights=None, nbins_hist=200, normalized=False, binning_method=None)[source]

Bases: object

Evaluates the likelihood of a time-delay distance ddt (in Mpc) against the model predictions, using a loglikelihood sampled from a Kernel Density Estimator. The KDE is constructed using a binned version of the full samples. Greatly improves speed at the cost of a (tiny) loss in precision.

Warning

you should adjust bandwidth and nbins_hist to the spacing and size of your samples chain!

original source: https://github.com/shsuyu/H0LiCOW-public/blob/master/H0_inference_code/lensutils.py credits to Martin Millon, Aymeric Galan

ddt_measurement()[source]
Returns:

mean, 1-sigma of the ddt inference/model measurement

log_likelihood(ddt, dd=None)[source]

Note: kinematics + imaging data can constrain Ds/Dds. The input of Ddt, Dd is transformed here to match Ds/Dds

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

Returns:

log likelihood given the single lens analysis

hierarc.Likelihood.LensLikelihood.ddt_lognorm_likelihood module

class hierarc.Likelihood.LensLikelihood.ddt_lognorm_likelihood.DdtLogNormLikelihood(z_lens, z_source, ddt_mu, ddt_sigma)[source]

Bases: object

The cosmographic likelihood coming from modeling lenses with imaging and kinematic data but no time delays, where the form of the likelihood is a lognormal distribution. Thus Ddt is not constrained but the kinematics can constrain Ds/Dds.

The current version includes a Gaussian in Ds/Dds but can be extended.

log_likelihood(ddt, dd=None)[source]

Note: kinematics + imaging data can constrain Ds/Dds. The input of Ddt, Dd is transformed here to match Ds/Dds

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

Returns:

log likelihood given the single lens analysis

hierarc.Likelihood.LensLikelihood.ds_dds_gauss_likelihood module

class hierarc.Likelihood.LensLikelihood.ds_dds_gauss_likelihood.DsDdsGaussianLikelihood(z_lens, z_source, ds_dds_mean, ds_dds_sigma)[source]

Bases: object

Class to handle cosmographic likelihood coming from modeling lenses with imaging and kinematic data but no time delays.

Thus Ddt is not constrained but the kinematics can constrain Ds/Dds. The likelihood in Ds/Dds is assumed Gaussian. Attention: Gaussian uncertainties in velocity dispersion do not translate into Gaussian uncertainties in Ds/Dds.

log_likelihood(ddt, dd, kin_scaling=None)[source]

Note: kinematics + imaging data can constrain Ds/Dds. The input of Ddt, Dd is transformed here to match Ds/Dds

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

Returns:

log likelihood given the single lens analysis

hierarc.Likelihood.LensLikelihood.kin_likelihood module

class hierarc.Likelihood.LensLikelihood.kin_likelihood.KinLikelihood(z_lens, z_source, sigma_v_measurement, j_model, error_cov_measurement, error_cov_j_sqrt, normalized=True, sigma_sys_error_include=False)[source]

Bases: object

Likelihood to deal with IFU kinematics constraints with covariances in both the model and measured velocity dispersion.

cov_error_measurement(sigma_v_sys_error=None)[source]
Parameters:

sigma_v_sys_error – float (optional) added error on the velocity dispersion measurement in quadrature

Returns:

error covariance matrix of the velocity dispersion measurements

cov_error_model(ds_dds, kin_scaling=1)[source]
Parameters:
  • ds_dds – Ds/Dds

  • kin_scaling – scaling of the anisotropy affecting sigma_v^2

Returns:

covariance matrix of the error in the predicted model (from mass model uncertainties)

log_likelihood(ddt, dd, kin_scaling=None, sigma_v_sys_error=None, sigma_v_sys_offset=None)[source]

Note: kinematics + imaging data can constrain Ds/Dds. The input of Ddt, Dd is transformed here to match Ds/Dds

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

  • sigma_v_sys_error – float (optional) added error on the velocity dispersion measurement in quadrature

  • sigma_v_sys_offset – float (optional) for a fractional systematic offset in the kinematic measurement such that sigma_v = sigma_v_measured * (1 + sigma_v_sys_offset)

Returns:

log likelihood given the single lens analysis

sigma_v_measurement(sigma_v_sys_error=None, sigma_v_sys_offset=None)[source]
Parameters:
  • sigma_v_sys_error – float (optional) added error on the velocity dispersion measurement in quadrature

  • sigma_v_sys_offset – float (optional) for a fractional systematic offset in the kinematic measurement such that sigma_v = sigma_v_measured * (1 + sigma_v_sys_offset)

Returns:

measurement mean (vector), measurement covariance matrix

sigma_v_measurement_mean(sigma_v_sys_offset=None)[source]
Parameters:

sigma_v_sys_offset – float (optional) for a fractional systematic offset in the kinematic measurement such that sigma_v = sigma_v_measured * (1 + sigma_v_sys_offset)

Returns:

corrected measured velocity dispersion

sigma_v_model(ds_dds, kin_scaling=1)[source]

Model predicted velocity dispersion for the IFU’s.

Parameters:
  • ds_dds – Ds/Dds

  • kin_scaling – scaling of the anisotropy affecting sigma_v^2

Returns:

array of predicted velocity dispersions

sigma_v_prediction(ddt, dd, kin_scaling=1)[source]

Model prediction mean velocity dispersion vector and model prediction covariance matrix.

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • kin_scaling – array of size of the velocity dispersion measurement or None, scaling of the predicted dimensionless quantity J (proportional to sigma_v^2) of the anisotropy model in the sampling relative to the anisotropy model used to derive the prediction and covariance matrix in the init of this class.

Returns:

model prediction mean velocity dispersion vector and model prediction covariance matrix

hierarc.Likelihood.LensLikelihood.mag_likelihood module

class hierarc.Likelihood.LensLikelihood.mag_likelihood.MagnificationLikelihood(amp_measured, cov_amp_measured, magnification_model, cov_magnification_model, magnitude_zero_point=20)[source]

Bases: object

Likelihood of an unlensed apprarent source magnification given a measurement of the magnified brightness This can i.e. be applied to lensed SNIa on the population level.

log_likelihood(mu_intrinsic)[source]
Parameters:

mu_intrinsic – intrinsic brightness of the source (already incorporating the inverse MST transform)

Returns:

log likelihood of the measured magnified images given the source brightness

hierarc.Likelihood.LensLikelihood.td_mag_likelihood module

class hierarc.Likelihood.LensLikelihood.td_mag_likelihood.TDMagLikelihood(time_delay_measured, cov_td_measured, amp_measured, cov_amp_measured, fermat_diff, magnification_model, cov_model, magnitude_zero_point=20)[source]

Bases: object

Likelihood of time delays and magnification likelihood.

This likelihood uses linear flux units and linear lensing magnifications.

log_likelihood(ddt, mu_intrinsic)[source]
Parameters:
  • ddt – time-delay distance (physical Mpc)

  • mu_intrinsic – intrinsic brightness of the source (already incorporating the inverse MST transform)

Returns:

log likelihood of the measured magnified images given the source brightness

hierarc.Likelihood.LensLikelihood.td_mag_magnitude_likelihood module

class hierarc.Likelihood.LensLikelihood.td_mag_magnitude_likelihood.TDMagMagnitudeLikelihood(time_delay_measured, cov_td_measured, magnitude_measured, cov_magnitude_measured, fermat_diff, magnification_model, cov_model)[source]

Bases: object

Likelihood of time delays and magnification likelihood.

This likelihood uses astronomical magnitude units in flux measurement and lensing magnification and Gaussian uncertainties in this space.

log_likelihood(ddt, mu_intrinsic)[source]
Parameters:
  • ddt – time-delay distance (physical Mpc)

  • mu_intrinsic – intrinsic brightness of the source (already incorporating the inverse MST transform)

Returns:

log likelihood of the measured magnified images given the source brightness

Module contents