eulerpi.core.dense_grid module

Module implementing the inference with a dense grid.

The inference with a dense grid approximates the (joint/marginal) parameter distribution(s) on a dense grid.

Note

The functions in this module are mainly intended for internal use and are accessed by inference function. Read the documentation of inference_dense_grid to learn more about the available options for the inference with a dense grid.

evaluate_on_grid_chunk(args: Tuple[ndarray, Model, ndarray, DataTransformation, ndarray, ndarray]) ndarray[source]

Define a function which evaluates the density for a given grid chunk. The input args contains the grid chunk, the model, the data, the data_stdevs and the slice.

Parameters:
  • grid_chunk (np.ndarray) – The grid chunk contains the grid points (parameter vectors) for which the density should be evaluated.

  • model (Model) – The model used for the inference.

  • data (np.ndarray) – The data points used for the inference.

  • data_transformation (DataTransformation) – The data transformation used to normalize the data.

  • data_stdevs (np.ndarray) – The standard deviations of the data points. (Currently the kernel width, #TODO!)

  • slice (np.ndarray) – The slice defines for which dimensions of the grid points / paramater vectors the marginal density should be evaluated.

Returns:

The evaluation results for the given grid chunk. It is a vector, containing the parameters in the first columns, the simulation results in the second columns and the density evaluations in the last columns.

Return type:

np.ndarray

generate_chebyshev_grid(num_grid_points: ndarray, limits: ndarray, flatten=False) ndarray | list[ndarray][source]

Generate a grid with the given number of grid points for each dimension.

Parameters:
  • num_grid_points (np.ndarray) – The number of grid points for each dimension.

  • limits (np.ndarray) – The limits for each dimension.

  • flatten (bool) – If True, the grid is returned as a flatten array. If False, the grid is returned as a list of arrays, one for each dimension. (Default value = False)

Returns:

The grid containing the grid points.

Return type:

np.ndarray

generate_regular_grid(num_grid_points: ndarray, limits: ndarray, flatten=False) ndarray | list[ndarray][source]

Generate a grid with the given number of grid points for each dimension.

Parameters:
  • num_grid_points (np.ndarray) – The number of grid points for each dimension.

  • limits (np.ndarray) – The limits for each dimension.

  • flatten (bool) – If True, the grid is returned as a flatten array. If False, the grid is returned as a list of arrays, one for each dimension. (Default value = False)

Returns:

The grid containing the grid points.

Return type:

np.ndarray

inference_dense_grid(model: Model, data: ndarray, data_transformation: DataTransformation, result_manager: ResultManager, slices: list[ndarray], num_processes: int, num_grid_points: int | list[ndarray] = 10, dense_grid_type: DenseGridType = DenseGridType.EQUIDISTANT, load_balancing_safety_faktor: int = 4) Tuple[Dict[str, ndarray], Dict[str, ndarray], Dict[str, ndarray], ResultManager][source]

This function runs a dense grid inference for the given model and data.

Parameters:
  • model (Model) – The model describing the mapping from parameters to data.

  • data (np.ndarray) – The data to be used for the inference.

  • data_transformation (DataTransformation) – The data transformation used to normalize the data.

  • result_manager (ResultManager) – The result manager to be used for the inference.

  • slices (np.ndarray) – A list of slices to be used for the inference.

  • num_processes (int) – The number of processes to be used for the inference.

  • num_grid_points (Union[int, list[np.ndarray]], optional) – The number of grid points to be used for each parameter. If an int is given, it is assumed to be the same for all parameters. Defaults to 10.

  • dense_grid_type (DenseGridType, optional) – The type of grid that should be used. Defaults to DenseGridType.EQUIDISTANT.

  • load_balancing_safety_faktor (int, optional) – Split the grid into num_processes * load_balancing_safety_faktor chunks. Defaults to 4.

Returns:

The parameter samples, the corresponding simulation results, the corresponding density evaluations for each slice and the result manager used for the inference.

Return type:

Tuple[Dict[str, np.ndarray], Dict[str, np.ndarray], Dict[str, np.ndarray], ResultManager]

Raises:

TypeError – If the num_grid_points argument has the wrong type.

run_dense_grid_evaluation(model: Model, data: ndarray, data_transformation: DataTransformation, slice: ndarray, result_manager: ResultManager, num_grid_points: ndarray, dense_grid_type: DenseGridType, num_processes: int, load_balancing_safety_faktor: int) Tuple[ndarray, ndarray, ndarray][source]

This function runs a dense grid evaluation for the given model and data.

Parameters:
  • model (Model) – The model for which the evaluation should be performed.

  • data (np.ndarray) – The data for which the evaluation should be performed.

  • data_transformation (DataTransformation) – The data transformation used to normalize the data.

  • slice (np.ndarray) – The slice for which the evaluation should be performed.

  • result_manager (ResultManager) – The result manager that should be used to save the results.

  • num_grid_points (np.ndarray) – The number of grid points for each dimension.

  • dense_grid_type (DenseGridType) – The type of grid that should be used. (Default value = DenseGridType.EQUIDISTANT)

  • num_processes (int) – The number of processes that should be used for the evaluation. (Default value = NUM_PROCESSES)

  • load_balancing_safety_faktor (int) – Split the grid into num_processes * load_balancing_safety_faktor chunks. This will ensure that each process can be loaded with a similar amount of work if the run time difference between the evaluations does not exceed the load_balancing_safety_faktor. (Default value = 4)

Returns:

The parameter samples, the corresponding simulation results, the corresponding density evaluations for the given slice.

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

Raises:
  • ValueError – If the dimension of the numbers of grid points does not match the number of parameters in the slice.

  • ValueError – If the grid type is unknown.