hierarc.Likelihood package

Subpackages

Submodules

hierarc.Likelihood.anisotropy_scaling module

hierarc.Likelihood.cosmo_likelihood module

class hierarc.Likelihood.cosmo_likelihood.CosmoLikelihood(kwargs_likelihood_list, cosmology, kwargs_bounds, sne_likelihood=None, kwargs_sne_likelihood=None, KDE_likelihood_chain=None, kwargs_kde_likelihood=None, ppn_sampling=False, lambda_mst_sampling=False, lambda_mst_distribution='delta', anisotropy_sampling=False, gamma_in_sampling=False, gamma_in_distribution='NONE', log_m2l_sampling=False, log_m2l_distribution='NONE', los_sampling=False, los_distributions=None, alpha_lambda_sampling=False, beta_lambda_sampling=False, alpha_gamma_in_sampling=False, alpha_log_m2l_sampling=False, lambda_ifu_sampling=False, lambda_ifu_distribution='NONE', sigma_v_systematics=False, sne_apparent_m_sampling=False, sne_distribution='GAUSSIAN', z_apparent_m_anchor=0.1, log_scatter=False, normalized=False, anisotropy_model='OM', anisotropy_distribution='NONE', custom_prior=None, interpolate_cosmo=True, num_redshift_interp=100, cosmo_fixed=None)[source]

Bases: object

This class contains the likelihood function of the Strong lensing analysis.

cosmo_instance(kwargs_cosmo)[source]
Parameters:

kwargs_cosmo – cosmology parameter keyword argument list

Returns:

astropy.cosmology (or equivalent interpolation scheme class)

likelihood(args, kwargs_cosmo_interp=None)[source]
Parameters:
  • args – list of sampled parameters

  • kwargs_cosmo_interp (dict) – interpolated angular diameter distances with ‘ang_diameter_distances’ and ‘redshifts’, and optionally ‘ok’ and ‘K’ in none-flat scenarios

Returns:

log likelihood of the combined lenses

hierarc.Likelihood.hierarchy_likelihood module

class hierarc.Likelihood.hierarchy_likelihood.LensLikelihood(z_lens, z_source, name='name', likelihood_type='TDKin', anisotropy_model='NONE', ani_param_array=None, ani_scaling_array=None, ani_scaling_array_list=None, gamma_in_array=None, log_m2l_array=None, param_scaling_grid_list=None, num_distribution_draws=50, global_los_distribution=False, kappa_pdf=None, kappa_bin_edges=None, mst_ifu=False, lambda_scaling_property=0, lambda_scaling_property_beta=0, normalized=True, kwargs_lens_properties=None, gamma_in_prior_mean=None, gamma_in_prior_std=None, los_distributions=None, **kwargs_likelihood)[source]

Bases: TransformedCosmography, LensLikelihoodBase, ParameterScalingIFU

Master class containing the likelihood definitions of different analysis for a single lens.

angular_diameter_distances(cosmo)[source]

Time-delay distance Ddt, angular diameter distance to the lens (dd)

Parameters:

cosmo – astropy.cosmology instance (or equivalent with interpolation)

Returns:

ddt, dd, ds in units physical Mpc

check_dist(kwargs_lens, kwargs_kin, kwargs_source, kwargs_los)[source]

Checks if the provided keyword arguments describe a distribution function of hyper parameters or are single values.

Parameters:
  • kwargs_lens – lens model hyper-parameter keywords

  • kwargs_kin – kinematic model hyper-parameter keywords

  • kwargs_source – source brightness hyper-parameter keywords

  • kwargs_los – list of dictionaries for line of sight hyper-parameters

Returns:

bool, True if delta function, else False

ddt_dd_model_prediction(cosmo, kwargs_lens=None, kwargs_los=None)[source]

Predicts the model uncertainty corrected ddt prediction of the applied model (e.g. power-law)

Parameters:
  • cosmo – astropy.cosmology instance

  • kwargs_lens – keywords of the hyper parameters of the lens model

  • kwargs_los – line of slight list of dictionaries

Returns:

ddt_model mean, ddt_model sigma, dd_model mean, dd_model sigma

draw_lens(lambda_mst=1, lambda_mst_sigma=0, gamma_ppn=1, lambda_ifu=1, lambda_ifu_sigma=0, alpha_lambda=0, beta_lambda=0, gamma_in=1, gamma_in_sigma=0, alpha_gamma_in=0, log_m2l=1, log_m2l_sigma=0, alpha_log_m2l=0)[source]

