ChainEventGraph#

class cegpy.ChainEventGraph(staged_tree: Optional[StagedTree] = None, node_prefix: str = 'w', generate: bool = True)[source]#

Bases: MultiDiGraph

Representation of a Chain Event Graph.

A Chain Event Graph reduces a staged tree.

The class is an extension of NetworkX MultiDiGraph.

Parameters:
  • staged_tree (StagedTree) – A staged tree object where the stages have been calculated.

  • node_prefix (str) – The prefix that is used for the nodes in the Chain Event Graph. Default = “w”

  • generate (bool) – Automatically generate the Chain Event Graph upon creation of the object. Default = True.

property sink: str#
Returns:

Sink node name

Return type:

str

property root: str#
Returns:

Root node name

Return type:

str

property stages: Mapping[str, Set[str]]#
Returns:

Mapping of stages to constituent nodes.

Return type:

Mapping[str, Set[str]]

property path_list: List[List[Tuple[str]]]#
Returns:

All the paths through the CEG, as a list of lists of edge tuples.

Return type:

List[List[Tuple[str]]]

generate() None[source]#

Identifies the positions i.e. the nodes of the CEG and the edges of the CEG along with their edge labels and edge counts. Here we use the algorithm from our paper with the optimal stopping time.

dot_graph(edge_info: str = 'probability') Dot[source]#

Returns Dot graph representation of the CEG. :param edge_info: Optional - Chooses which summary measure to be displayed on edges. Defaults to “count”. Options: [“count”, “prior”, “posterior”, “probability”]

Returns:

A graphviz Dot representation of the graph.

Return type:

pydotplus.Dot

create_figure(filename=None, edge_info: str = 'probability') Optional[Image][source]#

Draws the coloured chain event graph for the staged_tree.

Parameters:
  • filename (str) –

    Optional - When provided, file is saved to the filename, local to the current working directory. e.g. if filename = “output/ceg.svg”, the file will be saved to: cwd/output/ceg.svg Otherwise, if function is called inside an interactive notebook, image will be displayed in the notebook, even if filename is omitted.

    Supports any filetype that graphviz supports. e.g: “ceg.png” or “ceg.svg” etc.

  • edge_info (str) – Optional - Chooses which summary measure to be displayed on edges. Value can take: “count”, “prior”, “posterior”, “probability”

Returns:

The event tree Image object.

Return type:

IPython.display.Image or None