Skip to main content

A Python library for calculating delta hyperbolicity.

Project description

hypdelta

example workflow

hypdelta is a Python library for calculating delta hyperbolicity of distance matrices using various strategies and computational devices (CPU/GPU). It provides flexibility in choosing the method and device for computation to balance between accuracy and performance.

Features

  • Multiple Strategies: Supports naive, condensed, heuristic, CCL, and cartesian strategies for calculating delta hyperbolicity.
  • Device Flexibility: Can run on both CPU and GPU.
  • Customizable Parameters: Allows for setting parameters like block size, number of tries, and heuristic options.

Installation

To install hypdelta, you can clone the repository and install the requirements:

git clone https://github.com/tnmtvv/hypdelta.git
cd hypdelta
pip install -r requirements.txt

Usage

Here's a basic example to get you started with hypdelta:

import numpy as np
from hypdelta import hypdelta

# Generate a synthetic distance matrix
def generate_synthetic_points(dimensions, num_points):
    points = np.random.rand(num_points, dimensions)
    return points

def build_dist_matrix(data):
    arr_all_dist = []
    for p in data:
        arr_dist = list(
            map(lambda x: 0 if (p == x).all() else np.linalg.norm(p - x), data)
        )
        arr_all_dist.append(arr_dist)
    arr_all_dist = np.asarray(arr_all_dist)
    return arr_all_dist

def generate_dists(dim=100, num_points=100):
    points = generate_synthetic_points(dim, num_points)
    dist_arr = build_dist_matrix(points)
    return dist_arr

distance_matrix = generate_dists(dim=10, num_points=50)

# Calculate delta hyperbolicity using the naive strategy on CPU
delta = hypdelta(distance_matrix, device="cpu", strategy="naive")
print(f"Delta hyperbolicity (naive, CPU): {delta}")

# Calculate delta hyperbolicity using the CCL strategy on GPU
delta = hypdelta(distance_matrix, device="gpu", strategy="CCL", l=0.1)
print(f"Delta hyperbolicity (CCL, GPU): {delta}")

Strategies and Devices

The hypdelta function supports the following strategies:

  • "naive": A straightforward approach to calculate delta hyperbolicity.
  • "condensed": A strategy that uses condensed data representation.
  • "heuristic": A heuristic-based approach for faster computation.
  • "CCL": A strategy using far-away pairs for computation.
  • "cartesian": A strategy that utilizes the cartesian product of pairs.

And the following devices:

  • "cpu": Computation on the CPU.
  • "gpu": Computation on the GPU.

Parameters

  • distance_matrix: The distance matrix for which delta hyperbolicity is to be computed.
  • device: The device to use for computation, can be "cpu" or "gpu".
  • strategy: The strategy to use for computation. Options are "naive", "condensed", "heuristic", "CCL", and "cartesian".
  • l: A parameter for certain strategies like "CCL". Default is 0.05.
  • tries: Number of tries for the "condensed" strategy. Default is 25.
  • heuristic: Whether to use heuristic methods for the "condensed" strategy. Default is True.
  • threadsperblock: The number of threads per block for GPU computation. Default is (16, 16, 4).
  • max_threads: The maximum number of threads to use for GPU computation in the "cartesian" strategy. Default is 1024.
  • max_gpu_mem : The maximum gpu memory in Gb. Used in "cartesian" strategy. Default is 16.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Feel free to explore the repository and experiment with different strategies and devices to find the optimal settings for your use case.

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

hypdelta-0.1.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hypdelta-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

hypdelta-0.1.1-py2.py3-none-any.whl (14.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file hypdelta-0.1.1.tar.gz.

File metadata

  • Download URL: hypdelta-0.1.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.5 Windows/10

File hashes

Hashes for hypdelta-0.1.1.tar.gz
Algorithm Hash digest
SHA256 752059cda2dda51f58ec7a324811227bc144e4dfef3cf2449a43145dccc26a21
MD5 f2dd747ae8e4bedf2357eb4f7f05aa62
BLAKE2b-256 8e590a0d240b688294786b83773170774e33712aa6cbb8c2a9aec2e03891399f

See more details on using hashes here.

File details

Details for the file hypdelta-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hypdelta-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.5 Windows/10

File hashes

Hashes for hypdelta-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc6b461a722d2df378c740c4496680c01ec54acf736cb4652ee7199f91e4053
MD5 7bb96aa9f1b7f34b661e8cf98e11f79f
BLAKE2b-256 cbfb1e67307413f52372749c3de288f19db0028252d01bb0f0a2a3796d88ab2e

See more details on using hashes here.

File details

Details for the file hypdelta-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: hypdelta-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.5 Windows/10

File hashes

Hashes for hypdelta-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fa5a9bf99e4fc71575fd39feec60e3b66753cd199b83327f3da8efc5c5692b31
MD5 e42196a89a4234484cd5b720e839b179
BLAKE2b-256 c9d36d19ccf99d8bfe1c27af6e4ac79bee5c20a2229e019356acfc38b402ee95

See more details on using hashes here.

Supported by

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