beetroots.modelling.forward_maps package
Submodules
beetroots.modelling.forward_maps.abstract_base module
Abstract forward map
- class beetroots.modelling.forward_maps.abstract_base.ForwardMap(D: int, L: int, N: int, dict_fixed_values_scaled: dict[str, float | None] = {})[source]
Bases:
ABCForward model such that for every pixel \(n \in [1, N]\)
\[f : \theta_n \in \mathbb{R}^D \mapsto f(\theta_n) \in \mathbb{R}^L\]- D
dimensionality of input space
- Type:
int
- D_sampling
- L
dimensionality of output space
- Type:
int
- N
number of independent pixels
- Type:
int
- arr_fixed_values
- abstract compute_all(Theta: ndarray, compute_lin: bool = True, compute_log: bool = True, compute_derivatives: bool = True, compute_derivatives_2nd_order: bool = True) dict[str, ndarray][source]
gathers the evaluation of the forward map in linear and log scale and of the associated derivatives. Permits to limit repeating computations, but requires the storage in memory of the result.
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
compute_lin (bool, optional) – wether or not to compute the forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_log (bool, optional) – wether or not to compute the log-forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_derivatives (bool, optional) – wether or not to evaluate the derivatives of the forward map, by default True
compute_derivatives_2nd_order (bool, optional) – wether or not to evaluate the 2nd order derivatives of the forward map, by default True
- Returns:
forward_map_evals – dictionary with entries such as f_Theta, log_f_Theta, grad_f_Theta, grad_log_f_Theta, hess_diag_f_Theta and hess_diag_log_f_Theta, depending on the input booleans.
- Return type:
dict[str, np.ndarray]
- dict_fixed_values_scaled
- abstract evaluate(Theta: ndarray) ndarray[source]
evaluates the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the forward map images in the observation space \((f(\theta_n))_{n=1}^N\) with \(f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- abstract gradient(Theta: ndarray) ndarray[source]
returns the gradient of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- abstract hess_diag(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- list_indices_fixed
- list_indices_to_sample
beetroots.modelling.forward_maps.abstract_exp module
- class beetroots.modelling.forward_maps.abstract_exp.ExpForwardMap(D: int, L: int, N: int, dict_fixed_values_scaled: dict[str, float | None] = {})[source]
Bases:
ForwardMapForward model such that for every pixel \(n \in [1, N]\)
\[f : \theta_n \in \mathbb{R}^D \mapsto f(\theta_n) \in \mathbb{R}^L\]where \(f(\theta_n)\) can be written with a left composition with the exponential, i.e., \(f(\theta_n) = \exp \circ (\ln f) (\theta_n)\)
- D
dimensionality of input space
- Type:
int
- D_sampling
- L
dimensionality of output space
- Type:
int
- N
number of independent pixels
- Type:
int
- arr_fixed_values
- dict_fixed_values_scaled
- abstract evaluate_log(Theta: ndarray) ndarray[source]
evaluates the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the log-forward map images in the observation space \((\ln f(\theta_n))_{n=1}^N\) with \(\ln f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- abstract gradient_log(Theta: ndarray) ndarray[source]
returns the gradient of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla \ln f(\theta_n))_{n=1}^N\), with \(\nabla \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- abstract hess_diag_log(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 \ln f(\theta_n))_{n=1}^N\), with \(\text{diag} \nabla^2 \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- list_indices_fixed
- list_indices_to_sample
beetroots.modelling.forward_maps.basic_exp module
- class beetroots.modelling.forward_maps.basic_exp.BasicExpForwardMap(D, L, N, dict_fixed_values_scaled: dict[str, float | None] = {})[source]
Bases:
ExpForwardMapForward model such that for every pixel \(n \in [1, N]\)
\[f : \theta_n \in \mathbb{R}^D \mapsto \exp(\theta_n) \in \mathbb{R}^D\]i.e. in this class, \(D = L\)
- D
dimensionality of input space
- Type:
int
- D_sampling
- L
dimensionality of output space
- Type:
int
- N
number of independent pixels
- Type:
int
- arr_fixed_values
- compute_all(Theta: ndarray, compute_lin: bool = True, compute_log: bool = True, compute_derivatives: bool = True, compute_derivatives_2nd_order: bool = True) dict[str, ndarray][source]
gathers the evaluation of the forward map in linear and log scale and of the associated derivatives. Permits to limit repeating computations, but requires the storage in memory of the result.
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
compute_lin (bool, optional) – wether or not to compute the forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_log (bool, optional) – wether or not to compute the log-forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_derivatives (bool, optional) – wether or not to evaluate the derivatives of the forward map, by default True
compute_derivatives_2nd_order (bool, optional) – wether or not to evaluate the 2nd order derivatives of the forward map, by default True
- Returns:
forward_map_evals – dictionary with entries such as f_Theta, log_f_Theta, grad_f_Theta, grad_log_f_Theta, hess_diag_f_Theta and hess_diag_log_f_Theta, depending on the input booleans.
- Return type:
dict[str, np.ndarray]
- dict_fixed_values_scaled
- evaluate(Theta: ndarray) ndarray[source]
evaluates the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the forward map images in the observation space \((f(\theta_n))_{n=1}^N\) with \(f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- evaluate_log(Theta: ndarray) ndarray[source]
evaluates the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the log-forward map images in the observation space \((\ln f(\theta_n))_{n=1}^N\) with \(\ln f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- gradient(Theta: ndarray) ndarray[source]
returns the gradient of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- gradient_log(Theta: ndarray) ndarray[source]
returns the gradient of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla \ln f(\theta_n))_{n=1}^N\), with \(\nabla \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag_log(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 \ln f(\theta_n))_{n=1}^N\), with \(\text{diag} \nabla^2 \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- list_indices_fixed
- list_indices_to_sample
- output_subset
subset of outputs to be predicted. Can be updated with
restrict_to_output_subset- Type:
List[int]
beetroots.modelling.forward_maps.identity module
Implementation of the identity forward map
- class beetroots.modelling.forward_maps.identity.BasicForwardMap(L: int, N: int, dict_fixed_values_scaled: dict[str, float | None] = {})[source]
Bases:
ForwardMapForward model such that for every pixel \(n \in [1, N]\)
\[f : \theta_n \in \mathbb{R}^D \mapsto \theta_n \in \mathbb{R}^D\]i.e. in this class, \(D = L\)
- D
dimensionality of input space
- Type:
int
- D_sampling
- L
dimensionality of output space
- Type:
int
- N
number of independent pixels
- Type:
int
- arr_fixed_values
- compute_all(Theta: ndarray, compute_lin: bool = True, compute_log: bool = False, compute_derivatives: bool = True, compute_derivatives_2nd_order: bool = True) dict[source]
gathers the evaluation of the forward map in linear and log scale and of the associated derivatives. Permits to limit repeating computations, but requires the storage in memory of the result.
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
compute_lin (bool, optional) – always considered as True. Kept for this class for consistency.
compute_log (bool, optional) – always considered as False. Kept for this class for consistency.
compute_derivatives (bool, optional) – wether or not to evaluate the derivatives of the forward map, by default True
compute_derivatives_2nd_order (bool, optional) – wether or not to evaluate the 2nd order derivatives of the forward map, by default True
- Returns:
forward_map_evals – dictionary with the f_Theta entry and possibly grad_f_Theta, and hess_diag_f_Theta, depending on the input booleans.
- Return type:
dict[str, np.ndarray]
- dict_fixed_values_scaled
- evaluate(Theta: ndarray) ndarray[source]
evaluates the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the forward map images in the observation space \((f(\theta_n))_{n=1}^N\) with \(f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- gradient(Theta: ndarray) ndarray[source]
returns the gradient of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- list_indices_fixed
- list_indices_to_sample
- output_subset
subset of outputs to be predicted. Can be updated with
restrict_to_output_subset- Type:
List[int]
beetroots.modelling.forward_maps.neural_network_approx module
- class beetroots.modelling.forward_maps.neural_network_approx.NeuralNetworkApprox(path_model: str, model_name: str, dict_fixed_values_scaled: Dict[str, float | None], device: str | None = None)[source]
Bases:
ExpForwardMapForward model based on a neural network. For every entry \(n \in [1, N]\)
\[f : \theta_n \in \mathbb{R}^D \mapsto f(\theta_n) \in \mathbb{R}^L\]where \(f(\theta_n)\) can be written with a left composition with the exponential, i.e., \(f(\theta_n) = \exp \circ (\ln f) (\theta_n)\). Here the neural network corresponds to \(\ln f(\theta_n)\).
The neural network needs to be defined with the
nnbmapackage, presented in Palud et al. [2023]. Here are the links towards the corresponding GitHub repository, PyPi package and documentation.- D
full dimension of the physical parameter vector, including the scaling parameter \(\kappa\)
- Type:
int
- D_no_kappa
full dimension of the physical parameter vector, except for the scaling parameter \(\kappa\) (which is not an input of the neural network)
- Type:
int
- D_sampling
- L
total number of observables per pixel used for inversion
- Type:
int
- LOGE_10 = 2.3025850929940455
natural log (in base \(e\)) of 10, computed once and saved to limit redundant computations
- Type:
float
- N
number of independent pixels
- Type:
int
- arr_fixed_values
- compute_all(Theta: ndarray, compute_lin: bool = True, compute_log: bool = True, compute_derivatives: bool = True, compute_derivatives_2nd_order: bool = True) dict[source]
gathers the evaluation of the forward map in linear and log scale and of the associated derivatives. Permits to limit repeating computations, but requires the storage in memory of the result.
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
compute_lin (bool, optional) – wether or not to compute the forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_log (bool, optional) – wether or not to compute the log-forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_derivatives (bool, optional) – wether or not to evaluate the derivatives of the forward map, by default True
compute_derivatives_2nd_order (bool, optional) – wether or not to evaluate the 2nd order derivatives of the forward map, by default True
- Returns:
forward_map_evals – dictionary with entries such as f_Theta, log_f_Theta, grad_f_Theta, grad_log_f_Theta, hess_diag_f_Theta and hess_diag_log_f_Theta, depending on the input booleans.
- Return type:
dict[str, np.ndarray]
Note
To evaluate \(f(\theta_n)\) and the associated derivatives, 3 evaluations are enough for six functions. Calling each function would result in a total of 9 evaluations.
- device
device on which the neural network is to be run, either cuda or cpu
- Type:
str
- dict_fixed_values_scaled
- evaluate(Theta: ndarray) ndarray[source]
evaluates the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the forward map images in the observation space \((f(\theta_n))_{n=1}^N\) with \(f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- evaluate_log(Theta: ndarray) ndarray[source]
evaluates the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the log-forward map images in the observation space \((\ln f(\theta_n))_{n=1}^N\) with \(\ln f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- gradient(Theta)[source]
returns the gradient of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- gradient_log(Theta)[source]
returns the gradient of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla \ln f(\theta_n))_{n=1}^N\), with \(\nabla \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag(Theta)[source]
returns the diagonal of the hessian of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag_log(Theta)[source]
returns the diagonal of the hessian of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 \ln f(\theta_n))_{n=1}^N\), with \(\text{diag} \nabla^2 \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- list_indices_fixed
- list_indices_fixed_for_nn
indices of the entries to be fixed for the neural network, i.e., with an offset of 1 compared with list_indices_fixed due to the scaling parameter \(\kappa\)
- Type:
list
- list_indices_to_sample
- list_indices_to_sample_for_nn
indices of the entries to be sampled for the neural network, i.e., with an offset of 1 compared with list_indices_fixed due to the scaling parameter \(\kappa\)
- Type:
list
- network
instance of neural network from the
nnbmapackage (see https://pypi.org/project/nnbma/)- Type:
NeuralNetwork
- restrict_to_output_subset(output_subset: List[str]) None[source]
Restricts the full output set computed by the neural network to a potentially small subset of outputs. Permits to accelerate computations.
- Parameters:
output_subset (List[str]) – list of the names of the outputs to be considered in forward map evaluations and derivatives.
beetroots.modelling.forward_maps.regression_poly module
Contains a multi-line polynomial regressor made to approximate the true forward model given a grid of simulations
- class beetroots.modelling.forward_maps.regression_poly.PolynomialApprox(path_model: str, model_name: str, dict_fixed_values_scaled: dict[str, float | None], angle: float)[source]
Bases:
ExpForwardMapmulti-line polynomial regressor made to approximate the true forward model given a grid of simulations.
Given the fact that the true Meudon PDR code varies over orders of magnitudes and in order to guarantee that the interpolations are strictly positive, the regression is done in the log space. Therefore, for each line, the approximation is of the form
\[f_{\ell} (\theta_n) = \exp \circ \ln f_{\ell} (\theta_n), \quad \ln f_{\ell} \in \mathbb{R}[X]\]- D
full dimension of the physical parameter vector, including the scaling parameter \(\kappa\)
- Type:
int
- D_no_kappa
full dimension of the physical parameter vector, except for the scaling parameter \(\kappa\) (which is not an input of the polynomial)
- Type:
int
- D_sampling
- L
total number of observables per pixel used for inversion
- Type:
int
- LOGE_10 = 2.3025850929940455
natural log (in base \(e\)) of 10, computed once and saved to limit redundant computations
- Type:
float
- N
number of independent pixels
- Type:
int
- angle
observation angle
- Type:
float
- arr_fixed_values
- coeff_arr
coefficients associated to the monomials (loaded from model)
- Type:
np.ndarray of shape (L, n_coefs)
- coeff_arr_subset
coefficients of the polynomial with restricted outputs
- Type:
np.ndarray
- coeff_grad
coefficients associated to the monomials of the first derivative polynomial (computed in
__init__method)- Type:
np.ndarray of shape (D_no_kappa, L, n_coefs)
- coeff_grad_subset
coefficients of the first derivative polynomial with restricted outputs
- Type:
np.ndarray
- coeff_hess_diag
coefficients associated to the monomials of the first derivative polynomial (computed in
__init__method)- Type:
np.ndarray of shape (D_no_kappa, L, n_coefs)
- coeff_hess_diag_subset
coefficients of the diagonal of the second derivative polynomial with restricted outputs
- Type:
np.ndarray
- compute_all(Theta: ndarray, compute_lin: bool = True, compute_log: bool = True, compute_derivatives: bool = True, compute_derivatives_2nd_order: bool = True) dict[source]
gathers the evaluation of the forward map in linear and log scale and of the associated derivatives. Permits to limit repeating computations, but requires the storage in memory of the result.
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
compute_lin (bool, optional) – wether or not to compute the forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_log (bool, optional) – wether or not to compute the log-forward model (and possibly the gradient and diagonal of the Hessian), by default True
compute_derivatives (bool, optional) – wether or not to evaluate the derivatives of the forward map, by default True
compute_derivatives_2nd_order (bool, optional) – wether or not to evaluate the 2nd order derivatives of the forward map, by default True
- Returns:
forward_map_evals – dictionary with entries such as f_Theta, log_f_Theta, grad_f_Theta, grad_log_f_Theta, hess_diag_f_Theta and hess_diag_log_f_Theta, depending on the input booleans.
- Return type:
dict[str, np.ndarray]
Note
To evaluating \(f(\theta_n)\) and the associated derivatives, 3 evaluations are enough for six functions. Calling each function would result in a total of 9 evaluations.
- deg
degree of the polynomial
- Type:
int
- dict_fixed_values_scaled
- evaluate(Theta: ndarray) ndarray[source]
evaluates the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the forward map images in the observation space \((f(\theta_n))_{n=1}^N\) with \(f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- evaluate_log(Theta: ndarray) ndarray[source]
evaluates the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of the log-forward map images in the observation space \((\ln f(\theta_n))_{n=1}^N\) with \(\ln f(\theta_n) \in \mathbb{R}^L\)
- Return type:
np.ndarray of shape (N, L)
- gradient(Theta: ndarray) ndarray[source]
returns the gradient of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- gradient_log(Theta: ndarray) ndarray[source]
returns the gradient of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of gradients \((\nabla \ln f(\theta_n))_{n=1}^N\), with \(\nabla \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 f(\theta_n))_{n=1}^N\), with \(\nabla f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- hess_diag_log(Theta: ndarray) ndarray[source]
returns the diagonal of the hessian of the log-forward map for a set of input vectors \((\theta_n))_{n=1}^N\)
- Parameters:
Theta (np.ndarray of shape (N, D)) – array of points in the input space \(\Theta = (\theta_n)_{n=1}^N\) with \(\theta_n \in \mathbb{R}^D\)
- Returns:
array of diagonal of the hessians \((\text{diag} \nabla^2 \ln f(\theta_n))_{n=1}^N\), with \(\text{diag} \nabla^2 \ln f(\theta_n) \in \mathbb{R}^{D \times L}\)
- Return type:
np.ndarray of shape (N, D, L)
- list_indices_fixed
- list_indices_to_sample
- output_subset
names of the observables used for inversion
- Type:
list
- output_subset_indices
indices the observables
- Type:
list
- outputs_names
names of the observables
- Type:
list
- pow_arr
powers of the monomials (loaded from model)
- Type:
np.ndarray of shape (n_coefs, D_no_kappa)
- pow_grad
powers of the monomials of the first derivative polynomial (computed in
__init__method)- Type:
np.ndarray of shape (D_no_kappa, n_coefs, D_no_kappa)
- pow_hess_diag
powers of the monomials of the diagonal terms of the second derivative polynomial (computed in
__init__method)- Type:
np.ndarray of shape (D_no_kappa, n_coefs, D_no_kappa)
- beetroots.modelling.forward_maps.regression_poly.compute_grad_poly_params(pow_arr: ndarray, coeff_arr: ndarray) Tuple[ndarray, ndarray][source]
computes the power array and the coefficient array of the gradient of the multivariate polynomial defined with the given power and coefficient arrays
- Parameters:
pow_arr (np.ndarray of shape (n_coefs, D_no_kappa)) – array of powers of the initial multivariate polynomial
coeff_arr (np.ndarray of shape (L, n_coefs)) – array of coeffients of the initial multivariate polynomial
- Returns:
pow_grad (np.ndarray of shape (D_no_kappa, n_coefs, D_no_kappa)) – array of powers of the gradient of multivariate polynomial
coef_grad (np.ndarray of shape (D_no_kappa, L, n_coefs)) – array of coeffients of the gradient of multivariate polynomial
- beetroots.modelling.forward_maps.regression_poly.compute_hess_diag_poly_params(pow_arr: ndarray, coeff_arr: ndarray) Tuple[ndarray, ndarray][source]
computes the power array and the coefficient array of the diagonal of the hessian of the multivariate polynomial defined with the given power and coefficient arrays
- Parameters:
pow_arr (np.ndarray of shape (n_coefs, D_no_kappa)) – array of powers of the initial multivariate polynomial
coeff_arr (np.ndarray of shape (L, n_coefs)) – array of coefficients of the initial multivariate polynomial
- Returns:
pow_grad (np.ndarray of shape (D_no_kappa, n_coefs, D_no_kappa)) – array of powers of the diagonal hessian of multivariate polynomial
coef_grad (np.ndarray of shape (D_no_kappa, L, n_coefs)) – array of coefficients of the diagonal hessian of multivariate polynomial
- beetroots.modelling.forward_maps.regression_poly.evaluate_poly(Theta: ndarray, pow_arr: ndarray, coeff_arr: ndarray, deg: int) ndarray[source]