h0rton.h0_inference.mcmc_utils
¶
Module Contents¶
Classes¶
HybridBNNPenalty |
Wrapper for subclasses of BaseGaussianNLL that allows MCMC methods to appropriately penalize parameter samples |
Functions¶
get_lens_kwargs (init_dict, null_spread=False) |
Get the SPEMD, SHEAR kwargs with the provided init values and some conservative sigma, fixed, lower, and upper |
get_ps_kwargs (measured_img_ra, measured_img_dec, astrometry_sigma, hard_bound=30.0) |
Get the point source kwargs for the image positions |
get_ps_kwargs_src_plane (init_dict, astrometry_sigma, hard_bound=5.0) |
Get the point source kwargs for the source plane |
get_light_kwargs (init_R, null_spread=False) |
Get the usual sigma, lower, upper, and fixed kwargs for a SERSIC_ELLIPSE light with only the R_sersic allowed to vary |
get_special_kwargs (n_img, astrometry_sigma, delta_pos_hard_bound=5.0, D_dt_init=5000.0, D_dt_sigma=1000.0, D_dt_lower=0.0, D_dt_upper=15000.0) |
Get the point source kwargs for the image positions |
postprocess_mcmc_chain (kwargs_result, samples, kwargs_model, fixed_lens_kwargs, fixed_ps_kwargs, fixed_src_light_kwargs, fixed_special_kwargs, kwargs_constraints, kwargs_fixed_lens_light=None, verbose=False, forward_modeling=False) |
Postprocess the MCMC chain for making the chains consistent with the optimized lens model and converting parameters |
get_idx_for_params (out_dim, Y_cols, params_to_remove, likelihood_class, debug=False) |
Get columns corresponding to certain parameters from the BNN output |
remove_parameters_from_pred (orig_pred, remove_idx, return_as_tensor=True, device=’cpu’) |
Remove columns corresponding to certain parameters from the BNN output |
split_component_param (string, sep=’_’, pos=2) |
Split the component, e.g. lens_mass, from the parameter, e.g. center_x, from the paramter names under the Baobab convention |
dict_to_array (Y_cols, kwargs_lens, kwargs_source, kwargs_lens_light=None, kwargs_ps=None) |
Reformat kwargs into np array. Used to feed the current iteration of MCMC kwargs into the BNN posterior evaluation. |
-
h0rton.h0_inference.mcmc_utils.
get_lens_kwargs
(init_dict, null_spread=False)[source]¶ Get the SPEMD, SHEAR kwargs with the provided init values and some conservative sigma, fixed, lower, and upper
The sigma, fixed, lower, and upper kwargs are hardcoded.
- init_dict : dict
- the init values for each of the parameters in SPEMD and SHEAR
-
h0rton.h0_inference.mcmc_utils.
get_ps_kwargs
(measured_img_ra, measured_img_dec, astrometry_sigma, hard_bound=30.0)[source]¶ Get the point source kwargs for the image positions
- measured_img_ra : np.array
- measured ra of the images
- measured_img_dec : np.array
- measured dec of the images
- astrometry_sigma : float
- astrometric uncertainty in arcsec
- hard_bound : float
- hard bound of the image positions around zero in arcsec
- list of dict
- list of init, sigma, fixed, lower, and upper kwargs
-
h0rton.h0_inference.mcmc_utils.
get_ps_kwargs_src_plane
(init_dict, astrometry_sigma, hard_bound=5.0)[source]¶ Get the point source kwargs for the source plane
- measured_img_ra : np.array
- measured ra of the images
- measured_img_dec : np.array
- measured dec of the images
- astrometry_sigma : float
- astrometric uncertainty in arcsec
- hard_bound : float
- hard bound of the image positions around zero in arcsec
- list of dict
- list of init, sigma, fixed, lower, and upper kwargs
-
h0rton.h0_inference.mcmc_utils.
get_light_kwargs
(init_R, null_spread=False)[source]¶ Get the usual sigma, lower, upper, and fixed kwargs for a SERSIC_ELLIPSE light with only the R_sersic allowed to vary
-
h0rton.h0_inference.mcmc_utils.
get_special_kwargs
(n_img, astrometry_sigma, delta_pos_hard_bound=5.0, D_dt_init=5000.0, D_dt_sigma=1000.0, D_dt_lower=0.0, D_dt_upper=15000.0)[source]¶ Get the point source kwargs for the image positions
- measured_img_ra : np.array
- measured ra of the images
- measured_img_dec : np.array
- measured dec of the images
- astrometry_sigma : float
- astrometric uncertainty in arcsec
- hard_bound : float
- hard bound of the image positions around zero in arcsec
- list of dict
- list of init, sigma, fixed, lower, and upper kwargs
-
h0rton.h0_inference.mcmc_utils.
postprocess_mcmc_chain
(kwargs_result, samples, kwargs_model, fixed_lens_kwargs, fixed_ps_kwargs, fixed_src_light_kwargs, fixed_special_kwargs, kwargs_constraints, kwargs_fixed_lens_light=None, verbose=False, forward_modeling=False)[source]¶ Postprocess the MCMC chain for making the chains consistent with the optimized lens model and converting parameters
- pandas.DataFrame
- processed MCMC chain, where each row is a sample
-
class
h0rton.h0_inference.mcmc_utils.
HybridBNNPenalty
(Y_cols, likelihood_class, mcmc_train_Y_mean, mcmc_train_Y_std, exclude_vel_disp, device)[source]¶ Wrapper for subclasses of BaseGaussianNLL that allows MCMC methods to appropriately penalize parameter samples
-
h0rton.h0_inference.mcmc_utils.
get_idx_for_params
(out_dim, Y_cols, params_to_remove, likelihood_class, debug=False)[source]¶ Get columns corresponding to certain parameters from the BNN output
out_dim : int Y_cols : list of str
- remove_idx : list
- indices of the columns removed in orig_pred
- remove_param_idx : list
- indices of the parameters in Y_cols
-
h0rton.h0_inference.mcmc_utils.
remove_parameters_from_pred
(orig_pred, remove_idx, return_as_tensor=True, device='cpu')[source]¶ Remove columns corresponding to certain parameters from the BNN output
- orig_pred : np.array of shape [n_lenses, out_dim]
- the BNN output
- orig_Y_cols : list of str
- the original list of Y columns
- params_to_remove : list of str
- list of colums to remove. They must belong to orig_Y_cols
new_pred : np.array of shape [n_lenses, out_dim - len(params_to_remove)]
-
h0rton.h0_inference.mcmc_utils.
split_component_param
(string, sep='_', pos=2)[source]¶ Split the component, e.g. lens_mass, from the parameter, e.g. center_x, from the paramter names under the Baobab convention
- string : str
- the Baobab parameter name (column name)
- sep : str
- separation character between the component and the parameter. Default: ‘_’ (Baobab convention)
- pos : int
- position of the component when split by the separation character. Default: 2 (Baobab convention)
- tuple of str
- component, parameter