ModelDiagram#
- class epiworldpy.ModelDiagram(self: epiworldpy._core.ModelDiagram)#
Bases:
pybind11_objectDraws 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 a diagram from a transition probability matrix.
Draw a diagram from a file of transition counts.
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 Smatrix of transition probabilities, whereSis the number of states, stored by columns: entryi + j * Sis the probability of moving from stateito statej. This is whatDataBase.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_transitionargument ofModel.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_transitionargument ofModel.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.