graphskeleton

This module provides tools for creating and using graph skeletons for Bayesian networks. A graph skeleton in this case is a vertex set and a directed edge set, with no further information about the specific nodes.

class libpgm.graphskeleton.GraphSkeleton[source]

This class represents a graph skeleton, meaning a vertex set and a directed edge set. It contains the attributes V and E, and the methods load, getparents, getchildren, and toporder.

V = None

A list of names of vertices.

E = None

A list of [origin, destination] pairs of vertices that constitute edges.

alldata = None

(Inherited from dictionary) A variable that stores a key-indexable dictionary once it is loaded from a file.

load(path)[source]

Load the graph skeleton from a text file located at path.

Text file must be a plaintext .txt file with a JSON-style representation of a dict. Dict must contain the top-level keys “V” and “E” with the following formats:

{
    'V': ['<vertex_name_1>', ... , '<vertex_name_n'],
    'E': [['vertex_of_origin', 'vertex_of_destination'], ... ]
}
Arguments:
  1. path – The path to the file containing input data (e.g., “mydictionary.txt”).
Attributes modified:
  1. V – The set of vertices.
  2. E – The set of edges.
getparents(vertex)[source]

Return the parents of vertex in the graph skeleton.

Arguments:
  1. vertex – The name of the vertex whose parents the function finds.
Returns:
A list containing the names of the parents of the vertex.
getchildren(vertex)[source]

Return the children of vertex in the graph skeleton.

Arguments:
  1. vertex – The name of the vertex whose children the function finds.
Returns:
A list containing the names of the children of the vertex.
toporder()[source]

Modify the vertices of the graph skeleton such that they are in topological order.

A topological order is an order of vertices such that if there is an edge from u to v, u appears before v in the ordering. It works only for directed ayclic graphs.

Attributes modified:
  1. V – The names of the vertices are put in topological order.

The function also checks for cycles in the graph, and returns an error if one is found.

Previous topic

dictionary

Next topic

orderedskeleton

This Page