How to add a model? - illinoistech-itm/py-mgipsim GitHub Wiki

Defining the model

  • Define the state variables, inputs, constants, parameters, and model equations in the VirtualPatient/Models folder
  • In the Parameters file:
    • Define all model parameters and their vectorization function (as_array).
    • Define generate function that either loads patient files or draws random samples from distributions.
  • In the Inputs file:
    • Define all model inputs and their vectorization function (as_array).
  • In the Model file:
    • Define a unique name in the Model class, same name should be given to the folder.
    • Diff. equations should be defined in the model function.
    • Initial conditions should be defined in the preprocessing function.
    • A from_scenario function has to be defined which passes the inputs, parameters, etc. from the scenario to the model. Unit conversions from the default units to the model specific ones is convenient to do in this function.
  • Define virtual patient parameters in JSON files in the Patients folder.

Add model to the generate functions

  • Add functions that generate the necessary inputs of the model in generate_inputs_main function in the generate_inputs file.
  • Add model parameter generation in generate_virtual_subjects_main function in the generate_subjects file.

[!NOTE]
If the added model is just an auixiliary model, it can be readily used for simulation. An example is the physical activity -> heart rate model, and the implementation can be found in pymgipsim/InputGeneration/heart_rate_settings.py. If the added model represents the patient, the following steps are needed.

Update VirtualCohort

  • Add the defined model to the virtual patient class in VirtualPatient/VirtualPatient.

Update plots

  • Update plotting function with specifics of the defined model.

Optional: Controller compatibility