fgbuster.algebra¶
Low-level component separation functions
All the routines in this module do NOT support numpy.ma.MaskedArray
.
In that case, you have two options
Index masked_array with a mask so that you get a standard np.array containing only unmasked values
Whenever it is possible, you can pass masked_array.data and handle the masked values by setting the corresponding entries of invN to zero
Functions
|
|
|
|
|
Second Derivative of P |
|
|
|
Derivative of W |
|
Second Derivative of W |
|
|
|
Perform component separation |
|
|
|
|
|
|
|
Derivative of the log likelihood |
|
Perform component separation |
|
Provide a verbose callback function |
-
fgbuster.algebra.
comp_sep
(A_ev, d, invN, A_dB_ev, comp_of_dB, *minimize_args, **minimize_kwargs)[source]¶ Perform component separation
Build the (inverse) spectral likelihood and minimize it to estimate the parameters of the mixing matrix. Separate the components using the best-fit mixing matrix.
- Parameters
A_ev (function) – The evaluator of the mixing matrix. It takes a float or an array as argument and returns the mixing matrix, a ndarray with shape (…, n_freq, n_comp)
d (ndarray) – The data vector. Shape (…, n_freq).
invN (ndarray or None) – The inverse noise matrix. Shape (…, n_freq, n_freq).
A_dB_ev (function) – The evaluator of the derivative of the mixing matrix. It returns a list, each entry is the derivative with respect to a different parameter.
comp_of_dB (tuple or list of tuples) – It allows to provide as output of A_dB_ev only the non-zero columns A. If list, every entry refers to a parameter. Tuple(s) can have lenght 1 or 2. The first element is the index (or slice) of the component dimension of A (the last one) that is affected by the derivative:
A_dB_ev(x)[i]
is assumed to be the derivative ofA[..., comp_of_dB[i]]
. The second element of the touple, if present, is an array of integers. It can be used to specify that the same parameter is actually fitted for indpendentely on different sections of the … dimension(s). The index identifying these regions are collected in the array.minimize_args (list) – Positional arguments to be passed to scipy.optimize.minimize. At this moment it just contains x0, the initial guess for the spectral parameters
minimize_kwargs (dict) – Keyword arguments to be passed to scipy.optimize.minimize. A good choice for most cases is
minimize_kwargs = {'tol': 1, options: {'disp': True}}
. tol depends on both the solver and your signal to noise: it should ensure that the difference between the best fit -logL and and the minimum is well less then 1, without exagereting (a difference of 1e-4 is useless). disp also triggers a verbose callback that monitors the convergence.
- Returns
result – Result of the spectral likelihood maximisation It is the output of scipy.optimize.minimize, plus some extra. It includes
x: (ndarray) - the best-fit spectra indices
Sigma: (ndarray) - the semi-analytic covariance of the best-fit spectra indices patch.
s: (ndarray) - Separated components, Shape (…, n_comp)
invAtNA : (ndarray) - Covariance of the separated components. Shape (…, n_comp, n_comp)
- Return type
scipy.optimze.OptimizeResult (dict)
Note
The … in the arguments denote any extra set of dimension. They have to be compatible among different arguments in the numpy broadcasting sense.
-
fgbuster.algebra.
multi_comp_sep
(A_ev, d, invN, A_dB_ev, comp_of_dB, patch_ids, *minimize_args, **minimize_kargs)[source]¶ Perform component separation
Run an independent
comp_sep()
for entries identified by patch_ids and gathers the result.- Parameters
A_ev (function or ndarray) – The evaluator of the mixing matrix. It takes a float or an array as argument and returns the mixing matrix, a ndarray with shape (…, n_freq, n_comp) If list, the i-th entry is the evaluator of the i-th patch.
d (ndarray) – The data vector. Shape (…, n_freq).
invN (ndarray or None) – The inverse noise matrix. Shape (…, n_freq, n_freq). If a block of invN has a diagonal element equal to zero the corresponding entries of d are masked.
A_dB_ev (function) – The evaluator of the derivative of the mixing matrix. It returns a list, each entry is the derivative with respect to a different parameter.
comp_of_dB (tuple or list of tuples) – It allows to provide as output of A_dB_ev only the non-zero columns A. If list, every entry refers to a parameter. Due to the presence of the patch_ids arguemnt, unlike comp_sep the tuple(s) can have only lenght 1. The element is the index (or slice) of the component dimension of A (the last one) that is affected by the derivative:
A_dB_ev(x)[i]
is assumed to be the derivative ofA[..., comp_of_dB[i]]
.patch_ids (array) – id of regions.
minimize_args (list) – Positional arguments to be passed to scipy.optimize.minimize. At this moment, it just contains x0, the initial guess for the spectral parameters. It is required if A_ev is a function and ignored otherwise.
minimize_kwargs (dict) – Keyword arguments to be passed to scipy.optimize.minimize. A good choice for most cases is
minimize_kwargs = {'tol': 1, options: {'disp': True}}
. tol depends on both the solver and your signal-to-noise: it should ensure that the difference between the best fit -logL and the minimum is way less than 1, without exagerating (a difference of 1e-4 is useless). disp also triggers a verbose callback that monitors the convergence.
- Returns
result – It gathers the results of the component separation on each patch. It includes
x: (ndarray) -
x[i]
contains the best-fit spectra indices from the i-th patch. Shape (n_patches, n_param)Sigma: (ndarray) -
Sigma[i]
contains the semi-analytic covariance of the best-fit spectra indices estimated from the i-th patch. Shape (n_patches, n_param, n_param)s: (ndarray) - Separated components, collected from all the patches. Shape (…, n_comp)
patch_res: (list) - the i-th entry is the result of
comp_sep()
onpatch_ids == i
(with the exception of the quantities collected from all the patches)
- Return type
dict
Note
The … in the arguments denote any extra set of dimension. They have to be compatible among different arguments in the numpy broadcasting sense.
-
fgbuster.algebra.
logL_dB
(A, d, invN, A_dB, comp_of_dB=slice(None, None, None), return_svd=False)[source]¶ Derivative of the log likelihood
- Parameters
A (ndarray) – Mixing matrix. Shape (…, n_freq, n_comp)
d (ndarray) – The data vector. Shape (…, n_freq).
invN (ndarray or None) – The inverse noise matrix. Shape (…, n_freq, n_freq).
A_dB (ndarray or list of ndarray) – The derivative of the mixing matrix. If list, each entry is the derivative with respect to a different parameter.
comp_of_dB (tuple or list of tuples) – It allows to provide as output of A_dB_ev only the non-zero columns A. If list, every entry refers to a parameter. Tuple(s) can have lenght 1 or 2. The first element is the index (or slice) of the component dimension of A (the last one) that is affected by the derivative:
A_dB_ev(x)[i]
is assumed to be the derivative ofA[..., comp_of_dB[i]]
. The second element of the touple, if present, is an array of integers. It can be used to specify that the same parameter is actually fitted for indpendentely on different sections of the … dimension(s). The index identifying these regions are collected in the array.
- Returns
diff – Derivative of the spectral likelihood. If A_dB is a list,
diff[i]
is computed fromA_dB[i]
.- Return type
array
Note
The … in the shape of the arguments denote any extra set of dimensions. They have to be compatible among different arguments in the numpy broadcasting sense.
-
fgbuster.algebra.
P_dBdB
(A, A_dB, A_dBdB, comp_of_dB, invN=None, return_svd=False)[source]¶ Second Derivative of P
which could be useful for the computation of curvature of the log likelihood for any point and data vector
- Parameters
A (ndarray) – Mixing matrix. Shape (…, n_freq, n_comp)
invN (ndarray or None) – The inverse noise matrix. Shape (…, n_freq, n_freq).
A_dB (ndarray or list of ndarray) – The derivative of the mixing matrix. If list, each entry is the derivative with respect to a different parameter.
A_dBdB (ndarray or list of list of ndarray) – The second derivative of the mixing matrix. If list, each entry is the derivative of A_dB with respect to a different parameter.
comp_of_dB (tuple or list of tuples) – It allows to provide as output of A_dB_ev only the non-zero columns A. If list, every entry refers to a parameter. Unlike comp_sep the tuple(s) can have only lenght 1. The element is the index (or slice) of the component dimension of A (the last one) that is affected by the derivative:
A_dB_ev(x)[i]
is assumed to be the derivative ofA[..., comp_of_dB[i]]
.
- Returns
res – Second Derivative of P.
- Return type
array
-
fgbuster.algebra.
W_dB
(A, A_dB, comp_of_dB, invN=None, return_svd=False)[source]¶ Derivative of W
which could be particularly useful for the computation of residuals through the first order development of the map-making equation
- Parameters
A (ndarray) – Mixing matrix. Shape (…, n_freq, n_comp)
invN (ndarray or None) – The inverse noise matrix. Shape (…, n_freq, n_freq).
A_dB (ndarray or list of ndarray) – The derivative of the mixing matrix. If list, each entry is the derivative with respect to a different parameter.
comp_of_dB (tuple or list of tuples) – It allows to provide as output of A_dB_ev only the non-zero columns A. If list, every entry refers to a parameter. Unlike comp_sep the tuple(s) can have only lenght 1. The element is the index (or slice) of the component dimension of A (the last one) that is affected by the derivative:
A_dB_ev(x)[i]
is assumed to be the derivative ofA[..., comp_of_dB[i]]
.
- Returns
res – Derivative of W. If A_dB is a list,
res[i]
is computed fromA_dB[i]
.- Return type
array
-
fgbuster.algebra.
W_dBdB
(A, A_dB, A_dBdB, comp_of_dB, invN=None, return_svd=False)[source]¶ Second Derivative of W
which could be particularly useful for the computation of statistical residuals through the second order development of the map-making equation
- Parameters
A (ndarray) – Mixing matrix. Shape (…, n_freq, n_comp)
invN (ndarray or None) – The inverse noise matrix. Shape (…, n_freq, n_freq).
A_dB (ndarray or list of ndarray) – The derivative of the mixing matrix. If list, each entry is the derivative with respect to a different parameter.
A_dBdB (ndarray or list of list of ndarray) – The second derivative of the mixing matrix. If list, each entry is the derivative of A_dB with respect to a different parameter.
comp_of_dB (tuple or list of tuples) – It allows to provide as output of A_dB_ev only the non-zero columns A. If list, every entry refers to a parameter. Unlike comp_sep the tuple(s) can have only lenght 1. The element is the index (or slice) of the component dimension of A (the last one) that is affected by the derivative:
A_dB_ev(x)[i]
is assumed to be the derivative ofA[..., comp_of_dB[i]]
.
- Returns
res – Second Derivative of W.
- Return type
array