insidapy.simulate package

Submodules

insidapy.simulate.multivariate module

class insidapy.simulate.multivariate.multivariate_examples(example: str = 'rosenbrock', npoints: int = 20, noise_mode: str = 'percentage', noise_percentage: float = 5, coefs=None)

Bases: object

Class to initialize example data consisting of a ground truth (noiseless) and noisy observations.

Parameters:
  • example (str, optional) – String of the example to be loaded. Default to ‘rosenbrock’.

  • npoints (int, optional) – Number of grid points per dimension. Defalt to 20.

  • noise_mode (str, optional) – Type of noise that should be added. Default to ‘percentage’.

  • noise_percentage (float, optional) – In case ‘percentage’ is chosen as noise_mode, this indicates the percentage of noise that is added to the ground truth. Default to 5%.

  • coefs (list, optional) – Coefficients of the example function. Default to ‘None’ (defined in examples below individually).

addnoise()

Add noise to the ground truth data. No inputs required. Stores some attributes:

Stores:
Z_noisy (array):

Noisy observations of y(X,Y) as a grid of shape [n,n].

contour_plot_2_variables(nlevels=15, show: bool = True, save=False, save_figure_directory='./figures', save_figure_exensions: list = ['svg', 'png'])

Contour plot of the example.

Parameters:
  • nlevels (int, optional) – Number of level curves (integer) or a list of values at which the levels curves should be shown. Default to 15 levels.

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

  • 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’].

export_to_excel(destination: str = './data')

Exports the datasets stored in the dictionary to an excel file. The filename is ‘{example}_data.xlsx’ and ‘{example}_data_noisy.xlsx’

Parameters:

destination (str, optional) – Destination folder in which the excel files should be saved. Default to ‘.data’.

rosenbrock(coefs=None)

Rosenbrock function. No inputs required. Stores several attributes:

Stores:
x (array):

Independent variables as a vector of shape [n,].

z (function):

Dependent variable y(x) as a lambda function.

X, Y (array):

Independent variables as a grid of shape [n,n].

Z (array):

Dependent variable y(X,Y) as a grid of shape [n,n].

Z_noiy (array):

Noisy observations of y(X,Y) as a grid of shape [n,n].

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’].

insidapy.simulate.ode module

class insidapy.simulate.ode.batch(example: str = 'batch1', nbatches: int = 3, npoints_per_batch: int = 20, noise_mode: str = 'percentage', noise_percentage: float = 5, random_seed: int = 0, bounds_initial_conditions=None, time_span=None, initial_condition_generation_method: str = 'LHS', name_of_time_vector: str = 'time')

Bases: object

The batch class is used to simulate reactor in batch operation mode. The examples that are implemented are listed in utils.ode_default_library_description

Parameters:
  • example (str, optional) – String of the example to be loaded. Default to ‘batch1’ (batch fermentation with 3 species).

  • nbatches (int, optional)

  • npoints_per_batch (int, optional) – Number of x-data points (abscissa). Defalt to 20.

  • noise_mode (str, optional) – Type of noise that should be added. Default to ‘percentage’.

  • noise_percentage (float, optional) – In case ‘percentage’ is chosen as noise_mode, this indicates the percentage of noise that is added to the ground truth. Default to 5%.

  • random_seed (int, optional) – Fix the seed. Default to 0.

  • bounds_initial_conditions (_type_, optional) – The examples have different bounds for the initial conditions. The defaults are given in the function load_initial_conditions.If the user wants to overwrite these, this can be done here by providing a list of lower and upper bounds. (i.e., [[lb1, lb2, …], [ub1, ub2, …]]).

  • time_span (_type_, optional) – The examples have different time spans. The defaults are given in the function load_initial_conditions. If the user wants to overwrite these, this can be done here by providing a list of starting and end time points (i.e., [t0, tf]).

  • initial_condition_generation_method (str, optional) – Method to generate initial conditions. Default to ‘LHS’.

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

Stores:
x (array):

Ground truth abscissa data.

y (function):

Ground truth function data y(x).

y_noisy (array):

