pymob package#
Subpackages#
- pymob.inference package
- pymob.sim package
- Submodules
- pymob.sim.config module
ArrayParamCasestudyCasestudy.dataCasestudy.data_pathCasestudy.default_settings_pathCasestudy.init_rootCasestudy.logfileCasestudy.loggingCasestudy.model_configCasestudy.model_fieldsCasestudy.modulesCasestudy.nameCasestudy.observationsCasestudy.outputCasestudy.output_pathCasestudy.packageCasestudy.rootCasestudy.scenarioCasestudy.scenario_pathCasestudy.set_root()Casestudy.simulation
ConfigConfig.case_studyConfig.create_directory()Config.data_structureConfig.error_modelConfig.import_casestudy_modules()Config.import_simulation_from_case_study()Config.inferenceConfig.inference_numpyroConfig.inference_pyabcConfig.inference_pyabc_redisConfig.inference_pymooConfig.input_file_pathsConfig.model_configConfig.model_fieldsConfig.model_parametersConfig.model_post_init()Config.multiprocessingConfig.print()Config.save()Config.simulation
DataVariableDatastructureErrormodelFloatParamInferenceModelparametersMultiprocessingNumpyroNumpyro.chainsNumpyro.drawsNumpyro.gaussian_base_distributionNumpyro.init_strategyNumpyro.kernelNumpyro.model_configNumpyro.model_fieldsNumpyro.sa_adapt_state_sizeNumpyro.svi_iterationsNumpyro.svi_learning_rateNumpyro.thinningNumpyro.user_defined_preprocessingNumpyro.user_defined_probability_modelNumpyro.warmup
ParameterDictPyabcPymooRedisSimulationdatavar_to_string()dict_to_string()list_to_string()param_to_string()string_to_datavar()string_to_dict()string_to_list()string_to_param()
- pymob.sim.base module
- pymob.sim.evaluator module
- pymob.sim.solvetools module
- Module contents
- pymob.utils package
- Submodules
- pymob.utils.bayesian module
- pymob.utils.config module
- pymob.utils.errors module
- pymob.utils.help module
- pymob.utils.math_helpers module
- pymob.utils.misc module
- pymob.utils.plot_helpers module
- pymob.utils.store_file module
case_study_output()create_fname_date_ver()deserialize()go_to_case_studies()import_package()is_number()list_converter()opt()parse_config_section()prepare_casestudy()prepare_casestudy_sbi()prepare_sbi()prepare_scenario()read_config()read_settings()reroute_output_to_base()scenario_file()sequential_filename_iterator()serialize()store_sbi_simulations()unixify_path()unnest()
- Module contents
Submodules#
pymob.infer module#
pymob.prior_predictive_checks module#
pymob.simulate module#
pymob.simulation module#
- class pymob.simulation.SimulationBase(config: str | ConfigParser | Config | None = None)#
Bases:
object- property all_model_parameters: Dict[str, FloatParam | ArrayParam]#
- array2D_to_dataset(dataarray: DataArray) Dataset#
- benchmark(n=100, **kwargs)#
- property case_study#
- property case_study_path#
- check_dimensions(dataset)#
Check if dataset dimensions match the specified dimensions. TODO: Name datasets for referencing them in errormessages
- check_scaled_results_feasibility(scaled_results)#
Parameter inference or optimization over many variables can only succeed in reasonable time if the results that should be compared are on approximately equal scales. The Simulation class, automatically estimates the scales of result variables, when observations are provided.
Problems can occurr when observations are on very narrow ranges, but the simulation results can take much larger or lower values for that variable. As a result the inference procedure will almost exlusively focus on the optimization of this variable, because it provides the maximal return.
The function warns the user, if simulation results largely deviate from the scaled minima or maxima of the observations. In this case manual minima and maxima should be given
- compute()#
A wrapper around run, which catches errors, logs, does post processing
- property coordinates#
- create_coordinates(coordinate_data)#
- create_data_scaler()#
Creates a scaler for the data variables of the dataset over all remaining dimensions. In addition produces a scaled copy of the observations
- static create_dataset_from_numpy(Y, Y_names, coordinates)#
- create_interpolated_coordinates(dim)#
Combines coordinates from observations and from interpolation
- create_random_integers(n: int)#
- property data_path#
- property data_structure#
- property data_variable_bounds#
- property data_variables#
- dataset_to_2Darray(dataset: Dataset) DataArray#
- property dimensions#
- dispatch(theta, **evaluator_kwargs)#
Dispatch an evaluator, which will compute the model at parameters (theta). Evaluators are advantageous, because they are easier serialized than the whole simulation object. Comparison can then happen back in the simulation.
Theoretically, this could also be used to constrain coordinates etc, before evaluating.
- draw_seed()#
- dump(results)#
- property error_model#
- evaluate(theta)#
Wrapper around run to modify paramters of the model.
- property evaluator_dim_order#
- property fixed_model_parameters: Dict[str, FloatParam | ArrayParam]#
- property free_model_parameters: List[FloatParam | ArrayParam]#
- infer_ode_states() int#
- initialize(input)#
initializes the simulation. Performs any extra work, not done in parameterize or set_coordinates.
- property input_file_paths#
- property input_files#
- interactive()#
- load_functions()#
- load_modules()#
- model: Callable#
- property model_parameter_dict#
- property model_parameter_names#
- property model_parameter_values#
- property model_parameters: Dict[Literal['parameters', 'y0', 'x_in'], Any]#
- property n_cores#
- property n_free_parameters#
- property n_objectives#
- property n_ode_states#
- property objective#
- objective_function(results, **kwargs)#
- property objective_names#
- property observations#
- static option_as_list(opt)#
- property output_path#
- static parameterize(free_parameters: Dict[str, float | str | int], model_parameters: Dict) dict#
Optional. Set parameters and initial values of the model. Must return a dictionary with the keys ‘y0’ and ‘parameters’
Can be used to define parameters directly in the script or from a parameter file.
- Parameters:
input (List[str] file paths of parameter/input files) –
theta (List[Param] a list of Parameters. By default the parameters) – specified in the settings.cfg are used in this list.
- Returns:
tulpe
- Return type:
tuple of parameters, can have any length.
- parse_input(input: Literal['y0', 'x_in'], reference_data, drop_dims=['time'])#
Parses a config string e.g. y=Array([0]) or a=b to a numpy array and looks up symbols in the elements of data, where data items are key:value pairs of a dictionary, xarray items or anything of this form
The values are broadcasted along the remaining dimensions in the obser- vations that have not been dropped. Input refers to the argument in the config file.
This method is useful to prepare y0s from observations or to broadcast starting values along batch dimensions.
- plot(results)#
- print_scaling_info()#
- prior()#
- refill_consumed_seeds()#
- reorder_dims(Y)#
- reset_all_coordinates()#
- reset_coordinate(dim: str)#
- reset_data_variable(data_variable: str)#
- reshape_observations(observations, reduce_dim)#
This method reduces the dimensionality of the observations. Compiling xarray datasets from multiple experiments with different IDs and different endpoints, lead to blown up datasets where all combinations (even though they were not tested) are filled with NaNs. Reducing such artificial dimensions by flattening the arrays is the aim of this method.
TODO: There should be tests, whether the method is applicable (this may be already caught with the assertion)
TODO: The method should be generally applicable
- property results#
- property results_scaled#
- results_to_df(results)#
- property root_path#
- run()#
Implementation of the forward simulation of the model. Needs to return X and Y
- Returns:
X (np.ndarray | xr.DataArray)
Y (np.ndarray | xr.DataArray)
- scale_(dataset: Dataset)#
- scale_results(Y)#
- property scenario#
- property scenario_path#
- set_coordinates(input)#
- set_inferer(backend)#
- setup()#
Simulation setup routine, when the following methods have been defined:
coords = self.set_coordinates(input=self.input_file_paths) self.coordinates = self.create_coordinates(coordinate_data=coords) self.var_dim_mapper = self.create_dim_index() init-methods ————
self.initialize –> may be replaced by self.set_observations
- solver: Callable#
- property solver_post_processing#
- total_average(results)#
objective function returning the total MSE of the entire dataset
- validate()#
- property var_dim_mapper: Dict[str, List[str]]#
- pymob.simulation.flatten_parameter_dict(model_parameter_dict, exclude_params=[])#
Takes a dictionary of key value pairs where the values may be floats or arrays. It flattens the arrays and adds indexes to the keys. In addition a function is returned that back-transforms the flattened parameters.
- pymob.simulation.get_return_arguments(func)#
- pymob.simulation.is_iterable(x)#
- pymob.simulation.update_parameters_dict(config, x, parnames)#