Draws a realization of a specific model from the hyper-parameter distribution.

Parameters:
  • lambda_mst – MST transform

  • lambda_mst_sigma – spread in the distribution

  • gamma_ppn – Post-Newtonian parameter

  • lambda_ifu – secondary lambda_mst parameter for subset of lenses specified for

  • lambda_ifu_sigma – secondary lambda_mst_sigma parameter for subset of lenses specified for

  • alpha_lambda – float, linear slope of the lambda_int scaling relation with lens quantity self._lambda_scaling_property

  • beta_lambda – float, a second linear slope of the lambda_int scaling relation with lens quantity self._lambda_scaling_property_beta

  • gamma_in – inner slope of the NFW profile

  • gamma_in_sigma – spread in the distribution

  • alpha_gamma_in – float, linear slope of the gamma_in scaling relation with lens quantity self._lambda_scaling_property

  • log_m2l – log(mass-to-light ratio)

  • log_m2l_sigma – spread in the distribution

  • alpha_log_m2l – float, linear slope of the log(m2l) scaling relation with lens quantity self._lambda_scaling_property

Returns:

draw from the distributions

draw_lens_scaling_params(lambda_mst=1, lambda_mst_sigma=0, kappa_ext=0, kappa_ext_sigma=0, gamma_ppn=1, lambda_ifu=1, lambda_ifu_sigma=0, alpha_lambda=0, beta_lambda=0, gamma_in=1, gamma_in_sigma=0, alpha_gamma_in=0, log_m2l=1, log_m2l_sigma=0, alpha_log_m2l=0)[source]

Draws a realization of the anisotropy parameter scaling from the distribution.

Parameters:
  • lambda_mst – MST transform

  • lambda_mst_sigma – spread in the distribution

  • kappa_ext – external convergence mean in distribution

  • kappa_ext_sigma – spread in the distribution

  • gamma_ppn – Post-Newtonian parameter

  • lambda_ifu – secondary lambda_mst parameter for subset of lenses specified for

  • lambda_ifu_sigma – secondary lambda_mst_sigma parameter for subset of lenses specified for

  • alpha_lambda – float, linear slope of the lambda_int scaling relation with lens quantity self._lambda_scaling_property

  • beta_lambda – float, a second linear slope of the lambda_int scaling relation with lens quantity self._lambda_scaling_property_beta

  • gamma_in – inner slope of the NFW profile

  • gamma_in_sigma – spread in the distribution

  • alpha_gamma_in – float, linear slope of the gamma_in scaling relation with lens quantity self._lambda_scaling_property

  • log_m2l – log(mass-to-light ratio)

  • log_m2l_sigma – spread in the distribution

  • alpha_log_m2l – float, linear slope of the log(m2l) scaling relation with lens quantity self._lambda_scaling_property

Returns:

draw from the distributions

draw_scaling_params(kwargs_lens=None, **kwargs_kin)[source]

Draws a realization of the anisotropy parameter scaling from the distribution function.

Returns:

array of anisotropy parameter scaling

static draw_source(mu_sne=1, sigma_sne=0, lum_dist=0, **kwargs)[source]

Draws a source magnitude from a distribution specified by population parameters.

Parameters:
  • mu_sne – mean magnitude of SNe

  • sigma_sne – std of magnitude distribution of SNe relative to the mean magnitude

  • lum_dist – luminosity distance (astronomical magnitude scaling of defined brightness to the source redshift)

Returns:

realization of source amplitude given distribution

hyper_param_likelihood(ddt, dd, delta_lum_dist, kwargs_lens=None, kwargs_kin=None, kwargs_source=None, kwargs_los=None, cosmo=None)[source]

Log likelihood of the data of a lens given a model (defined with hyper- parameters) and cosmological distances.

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • delta_lum_dist – relative luminosity distance to pivot redshift

  • kwargs_lens – keywords of the hyper parameters of the lens model

  • kwargs_kin – keyword arguments of the kinematic model hyper parameters

  • kwargs_source – keyword argument of the source model (such as SNe)

  • kwargs_los – list of keyword arguments of global line of sight distributions

  • cosmo – astropy.cosmology instance

Returns:

log likelihood given the single lens analysis for the given hyper parameter

lens_log_likelihood(cosmo, kwargs_lens=None, kwargs_kin=None, kwargs_source=None, kwargs_los=None)[source]