Noisy observations of y(x).

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.

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_type}_{self.example}_{which_dataset}_batchdata.xlsx’ and ‘{self.example_type}_{self.example}_{which_dataset}_batchdata_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’.

load_initial_conditions()

Load initial conditions for the ODEs.

Stores:
y0 (array):

Initial conditions.

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_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’].

print_info()

Prints the information about the example that was loaded.

run_experiments()

Run the experiments. No inputs required. Stores some attributes:

Stores:
y (dict):

Dictionary with ground truth data for each batch.

runtime_odes (int):

Cumulative time to solve the ODEs of all batches.

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’].

show_implemented_examples(print_to_console: bool = True)

Show all implemented examples.

Parameters:

print_to_console (bool, optional) – If the implemented examples should be printed to the console or not. Defaults to true.

Stores:
implemented_examples (dict):

List of all implemented examples.

solve_ODE_model(y0, tspan)

Solve the ODE model for the given sample and time span. Returns the derivatives (dydt) as an array of shape [n,] and the runtime of the ODE solver.

Parameters:
  • y0 – Initial conditions.

  • tspan – Time span.

train_test_split(test_splitratio=None, list_testbatches=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).

  • list_testbatches (list, optional) – Batch number list of the batches which are used as test set. If not indicated, the test batch numbers are chosen randomly.

class insidapy.simulate.ode.custom_ode(filename_custom_ode: str, relative_path_custom_ode: str, species: list, custom_ode_function_name: str = None, bounds_initial_conditions=None, time_span=None, ode_arguments: dict = None, name_of_time_unit: str = 'h', name_of_species_units: str = None, nbatches: int = 1, npoints_per_batch: int = 50, noise_mode: str = 'percentage', noise_percentage: float = 5, random_seed: int = 0, initial_condition_generation_method: str = 'LHS', name_of_time_vector: str = 'time')

Bases: batch

The custom_ode class is used to simulate the time evolution of a system defined in a separate ODE file. The intention is to model a batch system. The user should create a file with the ODEs and provide the path to this file. The file should contain a function which takes the state vector y and time t as inputs and returns the derivatives dydt.

Parameters:
  • filename_custom_ode (str, required) – The file name to the file containing the system of ODEs.

  • relative_path_custom_ode (str, required) – The relative path to the file containing the system of ODEs.

  • custom_ode_function_name (str, required) – The name of the function in the file containing the system of ODEs. IF no name is given, the package tries to identify functions with name “ode” in them.

  • num_species (int, required) – Number of species in the system.

  • bounds_initial_conditions (_type_, optional) – The examples have different bounds for the initial conditions. The defaults are given in the function load_initial_conditions.If the user wants to overwrite these, this can be done here by providing a list of lower and upper bounds. (i.e., [[lb1, lb2, …], [ub1, ub2, …]]).

  • time_span (_type_, optional) – The examples have different time spans. The defaults are given in the function load_initial_conditions. If the user wants to overwrite these, this can be done here by providing a list of starting and end time points (i.e., [t0, tf]).

  • ode_arguments (dict, optional) – Dictionary containing the arguments that are passed to the ODE function with the form >>def ODE(y,t, args)<<. If none are indicated, it is assumed the ODE file has the form >>def ODE(y,t)<<. Defaults to None.

  • name_of_time_unit (str, optional) – Name of the time unit. Default to ‘h’ (hours).

  • name_of_species_units (str, optional) – Name of the species units. Default to ‘g/L’ for every species in the system.

  • nbatches (int, optional) – Number of different initial conditions. Defaults to 1.

  • npoints_per_batch (int, optional) – Number of x-data points (abscissa). Defalt to 50.

  • noise_mode (str, optional) – Type of noise that should be added. Default to ‘percentage’.

  • noise_percentage (float, optional) – In case ‘percentage’ is chosen as noise_mode, this indicates the percentage of noise that is added to the ground truth. Default to 5%.

  • random_seed (int, optional) – Fix the seed. Default to 0.

  • initial_condition_generation_method (str, optional) – Method to generate initial conditions. Default to ‘LHS’.

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

Stores:
x (array):

