pytspl
This module is the main module of the library.
It imports all the necessary modules and classes to be used by the user.
Subpackages
Attributes
Classes
Class for plotting simplicial complexes. |
Functions
|
Generate a random simplicial complex. |
|
List the available datasets. |
|
Load the dataset and return the simplicial complex |
|
Read the B1 and B2 incidence matrices. |
|
Read a csv file and returns a graph. |
|
Read a tntp file and returns a graph. |
Package Contents
- pytspl.__version__ = '0.1.5'
- pytspl.generate_random_simplicial_complex(num_of_nodes: int, p: float, dist_threshold: float, seed: int) tuple[source]
Generate a random simplicial complex.
- Args:
num_of_nodes (int): Number of nodes in the graph. p (float): Probability of edge creation. dist_threshold (float): Threshold for simplicial complex construction. seed (int): Seed for random number generator.
- Returns:
SimplicialComplex: The generated simplicial complex. dict: The coordinates of the nodes.
- pytspl.list_datasets() list[source]
List the available datasets.
- Returns:
list: The list of available datasets.
- pytspl.load_dataset(dataset: str) tuple[source]
Load the dataset and return the simplicial complex and coordinates.
- Args:
dataset (str): The name of the dataset.
- ValueError:
If the dataset is not found.
- Returns:
SimplicialComplex: The simplicial complex of the dataset. dict: The coordinates of the nodes. If the coordinates do not exist, the coordinates are generated using spring layout. dict: The flow data of the dataset. If the flow data does not exist, an empty dictionary is returned.
- pytspl.read_B1_B2(B1_filename: str, B2_filename: str) tuple[source]
Read the B1 and B2 incidence matrices.
- Args:
B1_filename (str): The name of the B1 incidence matrix file. B2_filename (str): The name of the B2 incidence matrix file.
- Returns:
SCBuilder: SC builder object to build the simplicial complex. list: List of triangles (2-simplices).
- pytspl.read_csv(filename: str, delimiter: str, src_col: str, dest_col: str, feature_cols: list = None, start_index_zero: bool = True) pytspl.simplicial_complex.scbuilder.SCBuilder[source]
Read a csv file and returns a graph.
- Args:
filename (str): The name of the csv file. delimiter (str): The delimiter used in the csv file. src_col (str): The name of the column containing the source nodes. dest_col (str): The name of the column containing the destination nodes. feature_cols (list, optional): The names of the feature columns. Defaults to None. start_index_zero (bool): True, if the node ids start from 0. False,
- Returns:
SCBuilder: SC builder object to build the simplicial complex.
- pytspl.read_tntp(filename: str, src_col: str, dest_col: str, skip_rows: int, delimiter: str = '\t', start_index_zero: bool = True) pytspl.simplicial_complex.scbuilder.SCBuilder[source]
Read a tntp file and returns a graph.
- Args:
filename (str): The name of the tntp file. src_col (str): The name of the column containing the source nodes. dest_col (str): The name of the column containing the destination nodes. skip_rows (int): The number of (metadata) rows to skip in the tntp file. delimiter (str): The delimiter used in the tntp file. Defaults to next line. start_index_zero (bool): True, if the node ids start from 0. False, if the node ids start from 1.
- Returns:
SCBuilder: SC builder object to build the simplicial complex.
- class pytspl.SCPlot(simplicial_complex: pytspl.simplicial_complex.SimplicialComplex, coordinates: dict = None)[source]
Class for plotting simplicial complexes.
- sc
- pos
- _init_axes(ax) dict[source]
Initialize the axes for the plot. The axis limits are set to the bounding box of the nodes.
- Args:
ax (matplotlib.axes.Axes): The axes object.
- Returns:
dict: The layout of the nodes.
- create_edge_flow(flow: numpy.ndarray) dict[source]
Create a dictionary of edge flows from the flow array.
- Args:
flow (np.ndarray): The flow on the edges.
- Returns:
dict: The edge flow dictionary.
- draw_sc_nodes(node_size: int = 300, node_color: str = '#ff7f0e', node_edge_colors: str = 'black', font_size: float = 12, font_color: str = 'k', font_weight: str = 'normal', cmap=plt.cm.Blues, vmin=None, vmax=None, alpha: float = 0.8, margins=None, with_labels: bool = False, ax=None) None[source]
Draw the nodes of the simplicial complex.
- Args:
node_size (int, optional): The size of the nodes. Defaults to 300. node_color (str, optional): The color of the nodes. Defaults to ‘#ff7f0e’. node_edge_colors (str, optional): The color of the node edges. Defaults to ‘black’. font_size (float, optional): The font size of the node labels. Defaults to 12. font_color (str, optional): The color of the node labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the node labels. Defaults to ‘normal’. cmap (mpl.colors.Colormap, optional): The color map. Defaults to plt.cm.Blues. vmin (float, optional): The minimum value for the color map. Defaults to None. vmax (float, optional): The maximum value for the color map. Defaults to None. alpha (float, optional): The transparency of the nodes. Defaults to 0.8. margins (float, optional): The margins of the plot. Defaults to None. with_labels (bool, optional): Whether to show the node labels. Defaults to False. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.
- _draw_node_labels(font_size: float = 12, font_color: str = 'k', font_weight: str = 'normal', alpha=None) None[source]
Draw the labels of the nodes.
- Args:
font_size (float, optional): The font size of the node labels. Defaults to 12. font_color (str, optional): The color of the node labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the node labels. Defaults to ‘normal’. alpha (float, optional): The transparency of the node labels. Defaults to None.
- draw_sc_edges(edge_flow: dict = None, edge_color: str = 'lightblue', edge_width: float = 1.0, arrowsize: int = 10, edge_cmap=plt.cm.Blues, edge_vmin=None, edge_vmax=None, directed: bool = True, alpha: float = 0.8, ax=None) None[source]
Draw the edges of the simplicial complex.
- Args:
edge_flow (dict, optional): The flow of the edges. e.g. {(0, 1): 0.5, (1, 2): 0.3, (2, 0): 0.2}. Defaults to None. edge_color (str, optional): The color of the edges. Defaults to ‘lightblue’. edge_width (float, optional): The width of the edges. Defaults to 1.0. arrowsize (int, optional): The size of the arrows. Defaults to 10. edge_cmap (mpl.colors.Colormap, optional): The color map of the edges. Defaults to plt.cm.Blues. edge_vmin (float, optional): The minimum value for the color map. Defaults to None. edge_vmax (float, optional): The maximum value for the color map. Defaults to None. directed (bool, optional): Whether the edges are directed. Defaults to True. alpha (float, optional): The transparency of the edges. Defaults to 0.8. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.
- _calculate_edge_label_position(src: tuple, dest: tuple, offset: float) tuple[source]
Calculate the position of the edge label based on the edge position.
- draw_edge_labels(edge_labels: dict, font_size: int = 10, font_color: str = 'k', font_weight: str = 'normal', offset=0.15, alpha=None, ax=None) dict[source]
Draw the labels (flow) of the edges.
- Args:
edge_labels (dict): The labels of the edges. e.g. {(0, 1): 0.5, (1, 2): 0.3, (2, 0): 0.2} Defaults to None. font_size (int, optional): The font size of the labels. Defaults to 10. font_color (str, optional): The color of the labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the labels. Defaults to ‘normal’. offset (float, optional): The offset of the labels from the center of the edge. Defaults to 0.15. alpha (float, optional): The transparency of the labels. Defaults to None. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.
- draw_network(edge_flow=None, directed: bool = True, with_labels: bool = True, ax=None, **kwargs) None[source]
Draw the simplicial complex network with edge flow. If the flow is not provided, the network is drawn without flow.
- Args:
edge_flow (dict, np.ndarray, list, optional): The labels of the edges. e.g. {(0, 1): 0.5, (1, 2): 0.3, (2, 0): 0.2}. You can also provide a numpy array of the flow. Defaults to None. directed (bool, optional): Whether the edges are directed. Defaults to True. with_labels (bool, optional): Whether to show the node labels. Defaults to True. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.
- Node kwargs:
node_size (int, optional): The size of the nodes. Defaults to 300. node_color (str, optional): The color of the nodes. Defaults to ‘#ff7f0e’. node_edge_colors (str, optional): The color of the node edges. Defaults to ‘black’. font_size (float, optional): The font size of the node labels. Defaults to 12. font_color (str, optional): The color of the node labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the node labels. Defaults to ‘normal’. cmap (mpl.colors.Colormap, optional): The color map. Defaults to plt.cm.Blues. vmin (float, optional): The minimum value for the color map. Defaults to None. vmax (float, optional): The maximum value for the color map. Defaults to None. alpha (float, optional): The transparency of the nodes. Defaults to 0.8. margins (float, optional): The margins of the plot. Defaults to None.
- Edge kwargs:
edge_color (str, optional): The color of the edges. Defaults to ‘lightblue’. edge_width (float, optional): The width of the edges. Defaults to 1.0. arrowsize (int, optional): The size of the arrows. Defaults to 10. edge_cmap (mpl.colors.Colormap, optional): The color map of the edges. Defaults to plt.cm.Blues. edge_vmin (float, optional): The minimum value for the color map. Defaults to None. edge_vmax (float, optional): The maximum value for the color map. Defaults to None. directed (bool, optional): Whether the edges are directed. Defaults to True. alpha (float, optional): The transparency of the edges. Defaults to 0.8.
- Edge label kwargs:
font_size (int, optional): The font size of the labels. Defaults to 10. font_color (str, optional): The color of the labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the labels. Defaults to ‘normal’. offset (float, optional): The offset of the labels from the center of the edge. Defaults to 0.15. alpha (float, optional): The transparency of the labels. Defaults to None.
- draw_hodge_decomposition(flow: numpy.ndarray, component=None, round_fig: bool = True, round_sig_fig: int = 2, figsize=(15, 5), font_dict={'fontsize': 20}) None[source]
Draw the Hodge decomposition of the flow.
- Args:
flow (np.ndarray): The flow on the edges. component (str, optional): The component of the flow to draw. If None, all three components are drawn. Defaults to None. round_fig (bool, optional): Whether to round the figures. Defaults to True. round_sig_fig (int, optional): The number of significant figures to round to. Defaults to 2. figsize (tuple, optional): The size of the figure. Defaults to (15, 5). font_dict (dict, optional): The font dictionary. Defaults to {“fontsize”: 20}.
- Raises:
ValueError: If an invalid component is provided.
- draw_eigenvectors(component: str, eigenvector_indices: numpy.ndarray = [], round_fig: bool = True, round_sig_fig: int = 2, with_labels: bool = True, figsize=(15, 5), font_dict={'fontsize': 20})[source]
Draw the eigenvectors for the given component and eigenvalue indices using eigendecomposition.
- Args:
component (str): The component of the eigenvectors to draw. eigenvector_indices (np.ndarray, optional): The indices of the eigenvectors to draw. Defaults to []. round_fig (bool, optional): Whether to round the figures. Defaults to True. round_sig_fig (int, optional): The number of significant figures to round to. Defaults to 2. with_labels (bool, optional): Whether to show the node labels. Defaults to True. figsize (tuple, optional): The size of the figure. Defaults to (15, 5). font_dict (dict, optional): The font dictionary. Defaults to {“fontsize”: 20}.