ModelDiagram#

class epiworldpy.ModelDiagram(self: epiworldpy._core.ModelDiagram)#

Bases: pybind11_object

Draws a model’s states and transitions as a flowchart.

Examples

>>> from epiworldpy import DiagramType, ModelDiagram, epimodels
>>> model = epimodels.ModelSIRCONN("COVID-19", n=10000, prevalence=0.01,
...                                contact_rate=5, transmission_rate=0.4,
...                                recovery_rate=0.95)
>>> model.run(ndays=100, seed=1912)
>>> ModelDiagram().draw_from_data(
...     DiagramType.Mermaid, model.get_states(),
...     model.get_db().get_transition_probability())

Create a diagram.

Methods

draw_from_data

Draw a diagram from a transition probability matrix.

draw_from_file

Draw a diagram from a file of transition counts.

draw_from_files

Draw a diagram from several files of transition counts, such as those saved by Model.run_multiple().

draw_from_data(self: epiworldpy._core.ModelDiagram, diagram_type: epiworldpy._core.DiagramType, states: collections.abc.Sequence[str], tprob: collections.abc.Sequence[SupportsFloat | SupportsIndex], fn_output: str = '', self_loops: bool = False) → None#

Draw a diagram from a transition probability matrix.

Parameters:
  • diagram_type (DiagramType) – Output format.

  • states (list of str) – State labels.

  • tprob (list of float) – Flattened S x S matrix of transition probabilities, where S is the number of states, stored by columns: entry i + j * S is the probability of moving from state i to state j. This is what DataBase.get_transition_probability() returns.

  • fn_output (str, default "") – Path of the output file. With an empty string, the diagram is printed instead.

  • self_loops (bool, default False) – Whether to draw transitions from a state to itself.

draw_from_file(self: epiworldpy._core.ModelDiagram, diagram_type: epiworldpy._core.DiagramType, fn_transition: str, fn_output: str = '', self_loops: bool = False) → None#

Draw a diagram from a file of transition counts.

Parameters:
  • diagram_type (DiagramType) – Output format.

  • fn_transition (str) – Path of a file written with the fn_transition argument of Model.write_data().

  • fn_output (str, default "") – Path of the output file. With an empty string, the diagram is printed instead.

  • self_loops (bool, default False) – Whether to draw transitions from a state to itself.

draw_from_files(self: epiworldpy._core.ModelDiagram, diagram_type: epiworldpy._core.DiagramType, fns_transition: collections.abc.Sequence[str], fn_output: str = '', self_loops: bool = False) → None#

Draw a diagram from several files of transition counts, such as those saved by Model.run_multiple().

Parameters:
  • diagram_type (DiagramType) – Output format.

  • fns_transition (list of str) – Paths of files written with the fn_transition argument of Model.write_data().

  • fn_output (str, default "") – Path of the output file. With an empty string, the diagram is printed instead.

  • self_loops (bool, default False) – Whether to draw transitions from a state to itself.