Reparameterize a model class

Todo

Explain how to create a reference model state for a custom model class

To start, you need a Model class. There are two options.

  • Create your own model as described here.

  • Use an existing model and reparameterize.

Parameterization is done using the function ‘set_reference()’. To copy the VanOsta2023 build with your own model parameterization, create a class derived from VanOsta2023. This can be done using the following code.

import circadapt
from circadapt.model.VanOsta2023 import VanOsta2023

class MyOwnModel(VanOsta2023):
    def set_reference(self):
        super().set_reference()

        # change model parameters here
        # e.g.
        self['Patch2022']['Sf_act'] = [84e3, 84e3, 120e3, 120e3, 120e3]

        # run stable if a steady-state reference is desired
        self.run(stable=True)

Note: to ensure future updates wont effect your model, set all model parameters as done on thet set_reference() function here.

When building on top of other model definitions, always reimplement the get_unittest_targets function. This function allows you to check whether updates alter your model. For example, VanOsta2023 needs the following targets:

class MyOwnModel(VanOsta2023):
    ...
    def get_unittest_targets(self):
        """Hardcoded results after initializing and running 1 beat."""
        return {
            'LVEDV': 141.6,
            'LVESV':  69.4,
            }

Other targets could be implemented, as described here.

If generating the model reference requires significant computational resources, it’s advisable to think about exporting the model reference. This process is automated through the utilization of the following __init__ function:

class MyOwnModel(VanOsta2023):
    ...
    def __init__(self, *arg, **kwarg):
        super().__init__(*arg, **kwarg)

        self._local_save_reference = True

    ...

When you run your script for the first time, the state of the reference model will be saved in the project directory.

Models might include predefined plot statements. These are automatically inherited from the parent model, but you can modify them according to your preferences if needed.

class MyOwnModel(VanOsta2023):
    ...
    def plot(self, fig=None):
        """Small plot of current model state."""
        if fig is None:
            fig = 1
        if isinstance(fig, int):
            fig = plt.figure(fig, clear=True, figsize=(12, 8))

        # plot magic here

    def plot_extended(self, fig=None):
        """Extended plot of current model state."""
        if fig is None:
            fig = 1
        if isinstance(fig, int):
            fig = plt.figure(fig, clear=True, figsize=(12, 8))

        # plot magic here

    ...