Log likelihood of the data of a lens given a model (defined with hyper- parameters) and cosmology.

Parameters:
  • cosmo – astropy.cosmology instance

  • kwargs_lens – keywords of the hyper parameters of the lens model

  • kwargs_kin – keyword arguments of the kinematic model hyper parameters

  • kwargs_source – keyword argument of the source model (such as SNe)

  • kwargs_los – list of keyword arguments of global line of sight distributions

Returns:

log likelihood of the data given the model

log_likelihood_single(ddt, dd, delta_lum_dist, kwargs_lens, kwargs_kin, kwargs_source, kwargs_los=None, sigma_v_sys_error=None)[source]

Log likelihood of the data of a lens given a specific model (as a draw from hyper-parameters) and cosmological distances.

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • delta_lum_dist – relative luminosity distance to pivot redshift

  • kwargs_lens – keywords of the hyper parameters of the lens model

  • kwargs_kin – keyword arguments of the kinematic model hyper parameters

  • kwargs_source – keyword arguments of source brightness

  • kwargs_los – line of sight list of dictionaries

  • sigma_v_sys_error – unaccounted uncertainty in the velocity dispersion measurement

Returns:

log likelihood given the single lens analysis for a single (random) realization of the hyper parameter distribution

luminosity_distance_modulus(cosmo, z_apparent_m_anchor)[source]

The difference in luminosity distance between a pivot redshift (z_apparent_m_anchor) and the source redshift (effectively the ratio as this is the magnitude transform)

Parameters:
  • cosmo – astropy.cosmology instance (or equivalent with interpolation)

  • z_apparent_m_anchor – redshift of pivot/anchor at which the apparent SNe brightness is defined relative to

Returns:

lum_dist(z_source) - lum_dist(z_pivot)

sigma_v_measured_vs_predict(cosmo, kwargs_lens=None, kwargs_kin=None, kwargs_los=None)[source]

Mean and error covariance of velocity dispersion measurement mean and error covariance of velocity dispersion predictions.

Parameters:
  • cosmo – astropy.cosmology instance

  • kwargs_lens – keywords of the hyper parameters of the lens model

  • kwargs_kin – keyword arguments of the kinematic model hyper-parameters

  • kwargs_los – line of sight parapers

Returns:

sigma_v_measurement, cov_error_measurement, sigma_v_predict_mean, cov_error_predict

hierarc.Likelihood.lens_sample_likelihood module

class hierarc.Likelihood.lens_sample_likelihood.LensSampleLikelihood(kwargs_lens_list, normalized=False, los_distributions=None)[source]

Bases: object

Class to evaluate the likelihood of a cosmology given a sample of angular diameter posteriors Currently this class does not include possible covariances between the lens samples.

log_likelihood(cosmo, kwargs_lens=None, kwargs_kin=None, kwargs_source=None, kwargs_los=None)[source]
Parameters:
  • cosmo – astropy.cosmology instance

  • kwargs_lens – keywords of the parameters of the lens model

  • kwargs_kin – keyword arguments of the kinematic model

  • kwargs_source – keyword argument of the source model (such as SNe)

  • kwargs_los – line of sight keyword argument list

Returns:

log likelihood of the combined lenses

num_data()[source]

Number of data points across the lens sample.

Returns:

integer

hierarc.Likelihood.transformed_cosmography module

class hierarc.Likelihood.transformed_cosmography.TransformedCosmography(z_lens, z_source)[source]

Bases: object

Class to manage hierarchical hyper-parameter that impact the cosmographic posterior interpretation of individual lenses.

displace_prediction(ddt, dd, gamma_ppn=1, lambda_mst=1, kappa_ext=0, mag_source=0)[source]

Here we effectively change the posteriors of the lens, but rather than changing the instance of the KDE we displace the predicted angular diameter distances in the opposite direction The displacements form different effects are multiplicative and thus invariant under the order those displacements are applied.

Parameters:
  • ddt – time-delay distance

  • dd – angular diameter distance to the deflector

  • lambda_mst – overall global mass-sheet transform applied on the sample, lambda_mst=1 corresponds to the input model

  • gamma_ppn – post-newtonian gravity parameter (=1 is GR)

  • kappa_ext – external convergence to be added on top of the D_dt posterior

  • mag_source – source magnitude (attention, log scale, thus transform needs to be changed!)

Returns:

ddt, dd, mag_source

Module contents