insidapy.augment package

Submodules

insidapy.augment.mimic module

class insidapy.augment.mimic.fit_and_augment(y: ndarray, t: ndarray, nparams: int, model: callable, parameter_bounds: ndarray, example: str = 'augment_fit_case_study', name_of_time_vector: str = 'time', time_unit: str = 'h', species_units: list = None)

Bases: object

This class takes observed data and a suggested ODE model as input. It then uses an indicated method to estimate the parameters of the given model. Last, it uses the identified model to create new data points. This procedure can be used to augment the small sample data set that might be available from measurements.

Parameters:
  • y (array, required) – Observed data of shape [n,m] where n is the number of time points and m is the number of species.

  • t (array, required) – Time points of shape [n,].

  • nparams (int, required) – Number of parameters to estimate in the ODE model.

  • model (callable, required) – Callable function that represents the ODE model. Should be in the form of f(t,y,params).

  • parameter_bounds (array, required) – Bounds for the parameters of shape [nparams,2].

  • example (str, optional) – Name of the example. Default given by ‘augment_fit_case_study’.

  • name_of_time_vector (str, optional) – Name of the time vector. Default is ‘time’.

  • time_unit (str, optional) – Unit of the time. Defaults to ‘hours’.

  • species_units (list, optional) – Units of the different species as a list. If nothing is given, ‘n.a.’ is used for each species.

Stores:
y (array):

Observed data.

t (array):

Time points.

nparams (int):

Number of parameters to estimate.

model (callable):

Callable function that represents the ODE model.

parameter_bounds (array):

Bounds for the parameters.

addnoise_per_species(y)

Uses some ground truth data and adds some noise to it. Stores the resulting vector as a new attribute.

Parameters:

y – Ground truth data. Shape as [npoints_per_batch, nspecies].

Stores:
y_noisy (array):

Noisy observations.

apply_estimated_parameters(y0=None, tspan=None, params=None)

Uses the estimated parameters to simulate the state profiles (solve the provided ODE model).

Parameters:
  • y0 (array, optional) – Initial conditions of the ODE. Defaults to None. If None, the first data point is assumed to be the initial condition.

  • tspan (array, optional) – Time points for the ODE integration. Defaults to None. If None, the time points of the observed measurements are used.

  • params (array, optional) – Parameters for the ODE. Defaults to None. If None, the identified parameters from the fitting are used.

export_dict_data_to_excel(destination: str = './data', which_dataset: str = 'all')

Exports the datasets stored in the dictionary to an excel file. The filename of the data is ‘{self.example_name}_{which_dataset}.xlsx’ and ‘{self.example_name}_{which_dataset}_noisy.xlsx’.

Parameters:
  • destination – Destination folder in which the excel files should be saved. Default to ‘.data’.

  • which_dataset – Which dataset should be exported (‘all’, ‘training’, or ‘testing’). Defaults to ‘all’.

fit(method: str = 'Nelder-Mead', objective: str = 'RMSE', num_random_search_steps: int = 5)

Fits the model to the observed data. A variety of existing optimizer methods can be used.

Parameters:
  • method (str, optional) – Optimization method for the parameter estimation. Default is currently set to the scipy method ‘Nelder-Mead’.

  • objective (str, optional) – Residual definition. Defaults to ‘RMSE’ (root mean squared error).

  • num_random_search_steps (int, optional) – Number of random search steps to find a good starting point for the optimization. Defaults to 5.

Stores:
y0 (array):

Initial condition for the ODE solver. The first data point is assumed to be the initial condition.

fittingresult (object):

Result of the optimization routine (for the scipy implementations, see scipy.optimize.minimize)

xopt (array):

Estimated parameters.

fopt (float):

Objective function value at the optimum.

fit_predict(method: str = 'Nelder-Mead', objective: str = 'RMSE', num_random_search_steps: int = 5, plotting: bool = False)

Convenience function to fit and predict in one step.

Parameters:
  • method (str, optional) – Optimization method for the parameter estimation. Default is currently set to the scipy method ‘Nelder-Mead’.

  • objective (str, optional) – Residual definition. Defaults to ‘RMSE’ (root mean squared error).

  • num_random_search_steps (int, optional) – Number of random search steps to find a good starting point for the optimization. Defaults to 5.

  • plotting (bool, optional) – If True, the fit is plotted. Defaults to False.

