Skip to main content

A Python implementation of the Cut Pursuit algorithm for graph optimization

Project description

Cut Pursuit with L2 Norm

A Python implementation of the Cut Pursuit algorithm using L2 norm for graph optimization problems. This package provides working tools for graph partitioning using max-flow/min-cut optimization. While inspired by the original C++ version , this implementation is not an exact replica but more focused on speed optimization.

Some parameters such as the cut-off threshold are discarded for simplicity. For the original C++ implementation of the Cut Pursuit algorithm, please refer to the cut-pursuit repository.

Several max-flow libraries have been evaluated, including PyMaxflow, SciPy's sparse module, NetworkX, and iGraph. Among these, PyMaxflow demonstrated the fastest performance. Notably, NetworkX offers CUDA support via RAPIDS and cuGraph; however, as of now, max-flow integration is lacking, and Windows support is limited.

The Cut Pursuit algorithm provides robust point clustering that preserves cluster shapes and edges, as demonstrated below:

Cut Pursuit Clustering Example

Installation

You can install the package via pip:

pip install cut-pursuit-l2

Or install directly from GitHub:

pip install git+https://github.com/truebelief/CutPursuit.git

Requirements

  • Python >=3.7
  • NumPy <2.0.0
  • SciPy
  • PyMaxflow

Basic Usage

Here's a simple example of how to use the Cut Pursuit algorithm:

import numpy as np
from cut_pursuit import perform_cut_pursuit

# Generate sample point cloud data
points = np.random.rand(1000, 3)

# Set parameters
K = 4  # number of nearest neighbors
lambda_ = 1.0  # regularization strength

# Run Cut Pursuit
components = perform_cut_pursuit(K, lambda_, points)

Advanced Usage

For more control over the algorithm, you can use the CutPursuit class directly:

from cut_pursuit import CutPursuit, CPParameter

# Create instance
cp = CutPursuit(n_vertices=1000)

# Set custom parameters
cp.set_parameters(
    flow_steps=4,
    max_ite_main=20,
    stopping_ratio=0.001,
    reg_strenth=1.0
)

# Run optimization
energy_values, computation_times = cp.run()

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

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

cut_pursuit_l2-0.1.2.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

cut_pursuit_l2-0.1.2-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cut_pursuit_l2-0.1.2.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for cut_pursuit_l2-0.1.2.tar.gz
Algorithm Hash digest
SHA256 de2af5a0e773bc19bb40d9f17f52556f97a31efc589ab6f010ace7a702772c96
MD5 7a6114b18e483216799c808c210323eb
BLAKE2b-256 ae6d87fa51a4064939073c50c59ebe066bc8ceb786d67dd4062d037d571733c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cut_pursuit_l2-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for cut_pursuit_l2-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 917f55f429cd07d625ab6e5425621a3517e0682a6ec0841c0ec85fd42049d7c8
MD5 9e8f1c52489c491d85cebf80a9205b52
BLAKE2b-256 631f8d434959515fee891abc9cae0dd5fae4c27ef6bea1ac1dbb12e82cbd0254

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