Simulation interfaces

class mshoot.SimModel

Bases: abc.ABC

MShoot statefull model interface.

simulate(udf, x0, **kwargs)

Simulate the model using the provided inputs udf and initial state x0.

The DataFrame should have the following content:

  • index - time in seconds and equal steps,
  • columns - input data,
  • column names - input variable names.

Return two DataFrames, ydf and xdf, with outputs and states, respectively, and with the same structure as udf.

Parameters:
  • udf – DataFrame, shape (n_steps, n_variables)
  • x0 – vector, size (n_states, )
  • **kwargs – Additional arguments required by some interfaces
Returns:

ydf, xdf

class mshoot.SimFMU(fmupath, outputs=[], states=[], parameters={}, verbose=False)

Bases: mshoot.mshoot.SimModel

simulate(udf, x0, save_state=False)

Simulate the model using the provided inputs udf and initial state x0.

The DataFrame should have the following content:

  • index - time in seconds and equal steps, named ‘time’,
  • columns - input data,
  • column names - input variable names.

The order of x0 should reflect the one used in states.

Return two DataFrames, ydf and xdf, with outputs and states, respectively, and with the same structure as udf.

Parameters:
  • udf – DataFrame, shape (n_steps, n_variables)
  • x0 – vector, size (n_states, )
Returns:

ydf, xdf

class mshoot.SimScikit(model='Linear', use_state=False, **args)

Bases: mshoot.mshoot.SimModel

Unlike other interface classes (e.g. SimFMU) which are simple wrappers for the existing models, SimScikit works more like an automation layer for Scikit-Learn models, covering model instantiation, training, and prediction (simulation). In addition, the selected ML model is turned into a dynamic model by:

  • predicting the time derivative of the state,
  • running a model in a time loop, at each step predicting one-step ahead,
  • using the time-backshifted output as one of the predictors.

The way this class should be used is as follows:

  1. Select the model type with __init__(…)
  2. Train the model with train(…)
  3. Simulate with simulate(…)

Note

TODO: Linear interpolation between time steps -> 0.5 * (feat[i-1] + feat[i]) (currently x[i] is calculated based on x[i-1], dt[i], and feat[i] only)

Parameters:
  • model – str, Scikit-Learn regression model type
  • use_state – bool, If True, state is included in the features
  • **args – Optional arguments to be passed to a sklearn model
simulate(udf, x0, **kwargs)

Simulate the model using the provided inputs udf and initial state x0.

The DataFrame should have the following content:

  • index - time in seconds and equal steps, named ‘time’,
  • columns - input data,
  • column names - input variable names.

The order of x0 should reflect the one used in states.

Return two DataFrames, ydf and xdf, with outputs and states, respectively, and with the same structure as udf.

Parameters:
  • udf – DataFrame, shape (n_variables, n_steps)
  • x0 – vector, size (n_states, )
Returns:

ydf, xdf

train(udf, xdf, ydf)

Train the model. The model can be retrained any time between the simulations.

Parameters:
  • udf – DataFrame, shape (n_steps, n_variables)
  • xdf – DataFrame, shape (n_steps, n_states)
  • ydf – DataFrame, shape (n_steps, n_outputs)
Returns:

None