micmac.likelihood.harmonic module¶
-
class HarmonicMicmacSampler(nside, lmax, nstokes, frequency_array, freq_noise_c_ell, pos_special_freqs=
[0, -1], n_components=3, lmin=2, n_iter=8, mask=None, spv_nodes_b=[], biased_version=False, boundary_Bf=None, boundary_r=None, step_size_r=0.0001, covariance_Bf=None, indexes_free_Bf=False, number_iterations_sampling=100, number_iterations_done=0, seed=0, disable_chex=True, instrument_name='SO_SAT')[source]¶ Bases:
SamplingFunctionsMain MICMAC Harmonic sampling object to initialize and launch the Metropolis-Hastings (MH) sampling in harmonic domain. The MH sampling will store Bf and r parameters.
- Parameters:
- nside : int¶
nside of the input frequency maps
- lmax : int¶
maximum multipole for the spherical harmonics transforms and harmonic domain objects,
- nstokes : int¶
number of Stokes parameters
- frequency_array : array[float]¶
array of frequencies, in GHz
- freq_noise_c_ell : array[float] of dimensions [frequencies, frequencies, lmax+1-lmin] or [frequencies, frequencies, lmax] (in which case it will be cut to lmax+1-lmin)¶
optional, noise power spectra for each frequency, in uK^2, dimensions
- pos_special_freqs : list[int] (optional)¶
indexes of the special frequencies in the frequency array respectively for synchrotron and dust, default is [0,-1] for first and last frequencies
- n_components : int (optional)¶
number of components for the mixing matrix, default 3
- lmin : int (optional)¶
minimum multipole for the spherical harmonics transforms and harmonic domain objects, default 2
- n_iter : int (optional)¶
number of iterations the spherical harmonics transforms (for map2alm transformations), default 8
- mask : None or array[float] of dimensions [n_pix] (optional)¶
mask to use in the sampling ; if not given, no mask is used, default None Note: the mask WILL NOT be applied to the input maps, it will be only used for the propagated noise covariance WARNING: Masked input are not currently supported, expect E-to-B leakage
- spv_nodes_b : list[dictionaries] (optional)¶
tree for the spatial variability, to generate from a yaml file, default [] in principle set up by get_nodes_b WARNING: The spatial variability is not currently supported, but will be passed to MicmacSampler obj when using create_Harmonic_MicmacSampler_from_MicmacSampler_obj
- biased_version : bool (optional)¶
use the biased version of the likelihood, so no computation of the correction term, default False
- boundary_Bf : None or array[float] (optional)¶
minimum and maximum Bf values accepted for Bf sample, set to [-inf,inf] for each Bf parameter if None, default None
- boundary_r : None or array[float] (optional)¶
minimum and maximum r values accepted for r sample, set to [-inf,inf] if None, default None
- step_size_r : float (optional)¶
step size for the Metropolis-Hastings sampling of r, default 1e-4
- covariance_Bf : None or array[float] of dimensions [(n_frequencies-len(pos_special_freqs))*(n_components-1), (n_frequencies-len(pos_special_freqs))*(n_components-1)] (optional)¶
covariance for the Metropolis-Hastings sampling of Bf ; will be repeated if multiresoltion case, default None
- number_iterations_sampling : int (optional)¶
maximum number of iterations for the sampling, default 100
- number_iterations_done : int (optional)¶
number of iterations already accomplished, in case the chain is resuming from a previous run, usually set by exterior routines, default 0
- seed : int or array[jnp.uint32] (optional)¶
seed for the JAX PRNG random number generator to start the chain or array of a previously computed seed, default 0
- disable_chex : bool (optional)¶
disable chex tests (to improve speed)
- instrument_name : str (optional)¶
name of the instrument as expected by cmbdb or given as ‘customized_instrument’ if redefined by user, default ‘SO_SAT’ see https://github.com/dpole/cmbdb/blob/master/cmbdb/experiments.yaml
-
__init__(nside, lmax, nstokes, frequency_array, freq_noise_c_ell, pos_special_freqs=
[0, -1], n_components=3, lmin=2, n_iter=8, mask=None, spv_nodes_b=[], biased_version=False, boundary_Bf=None, boundary_r=None, step_size_r=0.0001, covariance_Bf=None, indexes_free_Bf=False, number_iterations_sampling=100, number_iterations_done=0, seed=0, disable_chex=True, instrument_name='SO_SAT')[source]¶ Main MICMAC Harmonic sampling object to initialize and launch the Metropolis-Hastings (MH) sampling in harmonic domain. The MH sampling will store Bf and r parameters.
- Parameters:
- nside : int¶
nside of the input frequency maps
- lmax : int¶
maximum multipole for the spherical harmonics transforms and harmonic domain objects,
- nstokes : int¶
number of Stokes parameters
- frequency_array : array[float]¶
array of frequencies, in GHz
- freq_noise_c_ell : array[float] of dimensions [frequencies, frequencies, lmax+1-lmin] or [frequencies, frequencies, lmax] (in which case it will be cut to lmax+1-lmin)¶
optional, noise power spectra for each frequency, in uK^2, dimensions
- pos_special_freqs : list[int] (optional)¶
indexes of the special frequencies in the frequency array respectively for synchrotron and dust, default is [0,-1] for first and last frequencies
- n_components : int (optional)¶
number of components for the mixing matrix, default 3
- lmin : int (optional)¶
minimum multipole for the spherical harmonics transforms and harmonic domain objects, default 2
- n_iter : int (optional)¶
number of iterations the spherical harmonics transforms (for map2alm transformations), default 8
- mask : None or array[float] of dimensions [n_pix] (optional)¶
mask to use in the sampling ; if not given, no mask is used, default None Note: the mask WILL NOT be applied to the input maps, it will be only used for the propagated noise covariance WARNING: Masked input are not currently supported, expect E-to-B leakage
- spv_nodes_b : list[dictionaries] (optional)¶
tree for the spatial variability, to generate from a yaml file, default [] in principle set up by get_nodes_b WARNING: The spatial variability is not currently supported, but will be passed to MicmacSampler obj when using create_Harmonic_MicmacSampler_from_MicmacSampler_obj
- biased_version : bool (optional)¶
use the biased version of the likelihood, so no computation of the correction term, default False
- boundary_Bf : None or array[float] (optional)¶
minimum and maximum Bf values accepted for Bf sample, set to [-inf,inf] for each Bf parameter if None, default None
- boundary_r : None or array[float] (optional)¶
minimum and maximum r values accepted for r sample, set to [-inf,inf] if None, default None
- step_size_r : float (optional)¶
step size for the Metropolis-Hastings sampling of r, default 1e-4
- covariance_Bf : None or array[float] of dimensions [(n_frequencies-len(pos_special_freqs))*(n_components-1), (n_frequencies-len(pos_special_freqs))*(n_components-1)] (optional)¶
covariance for the Metropolis-Hastings sampling of Bf ; will be repeated if multiresoltion case, default None
- number_iterations_sampling : int (optional)¶
maximum number of iterations for the sampling, default 100
- number_iterations_done : int (optional)¶
number of iterations already accomplished, in case the chain is resuming from a previous run, usually set by exterior routines, default 0
- seed : int or array[jnp.uint32] (optional)¶
seed for the JAX PRNG random number generator to start the chain or array of a previously computed seed, default 0
- disable_chex : bool (optional)¶
disable chex tests (to improve speed)
- instrument_name : str (optional)¶
name of the instrument as expected by cmbdb or given as ‘customized_instrument’ if redefined by user, default ‘SO_SAT’ see https://github.com/dpole/cmbdb/blob/master/cmbdb/experiments.yaml
- compute_covariance_from_samples()[source]¶
Compute the covariance matrix from the sample chains of Bf and r
- Returns:
covariance_Bf_r – covariance matrix of the samples of Bf and r
- Return type:
array[float]
-
generate_CMB(return_spectra=
True)[source]¶ Returns CMB spectra of scalar modes only and tensor modes only (with r=1) Both CMB spectra are either returned in the usual form [number_correlations,lmax+1], or in the red_cov form if return_spectra == False
-
generate_input_freq_maps_from_fgs(freq_maps_fgs, r_true=
0, return_only_freq_maps=True, return_only_maps=False)[source]¶ Generate input frequency maps (CMB+foregrounds) from the input frequency foregrounds maps, return either the full frequency maps, the full frequency and CMB maps alone, or the full frequency and CMB maps with the theoretical reduced covariance matrices for the CMB scalar and tensor modes
- Parameters:
- Returns:
input_freq_maps (array[float] of dimensions [n_frequencies,nstokes,n_pix]) – input frequency maps
input_cmb_maps (array[float] of dimensions [nstokes,n_pix]) – input CMB maps
theoretical_red_cov_r0_total (array[float] of dimensions [lmax+1-lmin,nstokes,nstokes]) – theoretical reduced covariance matrix for the CMB scalar modes
theoretical_red_cov_r1_tensor (array[float] of dimensions [lmax+1-lmin,nstokes,nstokes]) – theoretical reduced covariance matrix for the CMB tensor modes
- get_alm_from_frequency_maps(input_freq_maps)[source]¶
Get the alms from the input frequency maps using JAX
- Parameters:
- Returns:
freq_alms_input_maps – alms from the input frequency maps the (lmax+1)*(lmax+2)//2 dimension is the flattened number of lm coefficients stored according to the Healpy convention
- Return type:
array[float] of dimensions [n_frequencies,nstokes,(lmax+1)*(lmax+2)//2]
-
perform_harmonic_MH(input_freq_maps, c_ell_approx, init_params_mixing_matrix, theoretical_r0_total, theoretical_r1_tensor, initial_guess_r=
0, covariance_Bf_r=None, input_freq_alms=None, print_bool=True)[source]¶ Perform Metropolis Hastings to find the best r and Bf in harmonic domain. The chains will be stored as object attributes:
all_samples_r for r
all_params_mixing_matrix_samples for Bf
- Parameters:
- input_freq_maps : array[float] of dimensions [n_frequencies,nstokes,n_pix]¶
input frequency maps
- c_ell_approx : array[float] of dimensions [number_correlations, lmax+1]¶
approximate CMB power spectra for the correction term
- init_params_mixing_matrix : array[float] of dimensions [n_frequencies-len(pos_special_freqs), n_correlations-1]¶
initial parameters for the mixing matrix
- theoretical_r0_total : array[float] of dimensions [lmax+1-lmin, number_correlations, number_correlations]¶
theoretical covariance matrix for the CMB scalar modes
- theoretical_r1_tensor : array[float] of dimensions [lmax+1-lmin, number_correlations, number_correlations]¶
theoretical covariance matrix for the CMB tensor modes
- initial_guess_r : float (optional)¶
initial guess for r, default 0
- covariance_Bf_r : None or array[float] of dimensions [(n_frequencies-len(pos_special_freqs))*(n_correlations-1) + 1, (n_frequencies-len(pos_special_freqs))*(n_correlations-1) + 1] (optional)¶
covariance for the Metropolis-Hastings sampling of Bf and r, default None
- input_freq_alms : array[float] of dimensions [n_frequencies,nstokes,(lmax + 1) * (lmax // 2 + 1)] (optional)¶
if provided, input_freq_alms is used instead of input_freq_maps for the MH steps
- print_bool : bool (optional)¶
option for test prints, default True
-
perform_harmonic_minimize(input_freq_maps, c_ell_approx, init_params_mixing_matrix, theoretical_r0_total, theoretical_r1_tensor, initial_guess_r=
0, method_used='ScipyMinimize', **options_minimizer)[source]¶ Perform a minimization to find the best r and Bf in harmonic domain. The results will be returned as the best parameters found.
- Parameters:
- input_freq_maps : array[float] of dimensions [n_frequencies,nstokes,n_pix]¶
input frequency maps
- c_ell_approx : array[float] of dimensions [number_correlations, lmax+1]¶
approximate CMB power spectra for the correction term
- init_params_mixing_matrix : array[float] of dimensions [n_frequencies-len(pos_special_freqs), n_correlations-1]¶
initial parameters for the mixing matrix
- theoretical_r0_total : array[float] of dimensions [lmax+1-lmin, number_correlations, number_correlations]¶
theoretical covariance matrix for the CMB scalar modes
- theoretical_r1_tensor : array[float] of dimensions [lmax+1-lmin, number_correlations, number_correlations]¶
theoretical covariance matrix for the CMB tensor modes
- initial_guess_r : float (optional)¶
initial guess for r, default 0
- method_used : str (optional)¶
method used for the minimization, default ‘ScipyMinimize’
- options_minimizer : dict (optional)¶
additional options dictionary for the minimizer
- Returns:
params – best parameters found
- Return type:
array[float] of dimensions [n_frequencies-len(pos_special_freqs)*(n_correlations-1) + 1]
- update_samples_MH(all_samples)[source]¶
Update the samples with new samples to add for r and Bf
- Parameters:
- all_samples : dictionary¶
dictionary of all the samples to update
- update_variable(all_samples, new_samples_to_add)[source]¶
Update the samples with new samples to add by stacking them