beetroots.modelling package

Subpackages

Submodules

beetroots.modelling.posterior module

class beetroots.modelling.posterior.Posterior(D: int, L: int, N: int, likelihood, prior_spatial=None, prior_indicator=None, separable: bool = True, dict_sites: Dict[int, ndarray] | None = None)[source]

Bases: object

D

number of distinct physical parameters

Type:

int

L

number of observables per pixel

Type:

int

N

number of pixels

Type:

int

compute_all(Theta: ndarray, idx_pix: ndarray | None = None, forward_map_evals: dict = {}, nll_utils: dict = {}, compute_derivatives: bool = True, compute_derivatives_2nd_order: bool = True) dict[source]

compute negative log pdf and derivatives of the posterior distribution

Parameters:
  • Theta (np.ndarray of shape (N, D)) – current iterate

  • forward_map_evals (dict[str, np.ndarray], optional) – output of the likelihood.evaluate_all_forward_map() method, by default {}

  • nll_utils (dict[str, np.ndarray], optional) – output of the likelihood.evaluate_all_nll_utils() method, by default {}

  • compute_derivatives (bool, optional) – wether to compte derivatives, by default True

Returns:

negative log pdf and derivatives of the posterior distribution

Return type:

dict[str, Union[float, np.ndarray]]

compute_all_for_saver(Theta: ndarray, forward_map_evals: dict[str, float | ndarray], nll_utils: dict) Tuple[dict[str, float | ndarray], ndarray][source]

computes negative log pdf of likelihood, priors and posterior (detailed values to be saved, not to be used in sampling)

Parameters:
  • Theta (np.ndarray of shape (N, D)) – current iterate

  • forward_map_evals (dict[str, Union[float, np.ndarray]]) – output of the likelihood.evaluate_all_forward_map() method

  • nll_utils ([str, Union[float, np.ndarray]]) – output of the likelihood.evaluate_all_nll_utils() method

Returns:

values to be saved

Return type:

dict[str, Union[float, np.ndarray]]

dict_sites

sites for pixels to be sampled in parallel in the MTM-chromoatic Gibbs kernel

Type:

dict[int, np.ndarray]

grad_neglog_pdf(Theta: ndarray, idx_pix: ndarray, forward_map_evals: dict[str, float | ndarray], nll_utils: dict[str, float | ndarray]) ndarray[source]
hess_diag_neglog_pdf(Theta: ndarray, idx_pix: ndarray, forward_map_evals: dict, nll_utils: dict) ndarray[source]
likelihood

data-fidelity term

Type:

Likelihood

mtm_neglog_pdf_priors(Theta: ndarray, idx_pix: ndarray, with_weights: bool | None = True, use_indicator_prior: bool | None = True, use_spatial_prior: bool | None = True, chromatic_gibbs: bool | None = True) ndarray[source]

computes the neg log-prior when only one pixel is modified

Parameters:
  • Theta (np.ndarray of shape (N, D)) – current iterate

  • idx_pix (int) – the index of the pixel to consider (0 <= idx_pix <= N - 1)

  • list_pixel_candidates (np.ndarray of shape (N_candidates, D)) – the list of all candidates for pixel idx_pi

  • spatial_weights (Optional[np.ndarray], optional) – vector of shape (D,) containing the weights of the spatial prior, by default None

  • use_indicator_prior (bool, optional) – wether to use the indicator prior term, by default True

  • use_spatial_prior (bool, optional) – wether to use the spatial prior term, by default True

Returns:

the negative log-prior of the candidates

Return type:

np.ndarray of shape (N_candidates,)

neglog_pdf(Theta: ndarray, idx_pix: ndarray, forward_map_evals: dict, nll_utils: dict, pixelwise: bool = False, chromatic_gibbs: bool = False) float | ndarray[source]

evaluates the negative log pdf of the posterior at Theta

Parameters:
  • Theta (np.ndarray) – point at which the posterior negative log pdf is to be evaluated

  • forward_map_evals (dict[str, Union[float, np.ndarray]]) – output of the likelihood.evaluate_all_forward_map() method

  • nll_utils ([str, Union[float, np.ndarray]]) – output of the likelihood.evaluate_all_nll_utils() method

  • pixelwise (bool, optional) – whether to return the prior neg log pdf per pixel, by default False

  • chromatic_gibbs (bool, optional) – by default False

Returns:

returns a float if pixelwise is False, otherwise an array of shape (N,)

Return type:

Union[float, np.ndarray]

neglog_pdf_priors(Theta: ndarray, idx_pix: ndarray, pixelwise: bool = False, chromatic_gibbs: bool = False) float | ndarray[source]

evaluates the negative log-pdf of the priors

Parameters:
  • Theta (np.ndarray) – vector to evaluate

  • pixelwise (bool, optional) – whether to return the prior neg log pdf per pixel, by default False

Returns:

returns a float if pixelwise is False, otherwise an array of shape (N,)

Return type:

Union[float, np.ndarray]

prior_indicator

prior term encoding validity intervals

Type:

SmoothIndicatorPrior

prior_spatial

spatial prior term

Type:

SpatialPrior

Module contents

Essentially contains the definition of

  1. The forward model (an polynomial regression of a grid of simulations of the Meudon PDR code)

  2. the negative logpdf of the likelihood, prior and posterior, their gradient and the diagonal of their hessian matrix