Skip to main content

A Python library for Topological Signal Processing and Learning.

Project description

Documentation Status https://img.shields.io/pypi/v/pytspl.svg https://github.com/irtazahashmi/pytspl/actions/workflows/onpush.yml/badge.svg https://codecov.io/gh/irtazahashmi/pytspl/graph/badge.svg?token=7KQ0U8FW70 License https://img.shields.io/badge/python-3.11+-blue?logo=python

The PyTSPL python package is a library for Topological Signal Processing and Learning. It is a free software distributed under the MIT license and available on PyPI. The documentation is available on Read the Docs and development takes place on GitHub.

The primary goal of PyTSPL is to provide a unified and comprehensive toolset for the analysis and visualization of higher-order interactions, currently centered towards simplical complexes (SCs). The functionalities of SCs are scattered and it’s difficult to use multiple functionalities together. By integrating multiple functionalities within a single library and extending them, PyTSPL aims to facilitate research and practical applications in various domains.

Currently, the PyTSPL facilitates the functionalities for SCs but the aim is to extend the library for additional topological learning functionalities.

Simlicial complexes (SC):

  • io: Responsible for reading raw datasets and preprocessing them such that they can be passed on to the next module to build an SC. The raw datasets can be read using the network_reader submodule. The data can be in various formats such as CSV, TNTP or plain incidence matrices B1 and B2. There is additional functionality to read the coordinates and edge flow of the SC as well. Additionally, there is functionality to load built-in datasets using the dataset_loader submodule. Finally, there is also a quick way to generate a random SC using the sc_generator submodule.

  • simplicial_complex: Once the raw data is read using the io module, it is stored in the simplicial_complex data structure. This data structure allows us to compute the algebraic properties of the SC. This includes computing the incidence matrix, adjacency matrix, Laplacian matrices and many others. It also allows for the computation of k-step lower and upper shifting and simplical embeddings of the SC.

  • plot: Offers the functionality to plot an SC in a quick and meaningful way. The user can draw the entire network or draw nodes, edges, and their respective labels in a custom way that meets their needs. The plots are drawn using the provided network coordinates. If the coordinates are not provided or don’t exist, the module automatically generates coordinates using NetworkX’s spring_layout.

  • decomposition: Offers functionality to decompose signals using eigendecomposition and Hodge decomposition. The eigendecomposition functionality allows users to extract the gradient, harmonic, and curl eigenpairs, whereas the Hodge decomposition allows users to obtain the divergence, curl, total variance of the SC. The gradient, harmonic, and curl flow can also be calculated.

  • filters: This module aims to provide simplicial convolutional filters for the SC, namely, Least-Squares filter, Grid-Based filter, and Chebyshev filter design. The applications for these filters include subcomponent extraction and edge flow denoising. Additionally, the module offers functionality for simplicial trend filtering for reconstructing simplicial signals from (partial) noisy observations.

  • hodge_gp: Hodge-Compositional Edge Gaussian Process is used to model functions defined over the edge set of an SC. This method aims to learn flow-type data on networks where edge flows can be characterized by discrete divergence and curl. This module is built on PyTorch and allows users to directly train their model and make predictions on real-world datasets.

Quick Start

The following demonstrates how to list available datasets and instantiate a SC using a built-in dataset:

>>> from pytspl import list_datasets, load_dataset
>>> print(list_datasets()) # print available datasets
>>> sc, coordinates, flow = load_dataset("paper")
Num. of nodes: 7
Num. of edges: 10
Num. of triangles: 3
Shape: (7, 10, 3)
Max Dimension: 2
Coordinates: 7
Flow: 10

Let’s go ahead and plot the SC using the coordinates:

>>> from pytspl import SCPlot
>>> import matplotlib.pyplot as plt
>>>
>>> scplot = SCPlot(simplical_complex=sc, coordinates=coordinates)
>>>
>>> fig, ax = plt.subplots(figsize=(4, 5))
>>> scplot.draw_network(ax=ax)

We can also plot the edge flow of the SC using:

>>> fig, ax = plt.subplots(figsize=(5, 5))
>>> scplot.draw_network(edge_flow=flow, ax=ax)

Let’s go ahead and load a larger dataset and plot it:

>>> sc, coordinates, flow = load_dataset("chicago-sketch")
>>> scplot = SCPlot(simplical_complex=sc, coordinates=coordinates)
>>> fig, ax = fig, ax = plt.subplots(figsize=(80, 40))
>>> scplot.draw_network(with_labels=False, node_size=200, arrowsize=20, ax=ax)

Installation

The PyTSPL is available on PyPI.

pip install pytspl

Note that you will need a recent version of Python (>=3.10).

To run the library, you will need to install the following dependencies due to the fact that PyPI does not allow for the installation of packages from git repositories:

git clone https://github.com/chebpy/chebpy
git clone https://github.com/pyt-team/TopoNetX
git clone https://github.com/pyt-team/TopoModelX

Contributing

See the guidelines for contributing in CONTRIBUTING.rst.

Acknowledgements

The PyTSPL was started in 2024 as an academic open-source project for research purposes at Delft University of Technology.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytspl-0.1.2.tar.gz (19.5 MB view details)

Uploaded Source

Built Distribution

pytspl-0.1.2-py3-none-any.whl (20.3 MB view details)

Uploaded Python 3

File details

Details for the file pytspl-0.1.2.tar.gz.

File metadata

  • Download URL: pytspl-0.1.2.tar.gz
  • Upload date:
  • Size: 19.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/22.5.0

File hashes

Hashes for pytspl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ddf98c26972c35fb2b8fc23aa2acb0981f9f946476004a7ed29885da42cd83a8
MD5 01c72178f7846d259060b594648e867e
BLAKE2b-256 5cef725a69e95cae8c63044b39032181cee66d5a738fafadf973e09adfcb3512

See more details on using hashes here.

File details

Details for the file pytspl-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pytspl-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/22.5.0

File hashes

Hashes for pytspl-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3bee2187e700ebefee7dac9e3113e6886e425b8e121a559c59d17b3a8eafb428
MD5 edd3ce812165f048ac33146a673eb3b0
BLAKE2b-256 7ca64ab9e0768ee0ecde5fec4d3b21e3bb888970750b6acaaa058fe0a0822599

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page