Skip to main content

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.

Metadata

Release files for cut-pursuit-l2 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cut-pursuit-l2 0.1.2
File Size Uploaded
cut_pursuit_l2-0.1.2.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cut-pursuit-l2 0.1.2
File Interpreter ABI Platform
cut_pursuit_l2-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 42.4 kB

Release files / cut_pursuit_l2-0.1.2.tar.gz

Download URL cut_pursuit_l2-0.1.2.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
de2af5a0e773bc19bb40d9f17f52556f97a31efc589ab6f010ace7a702772c96
BLAKE2b-256 checksum
How to use checksums
ae6d87fa51a4064939073c50c59ebe066bc8ceb786d67dd4062d037d571733c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.5

Release files / cut_pursuit_l2-0.1.2-py3-none-any.whl

Download URL cut_pursuit_l2-0.1.2-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
917f55f429cd07d625ab6e5425621a3517e0682a6ec0841c0ec85fd42049d7c8
BLAKE2b-256 checksum
How to use checksums
631f8d434959515fee891abc9cae0dd5fae4c27ef6bea1ac1dbb12e82cbd0254
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page