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 or epipack.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. If True, 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

fixed_parameters

A dictionary that maps parameter names to fixed values

Type

dict

t

The time points corresponding to values in the result dictionary.

Type

numpy.ndarray

return_keys

A list of result dictionary keys of which the result will be displayed.

Type

list

colors

A list of hexstrings.

Type

list

fig

The figure that will be displayed.

Type

matplotlib.Figure

ax

The axis that will be displayed.

Type

matplotlib.Axis

lines

Maps compartments to line objects

Type

dict

children

Contains two displayed boxes (controls and output)

Type

list

continuous_update

If False, curves will be updated only if the mouse button is released. If True, 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

update_xscale(change)[source]

Update the scale of the x-axis. For "log", pass an object change that has change.new=True

update_yscale(change)[source]

Update the scale of the y-axis. For "log", pass an object change that has change.new=True

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 conditions

  • parameter_values (dict) -- A dictionary that maps parameter symbols to single, fixed values or ranges (instances of epipack.interactive.Range or epipack.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 or dopri5.

  • continuous_update (bool, default = False) -- If False, curves will be updated only if the mouse button is released. If True, 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.

Type

epipack.symbolic_epi_models.SymbolicEpiModel

fixed_parameters

A dictionary that maps parameter symbols to single, fixed values

Type

dict

t

The time points over which the model will be integrated

Type

numpy.ndarray

return_compartments

A list of compartments that will be displayed.

Type

list

colors

A list of hexstrings.

Type

list

fig

The figure that will be displayed.

Type

matplotlib.Figure

ax

The axis that will be displayed.

Type

matplotlib.Axis

lines

Maps compartments to line objects

Type

dict

children

Contains two displayed boxes (controls and output)

Type

list

continuous_update

If False, curves will be updated only if the mouse button is released. If True, 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

update_xscale(change)[source]

Update the scale of the x-axis. For "log", pass an object change that has change.new=True

update_yscale(change)[source]

Update the scale of the y-axis. For "log", pass an object change that has change.new=True

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 of min and max.

class epipack.interactive.Range(min, max, step_count=100, value=None)[source]

Bases: dict

Defines a value range for an interactive linear value slider.

Parameters
  • min (float) -- Minimal value of parameter range

  • max (float) -- Maximal value of parameter range

  • step_count (int, default = 100) -- Divide the parameter space into that many intervals

  • value (float, default = None) -- Initial value. If None, defaults to the mean of min and max.

epipack.interactive.get_box_layout()[source]

Return default box layout