Parameterisation#
Until now, we have only dealt with parameters when it was necessary to inform PyGOM which of our symbols refer to states and which to parameters. However, before PyGOM can find numerical solutions to the equations, it must be fed numerical parameter values. PyGOM’s ODE solvers accept parameters in two forms: fixed, where they remain constant, or random, where they are drawn from a given distribution. We demonstrate these features on our model system, the SIR compartmental model. We start, as always, by encapsulating our ODE system in a PyGOM object, in this case loading a previously defined model.
from pygom import common_models
ode = common_models.SIR()
Fixed parameters#
Defining fixed parameters for \(\beta\), \(\gamma\) and \(N\) is simply done via a list of tuples as follows:
fixed_param_set=[('beta', 0.3), ('gamma', 0.25), ('N', 1e4)]
ode.parameters=fixed_param_set
Random parameters#
Instead, imagine that we have some prior uncertainty on the values of our model parameters. We may wish to reflect this by running model simulations over a variety of parameter values drawn randomly from a probability distribution. A suitable choice of distribution for \(\gamma\) and \(\beta\) is a gamma distribution, since it ensures that both parameters are positive as required. In this example, we’ll keep the total population, \(N\), fixed, showing that a mixture of parameter types (fixed and random) is possible.
To define our random distributions, we make use of the familiar syntax from R. Slightly cumbersomely, we have to define it via a tuple, where the first item is the function handle (name) and the second the parameters.
from pygom.utilR import rgamma
random_param_set = dict() # container for random param set
random_param_set['gamma'] = (rgamma,{'shape':100, 'rate':400})
random_param_set['beta'] = (rgamma,{'shape':100, 'rate':333.33})
random_param_set['N'] = 1e4
The values of the shape and rate parameters mean that \(\gamma\) and \(\beta\) have means of 0.25 and 0.3 and standard deviations of 0.025 and 0.03 respectively.
When changing parameters, it is a good idea to define a new SimulateOde
object, since there may be some calculated variables leftover from the previous parameter set.
We do not need to inform PyGOM that the parameters are random and define them in the same way as before:
ode = common_models.SIR()
ode.parameters=random_param_set