eulerpi.core.result_manager module

class ResultManager(model_name: str, run_name: str, slices=list[numpy.ndarray])[source]

Bases: object

The result manager is responsible for saving the results of the inference and loading them again.

model_name

The name of the model (e.g. “temperature”). It is used to create the folder structure.

Type:

str

run_name

The name of the run which shall be saved. It is used to create subfolders for different runs.

Type:

str

count_emcee_sub_runs(slice: ndarray) int[source]

This data organization function counts how many sub runs are saved for the specified scenario.

Parameters:

slice (np.ndarray) – The slice for which the number of sub runs should be counted.

Returns:

The number of completed sub runs of the emcee particle swarm sampler.

Return type:

num_existing_files(int)

create_application_folder_structure() None[source]

Creates the Application folder including subfolder where all simulation results are stored for this model. No files are deleted during this action.

create_slice_folder_structure(slice: ndarray) None[source]

Creates the subfolders in Aplication for the given slice where all simulation results are stored for this model and slice. No files are deleted during this action.

Parameters:

slice (np.ndarray) – The slice for which the folder structure will be created

delete_application_folder_structure() None[source]

Deletes the Applications subfolder

delete_slice_folder_structure(slice: ndarray) None[source]

Deletes the Applications/[slice] subfolder

Parameters:

slice (np.ndarray) – The slice for which the folder structure will be deleted

get_application_path() str[source]

Returns the path to the simulation results folder, containing also intermediate results.

Returns:

The path to the simulation results folder, containing also intermediate results.

Return type:

str

get_slice_name(slice: ndarray) str[source]

This organization function returns the name of the folder for the current slice.

Parameters:

slice (np.ndarray) – The slice for which the name of the folder will be returned.

Returns:

The name of the folder for the current slice.

Return type:

str

get_slice_path(slice: ndarray) str[source]

Returns the path to the folder where the results for the given slice are stored.

Parameters:

slice (np.ndarray) – The slice for which the path will be returned.

Returns:

The path to the folder where the results for the given slice are stored.

Return type:

str

load_inference_results(slices: list[ndarray] | None = None, num_burn_in_samples: int | None = None, thinning_factor: int | None = None) Tuple[Dict[str, ndarray], Dict[str, ndarray], Dict[str, ndarray]][source]

Load the inference results generated by EPI.

Parameters:
  • slices (list[np.ndarray]) – Slices for which the results will be loaded. Default is None and loads all slices.

  • num_burn_in_samples (int) – Number of samples that will be ignored per chain (i.e. walker). Only for mcmc inference. Default is None and uses the value that was used for the inference stored in inference_information.json.

  • thinning_factor (int) – Thinning factor that will be used to thin the Markov chain. Only for mcmc inference. Default is None and uses the value that was used for the inference stored in each inference_information.json.

Returns:

The parameters, the simulation results and the density evaluations.

Return type:

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

load_slice_inference_results(slice: ndarray, num_burn_in_samples: int | None = None, thinning_factor: int | None = None) Tuple[ndarray, ndarray, ndarray][source]

Load the files generated by the EPI algorithm through sampling

Parameters:
  • slice (np.ndarray) – Slice for which the results will be loaded

  • num_burn_in_samples (int) – Number of samples that will be ignored per chain (i.e. walker). Only for mcmc inference. Default is None and uses the value that was used for the inference stored in inference_information.json.

  • thinning_factor (int) – Thinning factor that will be used to thin the Markov chain. Only for mcmc inference. Default is None and uses the value that was used for the inference stored in inference_information.json.

Returns:

The parameters, the simulation results and the density evaluations.

Return type:

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

save_inference_information(slice: ndarray, model: Model, inference_type: InferenceType, num_processes: int, **kwargs) None[source]

Saves the information about the inference run.

Parameters:
  • slice (np.ndarray) – The slice for which the results will be saved.

  • model (Model) – The model for which the results will be saved.

  • inference_type (InferenceType) – The type of inference that was performed.

  • num_processes (int) – The number of processes that were used for the inference.

  • **kwargs – Additional information about the inference run. num_runs(int): The number of runs that were performed. Only for mcmc inference. num_walkers(int): The number of walkers that were used. Only for mcmc inference. num_steps(int): The number of steps that were performed. Only for mcmc inference. num_burn_in_samples(int): Number of samples that will be ignored per chain (i.e. walker). Only for mcmc inference. thinning_factor(int): The thinning factor that was used to thin the Markov chain. Only for mcmc inference. load_balancing_safety_faktor(int): The safety factor that was used for load balancing. Only for dense grid inference. num_grid_points(np.ndarray): The number of grid points that were used. Only for dense grid inference. dense_grid_type(DenseGridType): The type of dense grid that was used: either equidistant or chebyshev. Only for dense grid inference. num_levels(int): The number of sparse grid levels that were used. Only for sparse grid inference.

Raises:

ValueError – If the inference type is unknown.

save_overall(slice, overall_params, overall_sim_results, overall_density_evals)[source]

Saves the results of all runs of the emcee particle swarm sampler for the given slice.

Parameters:
  • slice (np.ndarray) – The slice for which the results will be saved. # TODO document dimensions of overall_params, overall_sim_results, overall_density_evals

  • overall_params (np.ndarray) – The results of the sampler.

  • overall_sim_results (np.ndarray) – The results of the sampler.

  • overall_density_evals (np.ndarray) – The results of the sampler.

save_run(model: Model, slice: ndarray, run, sampler_results: ndarray, final_walker_positions: ndarray) None[source]

Saves the results of a single run of the emcee particle swarm sampler. sampler_results has the shape (num_walkers * num_steps, sampling_dim + data_dim + 1), we save them as seperate files in the folders ‘Params’ and’SimResults’ and ‘DensityEvals’.

Parameters:
  • model (Model) – The model for which the results will be saved

  • slice (np.ndarray) – The slice for which the results will be saved

  • run (int) – The run for which the results will be saved

  • sampler_results (np.ndarray) – The results of the sampler, expects an np.array with shape (num_walkers * num_steps, sampling_dim + data_dim + 1)

  • final_walker_positions (np.ndarray) – The final positions of the walkers, expects an np.array with shape (num_walkers, sampling_dim)