Interactive¶
Interactive Jupyter widgets for SymbolicEpiModels.
-
class
epipack.interactive.
GeneralInteractiveWidget
(**kwargs)[source]¶ Bases:
ipywidgets.widgets.widget_box.HBox
An interactive widget that lets you control parameters that are passed to a custom function which returns a result dictionary.
Based on this tutorial: https://kapernikov.com/ipywidgets-with-matplotlib/
- Parameters
result_function (func) -- A function that returns a result dictionary when passed parameter values as
result_function(**parameter_values)
.parameter_values (dict) -- A dictionary that maps parameter names to single, fixed values or ranges (instances of
epipack.interactive.Range
orepipack.interactive.LogRange
).t (numpy.ndarray) -- The time points corresponding to values in the result dictionary.
return_keys (list, default = None) -- A list of result keys that should be shown. If
None
, all compartments will be displayed.figsize (tuple, default = (4,4)) -- Width and height of the created figure.
palette (str, default = 'dark') --
A palette from
epipack.colors
. Choose from[ 'dark', 'light', 'dark pastel', 'light pastel', 'french79', 'french79 pastel', 'brewer light', 'brewer dark', 'brewer dark pastel', 'brewer light pastel' ]
continuous_update (bool, default = False) -- If
False
, curves will be updated only if the mouse button is released. IfTrue
, curves will be continuously updated.show_grid (bool, default = False) -- Whether or not to display a grid
ylabel (str, default = 'frequency') -- What to name the yaxis
label_converter (func, default = str) -- A function that returns a string when passed a result key or parameter name.
-
result_function
¶ A function that returns a result dictionary when passed parameter values as
result_function(**parameter_values)
.- Type
func
-
t
¶ The time points corresponding to values in the result dictionary.
- Type
numpy.ndarray
-
fig
¶ The figure that will be displayed.
- Type
matplotlib.Figure
-
ax
¶ The axis that will be displayed.
- Type
matplotlib.Axis
-
continuous_update
¶ If
False
, curves will be updated only if the mouse button is released. IfTrue
, curves will be continuously updated.- Type
bool, default = False
-
lbl
¶ A function that returns a string when passed a result key or parameter name.
- Type
func, default = str
-
update_parameters
(*args, **kwargs)[source]¶ Update the current values of parameters as given by slider positions.
-
update_plot
(parameters)[source]¶ Recompute and -draw the epidemic curves with updated parameter values
-
class
epipack.interactive.
InteractiveIntegrator
(**kwargs)[source]¶ Bases:
ipywidgets.widgets.widget_box.HBox
An interactive widget that lets you control parameters of a SymbolicEpiModel and shows you the output.
Based on this tutorial: https://kapernikov.com/ipywidgets-with-matplotlib/
- Parameters
model (epipack.symbolic_epi_models.SymbolicEpiModel) -- An instance of
SymbolicEpiModel
that has been initiated with initial conditionsparameter_values (dict) -- A dictionary that maps parameter symbols to single, fixed values or ranges (instances of
epipack.interactive.Range
orepipack.interactive.LogRange
).t (numpy.ndarray) -- The time points over which the model will be integrated
return_compartments (list, default = None) -- A list of compartments that should be displayed. If
None
, all compartments will be displayed.return_derivatives (list, default = None) -- A list of derivatives that should be displayed If
None
, no derivatives will be displayed.figsize (tuple, default = (4,4)) -- Width and height of the created figure.
palette (str, default = 'dark') --
A palette from
epipack.colors
. Choose from[ 'dark', 'light', 'dark pastel', 'light pastel', 'french79', 'french79 pastel', 'brewer light', 'brewer dark', 'brewer dark pastel', 'brewer light pastel' ]
integrator (str, default = 'dopri5') -- Either
euler
ordopri5
.continuous_update (bool, default = False) -- If
False
, curves will be updated only if the mouse button is released. IfTrue
, curves will be continuously updated.show_grid (bool, default = False) -- Whether or not to display a grid
-
model
¶ An instance of
SymbolicEpiModel
that has been initiated with initial conditions.
-
t
¶ The time points over which the model will be integrated
- Type
numpy.ndarray
-
fig
¶ The figure that will be displayed.
- Type
matplotlib.Figure
-
ax
¶ The axis that will be displayed.
- Type
matplotlib.Axis
-
continuous_update
¶ If
False
, curves will be updated only if the mouse button is released. IfTrue
, curves will be continuously updated.- Type
bool, default = False
-
update_parameters
(*args, **kwargs)[source]¶ Update the current values of parameters as given by slider positions.
-
update_plot
(parameters)[source]¶ Recompute and -draw the epidemic curves with updated parameter values
-
class
epipack.interactive.
LogRange
(min, max, step_count=100, value=None, base=10)[source]¶ Bases:
dict
Defines a value range for an interactive logarithmic value slider.
- Parameters
min (float) -- Minimal value of parameter range
max (float) -- Maximal value of parameter range
step_count (int, default = 100) -- Divide the exponent space into that many intervals
base (float, default = 10) -- Base of the logarithm
value (float, default = None) -- Initial value. If
None
, defaults to the geometric mean ofmin
andmax
.