Ground truth abscissa data.

y (function):

Ground truth function data y(x).

y_noisy (array):

Noisy observations of y(x).

class insidapy.simulate.ode.fedbatch(example: str = 'fedbatch1', nbatches: int = 3, npoints_per_batch: int = 20, noise_mode: str = 'percentage', noise_percentage: float = 5, random_seed: int = 0, bounds_initial_conditions=None, time_span=None, initial_condition_generation_method: str = 'LHS', name_of_time_vector: str = 'time')

Bases: batch

The fedbatch class is used to simulate reactor in fedbatch operation mode. The class uses the batch class as basis. The examples that are implemented are listed in utils.ode_default_library_description.

Parameters:
  • example (str, optional) – String of the example to be loaded. Default to ‘fedbatch1’ (fed batch fermentation with 3 species).

  • nbatches (int, optional)

  • npoints_per_batch (int, optional) – Number of x-data points (abscissa). Defalt to 20.

  • noise_mode (str, optional) – Type of noise that should be added. Default to ‘percentage’.

  • noise_percentage (float, optional) – In case ‘percentage’ is chosen as noise_mode, this indicates the percentage of noise that is added to the ground truth. Default to 5%.

  • random_seed (int, optional) – Fix the seed. Default to 0.

  • bounds_initial_conditions (_type_, optional) – The examples have different bounds for the initial conditions. The defaults are given in the function load_initial_conditions.If the user wants to overwrite these, this can be done here by providing a list of lower and upper bounds. (i.e., [[lb1, lb2, …], [ub1, ub2, …]]).

  • time_span (_type_, optional) – The examples have different time spans. The defaults are given in the function load_initial_conditions. If the user wants to overwrite these, this can be done here by providing a list of starting and end time points (i.e., [t0, tf]).

  • initial_condition_generation_method (str, optional) – Method to generate initial conditions. Default to ‘LHS’.

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

Stores:
x (array):

Ground truth abscissa data.

y (function):

Ground truth function data y(x).

y_noisy (array):

Noisy observations of y(x).

insidapy.simulate.univariate module

class insidapy.simulate.univariate.univariate_examples(example: str = 'logistic', example_args: dict = None, nruns: int = 1, npoints: int = 20, tspan: list = [0, 10], noise_mode: str = 'percentage', noise_percentage: float = 5, seed=None)

Bases: object

Class to initialize example data consisting of a ground truth (noiseless) and noisy observations.

Parameters:
  • example – String of the example to be loaded. Default to ‘logistic’.

  • nruns – Number of runs to generate different functions.

  • npoints – Number of x-data points (abscissa). Defalt to 20.

  • tspan – List of staring and end points of abscissa data. Default to [0,10].

  • noise_mode – Type of noise that should be added. Default to ‘percentage’.

  • noise_percentage – In case ‘percentage’ is chosen as noise_mode, this indicates the percentage of noise that is added to the ground truth. Default to 5%.

  • seed – The numpy random seed is not fixed by default, but it can be if the user gives an integer value.

Stores:
x (array):

Ground truth abscissa data.

y (dict):

Ground truth function data y(x).

y_noisy (dict):

Noisy observations of y(x).

addnoise()

Add noise to the ground truth data.

Stores:
y_noisy (dict):

Noisy data of the ground truth data data y(x).

export_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 ‘univariate_{self.example}_{which_dataset}.xlsx’ and ‘’univariate_{self.example}_{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’.

logistic()

Logistic function as ground truth data.

Stores:
y (dict):

Ground truth function data y(x).

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

Plot the example data.

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’].

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’].

sin()

Sinusoidal ground truth data.

Stores:
y (dict):

Ground truth function data y(x).

step()

Step function as ground truth data with the step being located at the given position ‘step_pos’. Before the step, the function has the value of ‘x_min’ and after the step the value of ‘x_max’.

Stores:
y (dict):

Ground truth function data y(x).

train_test_split(test_splitratio=None, number_list_test=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).

  • number_list_test (list, optional) – List of numbers of the runs which are used as test set. If not indicated, the test runs are chosen randomly.