memilio.surrogatemodel.ode_secir_groups.model

Functions

get_test_statistic(test_inputs, test_labels, ...)

Calculates the mean absolute percentage error based on the test dataset.

initialize_model(parameters)

Initialize model from given list of parameters

network_fit(model, modeltype, ...[, ...])

Training and evaluation of a given model with mean squared error loss and Adam optimizer using the mean absolute error as a metric.

plot_compartment_prediction_model(inputs, ...)

Plot prediction of the model and label for one compartment.

plot_losses(history)

Plots the losses of the model training.

prepare_data_classic(data)

Transforming data to be processable by "classic" network, simply flattening and concatenating for each data instance.

prepare_data_timeseries(data)

Transforming data to be processable by "timeseries" network, simply repeating static values, flattening and concatenating for each data instance.

prod_time_series(obj, n, length_input)

Repeating static informations to fit into a time series framework

memilio.surrogatemodel.ode_secir_groups.model.get_test_statistic(
test_inputs,
test_labels,
model,
)

Calculates the mean absolute percentage error based on the test dataset.

Parameters:
  • test_inputs – inputs from test data.

  • test_labels – labels (output) from test data.

  • model – trained model.

Returns:

dataframe containing the MAPE for the different compartments

memilio.surrogatemodel.ode_secir_groups.model.initialize_model(parameters)

Initialize model from given list of parameters

Parameters:

parameters

tuple of parameters describing the model architecture, it should be of the form (number_of_output_days, number_age_groups, number_compartments,

hidden_layers, neurons_in_hidden_layer, activation_function, modelname)

Returns:

tensor flow keras model with the given architecture, see network_architectures.py

memilio.surrogatemodel.ode_secir_groups.model.network_fit(
model,
modeltype,
training_parameter,
path,
filename='data_secir_groups_30days_10k_active.pickle',
plot_stats=True,
)

Training and evaluation of a given model with mean squared error loss and Adam optimizer using the mean absolute error as a metric.

Parameters:
  • model – Keras sequential model.

  • modeltype – type of model. Can be ‘classic’ or ‘timeseries’. Data preparation is made based on the modeltype.

  • training_parameter – tuple of parameters used for the training process, it should be of the form (early_stop, max_epochs, loss, optimizer, metrics), where loss is a loss-function implemented in keras, optimizer is the name of the used optimizer, metrics is a list of used training metrics, e.g. [tf.keras.metrics.MeanAbsoluteError(), tf.keras.metrics.MeanAbsolutePercentageError()]

  • path – path of the dataset.

  • filename – name of the file containing the data

  • plot_stats – (Default value = True)

Returns:

training history as returned by the keras fit() method.

memilio.surrogatemodel.ode_secir_groups.model.plot_compartment_prediction_model(
inputs,
labels,
modeltype,
model=None,
plot_compartment='InfectedSymptoms',
max_subplots=8,
)

Plot prediction of the model and label for one compartment. The average of all age groups is plotted.

If model is none, we just plot the inputs and labels for the selected compartment without any predictions.

Parameters:
  • inputs – test inputs for model prediction.

  • labels – test labels.

  • modeltype – type of model. Can be ‘classic’ or ‘timeseries’

  • model – trained model. (Default value = None)

  • plot_compartment – (Default value = ‘InfectedSymptoms’)

  • max_subplots – Number of the simulation runs to be plotted and compared against. (Default value = 8)

Returns:

No return

memilio.surrogatemodel.ode_secir_groups.model.plot_losses(history)

Plots the losses of the model training.

Parameters:

history – model training history.

Returns:

No return

memilio.surrogatemodel.ode_secir_groups.model.prepare_data_classic(data)

Transforming data to be processable by “classic” network, simply flattening and concatenating for each data instance.

Parameters:

data – dictionary produced by data_generation

Returns:

dictionary with entries { “train_inputs”, “train_labels”, “valid_inputs”, “valid_labels”, “test_inputs”, “test_labels”}

memilio.surrogatemodel.ode_secir_groups.model.prepare_data_timeseries(data)

Transforming data to be processable by “timeseries” network, simply repeating static values, flattening and concatenating for each data instance.

Parameters:

data – dictionary produces by data_generation

Returns:

dictionary with entries { “train_inputs”, “train_labels”, “valid_inputs”, “valid_labels”, “test_inputs”, “test_labels”

}

memilio.surrogatemodel.ode_secir_groups.model.prod_time_series(obj, n, length_input)

Repeating static informations to fit into a time series framework

Parameters:
  • obj – an array of objects of shape (n, shape_rest), which should be repeated

  • n – total number of samples

  • length_input – number of days observed per input

Returns:

a tensor of shape [n, length_input, -1], where for each sample the static object is repeated length_input times