1.1. ReebGraph class

This is the Reeb graph class which is the majority of functionality of the package. This includes functionality such as assigning function values to nodes in the Reeb graph and plotting the graph.

Note that this class can be imported as:

import cereeberus
R = cereeberus.ReebGraph()
class cereeberus.reeb.reebgraph.ReebGraph(G=None, f={}, seed=None, verbose=False)[source]

A Reeb graph stored as a networkx MultiDiGraph. The function values are stored as a dictionary. The directedness of the edges follows the convention that the edge goes from the lower function value to the higher function value node.

__init__(G=None, f={}, seed=None, verbose=False)[source]

Initializes a Reeb graph object.

Parameters:
  • G – nx.graph, optional. If not None, a graph to initialize the Reeb graph.

  • f – dict, optional. If not an empty dictionary, a dictionary of function values associated with the graph nodes.

  • seed – int, optional. If not None, a seed to pass to the spring layout.

  • verbose – bool, optional. If True, will print out additional information during initialization.

summary()[source]

Summary of the Reeb graph.

Returns:

dict

A dictionary with the number of nodes and edges in the Reeb graph.

up_degree(node)[source]

Get the up degree of a node.

Parameters:

node – int. The node to get the up degree of.

Returns:

int

The up degree of the node.

down_degree(node)[source]

Get the down degree of a node.

Parameters:

node – int The node to get the down degree of.

Returns:

int

The down degree of the node.

number_connected_components()[source]

Get the number of connected components in the Reeb graph.

Returns:

int

The number of connected components in the Reeb graph.

next_vert_name(s)[source]

Making a simple name generator for vertices. If you’re using integers, it will just up the count by one. Letters will be incremented in the alphabet. If you reach ‘Z’, it will return ‘AA’. If you reach ‘ZZ’, it will return ‘AAA’, etc.

Parameters:

s (str or int) – The name of the vertex to increment.

Returns:

str or int

The next name in the sequence.

add_node(vertex, f_vertex, reset_pos=True)[source]

Add a vertex to the Reeb graph. If the vertex name is given as None, it will be assigned via the next_vert_name method.

Parameters:
  • vertex (hashable like int or str, or None) – The name of the vertex to add.

  • f_vertex (float) – The function value of the vertex being added.

  • reset_pos (bool, optional) – If True, will reset the positions of the nodes based on the function values.

add_nodes_from(nodes, f_dict, reset_pos=True)[source]

Add a list of nodes to the Reeb graph.

Parameters:
  • nodes (list) – The list of node names to add.

  • f_dict (dict) – A dictionary of function values associated with the nodes. Should be f_dict[node] = f_value.

  • reset_pos (bool, optional) – If True, will reset the positions of the nodes based on the function values.

remove_node(vertex, reset_pos=True)[source]

Remove a vertex from the Reeb graph.

Parameters:
  • vertex (hashable like int or str) – The name of the vertex to remove.

  • reset_pos (bool, optional) – If True, will reset the positions of the nodes based on the function values.

remove_nodes_from(nodes, reset_pos=True)[source]

Remove a list of nodes from the Reeb graph.

Parameters:
  • nodes (list) – The list of node names to remove.

  • reset_pos (bool, optional) – If True, will reset the positions of the nodes based on the function values.

add_edge(u, v, reset_pos=True)[source]

Add an edge to the Reeb graph. Make sure that the edge points to the vertex with higher function value.

Note that if the edge added is between two vertices with the same function value, it will collapse the two vertices into one.

Parameters:
  • u – The edge to add.

  • v – The edge to add.

  • reset_pos (bool) – Optional. If True, will reset the positions of the nodes based on the function values.

add_edges_from(edges, reset_pos=True)[source]

Add a list of edges to the Reeb graph.

Parameters:
  • edges (list) – The list of edges to add.

  • reset_pos (bool) – Optional. If True, will reset the positions of the nodes based on the function values.

subdivide_edge(u, v, w, f_w)[source]

Subdivide an edge with a new vertex.

Parameters:
  • u – The edge to subdivide.

  • v – The edge to subdivide.

  • w – The new vertex to add.

  • f_w – The function value of the new vertex.

remove_regular_vertex(v)[source]

Remove a regular vertex from the Reeb graph. A regular vertex is one for which down degree = up degree = 1, so it can be removed and replaed with a single edge.

Parameters:

v (int) – The vertex to remove.

remove_all_regular_vertices()[source]

Remove all regular vertices from the Reeb graph.

remove_isolates()[source]

Remove all isolated vertices from the Reeb graph.

set_pos_from_f(seed=None, verbose=False)[source]

Set the position of the nodes based on the function values. The result will be the (spring layout x, function value y). Note that this will overwrite the previous positions.

Parameters:

verbose (bool) – Optional. If True, will print out the function values and the positions.

draw(with_labels=True, with_colorbar=False, cpx=0.1)[source]

A drawing of the Reeb graph. Uses the fancy version from cereeberus.compute.draw.

Parameters:
  • with_labels (bool) – Optional. If True, will include the labels of the nodes.

  • cpx (float) – Optional. A parameter that controls “loopiness” of multiedges in the drawing.

Returns:

None

induced_subgraph(nodes)[source]

Returns the subgraph of the Reeb graph induced by the nodes in the list nodes.

Parameters:

nodes (list) – The list of nodes to include in the subgraph.

Returns:

The subgraph of the Reeb graph induced by the nodes in the list nodes.

Return type:

ReebGraph

slice(a, b, verbose=False)[source]

Returns the subgraph of the Reeb graph with image in the open interval (a,b). This will convert any edges that cross the slice into vertices.

Parameters:
  • a (float) – The lower bound of the slice.

  • b (float) – The upper bound of the slice.

Returns:

The subgraph of the Reeb graph with image in (a,b).

Return type:

ReebGraph

connected_components()[source]

Returns the connected components of the Reeb graph by providing a set of vertices for each connected component. If you want to actually get the subgraphs of ReebGraph R returned as Reeb graphs, you can use:

[R.induced_subgraph(component) for component in R.connected_components()]
Returns:

A generator of sets of nodes, one for each component of the Reeb graph.

get_largest_component()[source]

Returns the largest connected component of the Reeb graph as a set of nodes. Note: this is not well defined unless the Reeb graph is minimal.

Returns:

The largest connected component of the Reeb graph based on number of vertices.

Return type:

ReebGraph

to_mapper(delta=None)[source]

Convert the Reeb graph to a Mapper graph as long as all function values are integers. Note this is NOT the same as computing the mapper graph of a given Reeb graph as the input topological space. This will create a new Mapper graph object with the same nodes and edges as the Reeb graph.

Parameters:

delta (float) – Optional. The delta value to use for the Mapper graph. If None, will use 1.

Returns:

The Mapper graph representation of the Reeb graph.

Return type:

MapperGraph