Prediction¶
Generate predictions from simulations with specified parameter vectors, with optional post-processing.
-
class
pypesto.predict.
AmiciPredictor
(amici_objective: pypesto.objective.amici.AmiciObjective, amici_output_fields: Optional[Sequence[str]] = None, post_processor: Optional[Callable] = None, post_processor_sensi: Optional[Callable] = None, post_processor_time: Optional[Callable] = None, max_chunk_size: Optional[int] = None, output_ids: Optional[Sequence[str]] = None, condition_ids: Optional[Sequence[str]] = None)[source]¶ Bases:
object
Do forward simulations (predictions) with parameter vectors, for an AMICI model. The user may supply post-processing methods. If post-processing methods are supplied, and a gradient of the prediction is requested, then the sensitivities of the AMICI model must also be post-processed. There are no checks here to ensure that the sensitivities are correctly post-processed, this is explicitly left to the user. There are also no safeguards if the postprocessor routines fail. This may happen if, e.g., a call to Amici fails, and no timepoints, states or observables are returned. As the AmiciPredictor is agnostic about the dimension of the postprocessor and also the dimension of the postprocessed output, these checks are also left to the user. An example for such a check is provided in the default output (see _default_output()).
-
__call__
(x: numpy.ndarray, sensi_orders: Tuple[int, …] = (0), mode: str = 'mode_fun', output_file: str = '', output_format: str = 'csv') → pypesto.predict.result.PredictionResult[source]¶ Simulate a model for a certain prediction function. This method relies on the AmiciObjective, which is underlying, but allows the user to apply any post-processing of the results, the sensitivities, and the timepoints.
- Parameters
x – The parameters for which to evaluate the prediction function.
sensi_orders – Specifies which sensitivities to compute, e.g. (0,1) -> fval, grad.
mode – Whether to compute function values or residuals.
output_file – Path to an output file.
output_format – Either ‘csv’, ‘h5’. If an output file is specified, this routine will return a csv file, created from a DataFrame, or an h5 file, created from a dict.
- Returns
PredictionResult object containing timepoints, outputs, and output_sensitivities if requested
- Return type
results
-
__init__
(amici_objective: pypesto.objective.amici.AmiciObjective, amici_output_fields: Optional[Sequence[str]] = None, post_processor: Optional[Callable] = None, post_processor_sensi: Optional[Callable] = None, post_processor_time: Optional[Callable] = None, max_chunk_size: Optional[int] = None, output_ids: Optional[Sequence[str]] = None, condition_ids: Optional[Sequence[str]] = None)[source]¶ Constructor.
- Parameters
amici_objective – An objective object, which will be used to get model simulations
amici_output_fields – keys that exist in the return data object from AMICI, which should be available for the post-processors
post_processor – A callable function which applies postprocessing to the simulation results and possibly defines different outputs than those of the amici model. Default are the observables (pypesto.predict.constants.AMICI_Y) of the AMICI model. This method takes a list of dicts (with the returned fields pypesto.predict.constants.AMICI_T, pypesto.predict.constants.AMICI_X, and pypesto.predict.constants.AMICI_Y of the AMICI ReturnData objects) as input. Safeguards for, e.g., failure of AMICI are left to the user.
post_processor_sensi – A callable function which applies postprocessing to the sensitivities of the simulation results. Defaults to the observable sensitivities of the AMICI model. This method takes a list of dicts (with the returned fields pypesto.predict.constants.AMICI_T, pypesto.predict.constants.AMICI_X, pypesto.predict.constants.AMICI_Y, pypesto.predict.constants.AMICI_SX, and pypesto.predict.constants.AMICI_SY of the AMICI ReturnData objects) as input. Safeguards for, e.g., failure of AMICI are left to the user.
post_processor_time – A callable function which applies postprocessing to the timepoints of the simulations. Defaults to the timepoints of the amici model. This method takes a list of dicts (with the returned field pypesto.predict.constants.AMICI_T of the amici ReturnData objects) as input. Safeguards for, e.g., failure of AMICI are left to the user.
max_chunk_size – In some cases, we don’t want to compute all predictions at once when calling the prediction function, as this might not fit into the memory for large datasets and models. Here, the user can specify a maximum chunk size of conditions, which should be simulated at a time. Defaults to None, meaning that all conditions will be simulated.
output_ids – IDs of outputs, as post-processing allows the creation of customizable outputs, which may not coincide with those from the AMICI model (defaults to AMICI observables).
condition_ids – List of identifiers for the conditions of the edata objects of the amici objective, will be passed to the PredictionResult at call.
-
-
class
pypesto.predict.
PredictionConditionResult
(timepoints: numpy.ndarray, output_ids: Sequence[str], output: Optional[numpy.ndarray] = None, output_sensi: Optional[numpy.ndarray] = None, x_names: Optional[Sequence[str]] = None)[source]¶ Bases:
object
This class is a light-weight wrapper for the prediction of one simulation condition of an amici model. It should provide a common api how amici predictions should look like in pyPESTO.
-
__init__
(timepoints: numpy.ndarray, output_ids: Sequence[str], output: Optional[numpy.ndarray] = None, output_sensi: Optional[numpy.ndarray] = None, x_names: Optional[Sequence[str]] = None)[source]¶ Constructor.
- Parameters
timepoints – Output timepoints for this simulation condition
output_ids – IDs of outputs for this simulation condition
outputs – Postprocessed outputs (ndarray)
outputs_sensi – Sensitivities of postprocessed outputs (ndarray)
x_names – IDs of model parameter w.r.t to which sensitivities were computed
-
-
class
pypesto.predict.
PredictionResult
(conditions: Sequence[Union[pypesto.predict.result.PredictionConditionResult, Dict]], condition_ids: Optional[Sequence[str]] = None, comment: Optional[str] = None)[source]¶ Bases:
object
This class is a light-weight wrapper around predictions from pyPESTO made via an amici model. It’s only purpose is to have fixed format/api, how prediction results should be stored, read, and handled: as predictions are a very flexible format anyway, they should at least have a common definition, which allows to work with them in a reasonable way.
-
__init__
(conditions: Sequence[Union[pypesto.predict.result.PredictionConditionResult, Dict]], condition_ids: Optional[Sequence[str]] = None, comment: Optional[str] = None)[source]¶ Constructor.
- Parameters
conditions – A list of PredictionConditionResult objects or dicts
condition_ids – IDs or names of the simulation conditions, which belong to this prediction (e.g., PEtab uses tuples of preequilibration condition and simulation conditions)
comment – An additional note, which can be attached to this prediction
-
-
class
pypesto.predict.
PredictorTask
(predictor: pypesto.predict.Predictor, x: Sequence[float], sensi_orders: Tuple[int, …], mode: str, id: str)[source]¶ Bases:
pypesto.engine.task.Task
Perform a single prediction with
pypesto.engine.Task
.Designed for use with
pypesto.ensemble.Ensemble
.-
predictor
¶ The predictor to use.
-
x
¶ The parameter vector to compute predictions with.
-
sensi_orders
¶ Specifies which sensitivities to compute, e.g. (0,1) -> fval, grad.
-
mode
¶ Whether to compute function values or residuals.
-
id
¶ The input ID.
-
__init__
(predictor: pypesto.predict.Predictor, x: Sequence[float], sensi_orders: Tuple[int, …], mode: str, id: str)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
execute
() → pypesto.predict.PredictionResult[source]¶ Execute the task and return its results.
-