Helper Module for Deep Learning.
-
class
pynet.plotting.graph.Graph[source]¶ Simple Graph Structure on which we want to perform a topological tree (no cycle).
The algorithm is based on the R.E. Tarjanlinear linear optimization (O(N+A)).
Attributes
_nodes
(dict) the graph nodes {node.name: node}
_links
(list) graph edges (from_node, to_node)
-
add_graph(graph)[source]¶ Method to add a Graph in the Graph.
- Parameters
graph: Graph (mandatory)
the graph to insert.
-
add_link(from_node, to_node)[source]¶ Method to add an edge between two GraphNodes of the Graph.
- Parameters
from_node: GraphNode (mandatory)
node link representation of the form ‘<node>.<control>’.
to_node: GraphNode (mandatory)
node link representation of the form ‘<node>.<control>’.
-
add_node(node)[source]¶ Method to add a GraphNode in the Graph.
- Parameters
node: GraphNode (mandatory)
the node to insert.
-
adjacency_matrix()[source]¶ Compute the graph adjacency matrix.
- Returns
adjacency_matrix: array
Graph adjacency matrix.
node_names: list
Ordered node names.
-
find_node(node_name)[source]¶ Method to find a GraphNode in the Graph.
- Parameters
node_name: str (mandatory)
the name of the desired node.
-
layout(scale=1.0)[source]¶ Position nodes using the eigenvectors of the graph Laplacian.
- Parameters
scale: float (optional, default 1.0)
Scale factor for positions. The nodes are positioned in a box of size [0, scale] x [0, scale].
- Returns
pos: dict
A dictionary of positions keyed by node.
-
remove_node(node_name)[source]¶ Method to remove a GraphNode from the Graph.
- Parameters
node: string (mandatory)
the name of the node to remove.
-
topological_sort()[source]¶ Perform the topological sort: find an order in which all the nodes can be taken.
Step 1: Identify nodes that have no incoming link (nnil). Step 2: Loop until there are nnil a) Delete the current nodes c_nnil of in-degree 0. b) Place it in the output. c) Remove all its outgoing links from the graph. d) If the node has in-degree 0, add the node to nnil. Step 3: Assert that there is no loop in the graph.
- Returns
output: list of tuple
a list of ordered nodes with a tuple element containing the node name and the node meta element.
-
-
class
pynet.plotting.graph.GraphNode(name, meta)[source]¶ Simple Graph Node Structure.
Attributes
name
(str) the node name
meta
(object) a python object stored in the node
links_to
(list) object to store the graph edges: sucessor
links_from
(list) object to store the graph edges: predecessor
links_to_degree
(int) degree of the node regarding the successors
links_from_degree
(int) degree of the node regarding the predecessors
-
__init__(name, meta)[source]¶ Create a Graph Node.
- Parameters
name: str (mandatory)
the name of the node.
meta: object
an python object to store in the node.
-
add_link_from(node)[source]¶ Method to add a Predecessor.
- Parameters
node: GraphNode (mandatory)
the predecessor node.
-
add_link_to(node)[source]¶ Method to add a Successor.
- Parameters
node: GraphNode (mandatory)
the successor node.
-
Follow us
Inspired by AZMIND template.