3.5. Torus Lower Star Simplicial Complex

This module contains the Torus class, which generates a simplicial complex representing a torus as an nxn grid, and gives it a lower star filtration. Pictures of these can be seen in this notebook

class cereeberus.data.ex_torus.Torus[source]

Class to create an example torus using the LowerStarSC.

Inherits from:

LowerStarSC: A lower star simplicial complex.

__init__()[source]

Initializes the torus by inserting simplices.

get_vertex_integer(i, j)[source]

Returns the unique integer for the vertex at (i, j).

get_vertex_coordinates(vertex_int)[source]

Returns the (i, j) coordinates for a given vertex integer.

plot()[source]

Plots a flat representation of the torus’s 1-skeleton.

Example

>>> torus = Torus()
>>> torus.generate_grid(grid_size=5)
>>> torus.assign_random_values(0, 10)
>>> torus.plot()
__init__()[source]

Initialize class. Due to SimplexTree C++ weirdness, this does nothing but initialize the instance. Call T.generate_grid(5) to add the content.

generate_grid(grid_size=5)[source]

Initializes a simplicial complex representing a torus. The grid_size is used to generate a mesh with (n-1)x(n-1) vertices. Visually, this could be drawn as a grid of nxn vertices, but where the last row and the last column are matched up.

Parameters:

grid_size (int, optional) – _description_. Defaults to 5, Minimum is 4

get_vertex_integer(i, j)[source]

Returns the unique integer corresponding to the vertex at position (i, j) in the grid.

Parameters:
  • i (int) – Row index.

  • j (int) – Column index.

Returns:

Unique integer representing the vertex.

Return type:

int

get_vertex_coordinates(vertex_int)[source]

Returns the (i, j) coordinates of a vertex given its unique integer.

Parameters:

vertex_int (int) – Unique integer representing the vertex.

Returns:

(i, j) coordinates of the vertex.

Return type:

tuple

assign_filtration(vertex, value)[source]

Sets the filtration value for a given vertex. Vertex can be provided either as an integer, as a single integer in a list representing the integer label of the vertex, or as (i, j) coordinates for the grid structure of the torus.

Parameters:
  • vertex (Union[int, tuple]) – Unique integer representing the vertex or (i, j) coordinates.

  • value (float) – Filtration value to set.

plot(ax=None, cmap=<matplotlib.colors.ListedColormap object>, **kwargs)[source]

Gives a flat plot of the torus’s 1-skeleton using matplotlib.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure and axes are created. Defaults to None.

  • cmap (matplotlib.colors.Colormap, optional) – Colormap to use for vertex colors based on filtration values. Defaults to plt.cm.viridis.

  • **kwargs – Additional keyword arguments passed to plt.scatter for vertex plotting.