eulerpi.core.transformations module
This module implements the random variable transformation of the EPI algorithm.
- calc_gram_determinant(jac: Array) float64 [source]
Evaluate the pseudo-determinant of the jacobian
\[\sqrt{\det \left({\frac{ds}{dq}(q)}^\intercal {\frac{ds}{dq}(q)}\right)}\]Warning
The pseudo-determinant of the model jacobian serves as a correction term in the
evaluate_density
function. Therefore this function returns 0 if the result is not finite.- Parameters:
jac (jnp.ndarray) – The jacobian for which the pseudo determinant shall be calculated
- Returns:
The pseudo-determinant of the jacobian. Returns 0 if the result is not finite.
- Return type:
jnp.double
Examples:
import jax.numpy as jnp from eulerpi.core.transformations import calc_gram_determinant jac = jnp.array([[1,2], [3,4], [5,6], [7,8]]) pseudo_det = calc_gram_determinant(jac)
- eval_log_transformed_density(param: ndarray, model: Model, data: ndarray, data_transformation: DataTransformation, data_stdevs: ndarray, slice: ndarray) Tuple[float64, ndarray] [source]
Calculate the logarithmical parameter density as backtransformed data density using the simulation model
\[\begin{split}\log{\Phi_\mathcal{Q}(q)} := \begin{cases} \log{\Phi_\mathcal{Q}(q)} \quad \text{if } \Phi_\mathcal{Q}(q) > 0 \\ -\infty \quad \text{else} \end{cases}\end{split}\]- Parameters:
param (np.ndarray) – parameter for which the transformed density shall be evaluated
model (Model) – model to be evaluated
data (np.ndarray) – data for the model. 2D array with shape (#num_data_points, #data_dim)
data_transformation (DataTransformation) – The data transformation used to normalize the data.
data_stdevs (np.ndarray) – array of suitable kernel width for each data dimension
slice (np.ndarray) – slice of the parameter vector that is to be evaluated
- Returns:
: natural log of the parameter density at the point param : sampler_results (array concatenation of parameters, simulation results and evaluated density, stored as “blob” by the emcee sampler)
- Return type:
Tuple[np.double, np.ndarray]
- evaluate_density(param: ndarray, model: Model, data: ndarray, data_transformation: DataTransformation, data_stdevs: ndarray, slice: ndarray) Tuple[float64, ndarray] [source]
Calculate the parameter density as backtransformed data density using the simulation model
\[\Phi_\mathcal{Q}(q) = \Phi_\mathcal{Y}(s(q)) \cdot \sqrt{\det \left({\frac{ds}{dq}(q)}^\intercal {\frac{ds}{dq}(q)}\right)}\]- Parameters:
param (np.ndarray) – parameter for which the transformed density shall be evaluated
model (Model) – model to be evaluated
data (np.ndarray) – data for the model. 2D array with shape (#num_data_points, #data_dim)
data_transformation (DataTransformation) – The data transformation used to normalize the data.
data_stdevs (np.ndarray) – array of suitable kernel width for each data dimension
slice (np.ndarray) – slice of the parameter vector that is to be evaluated
- Returns:
: parameter density at the point param : vector containing the parameter, the simulation result and the density
- Return type:
Tuple[np.double, np.ndarray]
Examples:
import numpy as np from eulerpi.examples.heat import Heat from eulerpi.core.kde import calc_kernel_width from eulerpi.core.data_transformation import DataIdentity from eulerpi.core.transformations import evaluate_density # use the heat model model = Heat() # generate 1000 artificial, 5D data points for the Heat example model data_mean = np.array([0.5, 0.1, 0.5, 0.9, 0.5]) data = np.random.randn(1000, 5)/25.0 + data_mean # evaluating the parameter probabiltiy density at the central parameter of the Heat model eval_param = model.central_param # calculating the kernel widths for the data based on Silverman's rule of thumb data_stdevs = calc_kernel_width(data) # evaluate the three-variate joint density slice = np.array([0,1,2]) (central_param_density, all_res) = evaluate_density(param = eval_param, model = model, data = data, data_transformation = DataIdentity(), # no data transformatio, data_stdevs = data_stdevs, slice = slice) # all_res is the concatenation of the evaluated parameter, the simulation result arising from that parameter and the inferred paramter density. Decompose as follows: eval_param = all_res[0:model.param_dim] sim_result = all_res[model.param_dim:model.param_dim+model.data_dim] central_param_density = all_res[-1]