network – Directed Acyclic Graphs

A pebl network is a collection of nodes and directed edges between nodes.

Nodes are a list of pebl.data.Variable instances. Edges are stored in EdgeList instances. This module provides two implementations, MatrixEdgeList for small networks and SparseEdgeList for large, sparse networks. Both offer the same functionality with different performance characteristics.

Functions and methods accept and return nodes as numbers representing their indices and edges as tuples of integers corresponding to (srcnode, destnode).

Edges

class pebl.network.EdgeSet(num_nodes=0)

Maintains a set of edges.

Performance characteristics:
  • Edge insertion: O(1)
  • Edge retrieval: O(n)

Uses adjacency lists but exposes an adjacency matrix interface via the adjacency_matrix property.

add(edge)

Add an edge to the list.

add_many(edges)

Add multiple edges.

adjacency_lists

Set or get edges as two adjacency lists.

Property returns/accepts two adjacency lists for outgoing and incoming edges respectively. Each adjacency list if a list of sets.

adjacency_matrix

Set or get edges as an adjacency matrix.

The adjacency matrix is a boolean numpy.ndarray instance.

children(node)

Return list of nodes (as node indices) that have an edge from given node.

The returned list is sorted. Method is also aliased as children().

clear()

Clear the list of edges.

incoming(node)

Return list of nodes (as node indices) that have an edge to given node.

The returned list is sorted. Method is also aliased as parents().

outgoing(node)

Return list of nodes (as node indices) that have an edge from given node.

The returned list is sorted. Method is also aliased as children().

parents(node)

Return list of nodes (as node indices) that have an edge to given node.

The returned list is sorted. Method is also aliased as parents().

remove(edge)

Remove edges from edgelist.

If an edge to be removed does not exist, fail silently (no exceptions).

remove_many(edges)

Remove multiple edges.

Network

class pebl.network.Network(nodes, edges=None)

A network is a set of nodes and directed edges between nodes

Creates a Network.

nodes is a list of pebl.data.Variable instances. edges can be:

  • an EdgeSet instance
  • a list of edge tuples
  • an adjacency matrix (as boolean numpy.ndarray instance)
  • string representation (see Network.as_string() for format)
as_dotfile(filename)

Saves network as a dot file.

as_dotstring()

Returns network as a dot-formatted string

as_image(filename, decorator=<function <lambda> at 0x1029e6cf8>, prog='dot')

Creates an image (PNG format) for the newtork.

decorator is a function that accepts a pydot graph, modifies it and returns it. decorators can be used to set visual appearance of networks (color, style, etc).

prog is the Graphviz program to use (default: dot).

as_pydot()

Returns a pydot instance for the network.

as_string()

Returns the sparse string representation of network.

If network has edges (2,3) and (1,2), the sparse string representation is “2,3;1,2”.

copy()

Returns a copy of this network.

is_acyclic(roots=None)

Uses a depth-first search (dfs) to detect cycles.

is_acyclic_python(roots=None)

Uses a depth-first search (dfs) to detect cycles.

layout(width=400, height=400, dotpath='dot')

Determines network layout using Graphviz’s dot algorithm.

width and height are in pixels. dotpath is the path to the dot application.

The resulting node positions are saved in network.node_positions.

Factory functions

pebl.network.fromdata(data_)

Creates a network from the variables in the dataset.

pebl.network.random_network(nodes, required_edges=[], prohibited_edges=[])

Creates a random network with the given set of nodes.

Can specify required_edges and prohibited_edges to control the resulting random network.

Table Of Contents

Previous topic

learner.simanneal – Simulated annealing learner

Next topic

posterior – Posterior distribution

This Page