Marked Graph

a marked graph
class pyagrum.EdgeMark(value)

The mark at an end of an edge of a marked graph (pyagrum.MarkedGraph, pyagrum.PAG).

An edge x-y carries one mark at x and one at y: x->y has a tail at x and an arrowhead at y, x<->y an arrowhead at both ends, x--y a tail at both ends; a circle is an end whose mark is not determined (in a PAG, it varies across the equivalence class).

Attributes

Arrowhead

The mark at an end of an edge of a marked graph (pyagrum.MarkedGraph, pyagrum.PAG).

Circle

The mark at an end of an edge of a marked graph (pyagrum.MarkedGraph, pyagrum.PAG).

Tail

The mark at an end of an edge of a marked graph (pyagrum.MarkedGraph, pyagrum.PAG).

class pyagrum.MarkedGraph(*args)

MarkedGraph represents a graph whose edges carry a mark at each of their ends.

Each edge between nodes x and y has two marks, one at each end (pyagrum.EdgeMark):

  • EdgeMark.Circle (o): undetermined end

  • EdgeMark.Tail (-): tail

  • EdgeMark.Arrowhead (>): arrowhead

There is at most one edge between two nodes: x->y (tail at x, arrowhead at y), x<->y, x--y, x o-> y, x o-o y… A marked graph is not an undirected graph: its skeleton is given by skeleton() and its directed view by parents, children, spouses and undirectedNeighbours.

MarkedGraph() -> MarkedGraph

default constructor

MarkedGraph(src) -> MarkedGraph
Parameters:

See also pyagrum.fastMarkedGraph, pyagrum.PAG and pyagrum.MAG.

Scientific notes

A marked graph has at most one edge between two nodes, with a mark at each end: a tail, an arrowhead or a circle. The tails and arrowheads give the directed (\(\to\)), bidirected (\(\leftrightarrow\)) and undirected (\(-\)) edges of the ancestral graphs [1] (pyagrum.MAG); the circles are the marks that vary in a Markov equivalence class of such graphs, in the partial ancestral graphs [2] (pyagrum.PAG).

Conventions of pyAgrum: markAt(x, y) is the mark at the \(y\) end of the edge \(x - y\); an edge added without marks is \(x \circ\!\!-\!\!\circ\, y\). The directed view is read from the marks: the parents of \(x\) are the nodes \(y\) with \(y \to x\), its spouses the nodes with \(y \leftrightarrow x\), and a node \(z\) is a definite collider on \(x - z - y\) when both edges have an arrowhead at \(z\). A marked graph checks no other property.

Methods

addEdge()

Add an edge between two nodes with specified endpoint marks.

addNode()

Add a new node to the graph and return its id.

addNodeWithId()

Add a node with a chosen id.

addNodes()

Add n new nodes to the graph.

adjacencyMatrix()

adjacency matrix from a graph/graphical models

children()

clear()

Remove all the nodes and edges from the graph.

clearEdges()

Remove all edges and their endpoint marks from the graph.

clearNodes()

Remove all the nodes, hence all the edges and their marks, from the graph (same as clear()).

connectedComponents()

connectedComponentsCount()

number of connected components

connectedComponentsList()

connected components as a dict of sets

edges()

empty()

Check whether the graph has no nodes.

emptyEdges()

Check whether the graph has no edges.

eraseEdge()

Erase the edge (and its marks) if it exists.

eraseNeighbours()

Remove all edges adjacent to a given node (and their marks).

eraseNode()

Erase the node and all the adjacent edges.

existsEdge()

Check whether an edge exists between two nodes.

existsNode()

Check whether a node with the given id exists in the graph.

hasName()

Check whether a node has an explicitly assigned name.

idFromName()

Return the id of the node with the given name, or None if no such name exists.

idsFromNames()

The ids of nodes given by their names, in a container of the same type.

isArrowhead()

Return True if the mark at dst (seen from src) is an arrowhead.

isBidirected()

Return True if both endpoints of edge (x, y) are arrowheads (bidirected edge).

isCircle()

Return True if the mark at dst (seen from src) is a circle.

isDefCollider()

Return True if z is a definite collider on the path x-z-y.

isDefinitelyDirected()

Return True if the edge x-y is definitely directed from x to y.

isTail()

Return True if the mark at dst (seen from src) is a tail.

isUndirected()

Return True if the edge x-y has a tail at both ends (x–y).

markAt()

Return the endpoint mark on the dst side of edge (src, dst).

nameFromId()

Return the name of a node, or its id as a string if no name was set.

namesFromIds()

The names of nodes given by their ids, in a container of the same type.

neighbours()

nodes()

parents()

reorientAllWith()

Set all endpoint marks in the graph to the given mark.

saveGUM()

Save the graph as a .jgum (text) or .bgum (binary) file (its class, its nodes with their names, its arcs, edges and marks).

saveGUMstring()

Save the graph as a jgum string (see pyagrum.graphFromGUMString to read it back).

setMarkAt()

Set the endpoint mark on the dst side of edge (src, dst).

setName()

Assign a name to a node.

size()

Return the number of nodes in the graph.

sizeEdges()

Return the number of edges in the graph.

skeleton()

spouses()

toDot()

Return a Graphviz dot representation of the graph.

undirectedNeighbours()