mimic_experiments(LB, UB, nbatches: int = 5, noise_mode: str = 'percentage', noise_percentage: float = 2.5)

Run the experiments with the identified parameters. No inputs required. Stores some attributes:

Parameters:
  • LB (array, required) – Lower bounds of the initial conditions.

  • UB (array, required) – Upper bounds of the initial conditions.

  • nbatches (int, optional) – Number of samples to generate. Defaults to 5.

  • noise_mode (str, optional) – Mode of noise addition. Defaults to ‘percentage’.

  • noise_percentage (float, optional) – Percentage of noise to add. Defaults to 2.5.

Stores:
y (dict):

Dictionary with ground truth data for each batch.

y_noisy (dict):

Dictionary with noisy data for each batch.

plot_experiments(show: bool = True, save: bool = False, figname: str = 'figure', save_figure_directory: str = './figures', save_figure_exensions: list = ['svg', 'png'])

Plot experiments that were simulated.

Parameters:
  • show (bool, optional) – Boolean indicating whether the figure should be shown. Default to True.

  • figname (str, optiona) – Name of the figure. Default to ‘figure’.

  • save (bool, optional) – Boolean indicating whether the figure should be saved. Default to False.

  • save_figure_directory (str, optional) – Directory in which the figure should be saved. Default to ‘./figures’.

  • save_figure_exensions (list, optional) – List of file extensions in which the figure should be saved. Default to [‘svg’,’png’].

plot_fit(show: bool = True, save: bool = False, figname: str = 'figure', save_figure_directory: str = './figures', save_figure_exensions: list = ['svg', 'png'])

Plot the fit of the model to the observed data.

plot_train_test_experiments(show: bool = True, save: bool = False, figname: str = 'figure', save_figure_directory: str = './figures', save_figure_exensions: list = ['svg', 'png'])

Plot experiments that were simulated. The training and testing runs are colored differently.

Parameters:
  • show (bool, optional) – Boolean indicating whether the figure should be shown. Default to True.

  • figname (str, optiona) – Name of the figure. Default to ‘figure’.

  • save (bool, optional) – Boolean indicating whether the figure should be saved. Default to False.

  • save_figure_directory (str, optional) – Directory in which the figure should be saved. Default to ‘./figures’.

  • save_figure_exensions (list, optional) – List of file extensions in which the figure should be saved. Default to [‘svg’,’png’].

predict(show: bool = True, save: bool = False, figname: str = 'figure', save_figure_directory: str = './figures', save_figure_exensions: list = ['svg', 'png'])

Uses the estimated parameters to simulate the state profiles (solve the provided ODE model).

Parameters:

plotting (bool, optional) – If True, the fit is plotted. Defaults to False.

This function is a naive optimization routine that randomly samples the allowed space and returns the best value. This is used to find a good starting point for the optimization later on.

Parameters:
  • f (function, required) – callable function to optimize.

  • n_p (int, required) – number of points to sample.

  • bounds_rs (np.array, required) – bounds of the search space.

  • iter_rs (int, required) – number of iterations.

rmse_(y_est, y_obs)

Returns the root mean squared error (RMSE) of two vectors.

Parameters:
  • y_est (array) – Estimated values (predictions)

  • y_obs (array) – Observed values

Returns:

RMSE of the vectors indicated.

Return type:

float

save_figure(save: bool = False, figure_name: str = 'figure', savedirectory: str = './figures', save_figure_exensions: list = ['svg', 'png'])

Saves a figure.

Parameters:
  • save (bool) – Boolean indicating whether the figure should be saved. Defaults to False

  • figure_name (str) – Name of the figure. Defaults to ‘figure’.

  • savedirectory (str) – Directory in which the figure should be saved. Defaults to ‘./figures’.

  • save_figure_exensions (list) – List of file extensions in which the figure should be saved. Defaults to [‘svg’,’png’].

solve_ode(fun, y0, tspan, params)

Solve the ODE with the given parameters.

Parameters:
  • fun (callable) – Callable function that represents the ODE model.

  • y0 (array) – Initial condition for the ODE solver. The first data point is assumed to be the initial condition.

  • tspan (array) – Time points.

  • params (array) – Parameters.

train_test_split(test_splitratio=None)

Splits the data into training and testing data.

Parameters:

test_splitratio (float, optional) – Ratio [0,1) of the data which is used as test set. Defaults to None (explicitly ask user due to assert).