Skip to main content

OPForch: PyTorch Optimum-Path Forest Classifiers

Latest release CI License

OPForch implements Optimum-Path Forest classifiers with PyTorch tensors for CPU and CUDA execution. It is a tensor-first successor to OPFython and retains the familiar OPF training, prediction, persistence, distance, streaming, and conversion APIs.

Installation

OPForch requires Python 3.8 or newer and PyTorch 2.0 or newer.

pip install opforch

For development:

git clone https://github.com/gugarosa/opforch.git
cd opforch
uv sync --locked

Quick start

from opforch.models import SupervisedOPF
from opforch.stream import loader, parser, splitter

data = loader.load_txt("data/boat.txt")
X, Y = parser.parse_loader(data)
X_train, X_test, Y_train, Y_test = splitter.split(X, Y)

model = SupervisedOPF(distance="log_squared_euclidean")
model.fit(X_train, Y_train)
predictions = model.predict(X_test)

Select a CUDA device through the existing device argument:

model = SupervisedOPF(distance="euclidean", device="cuda:0")

Classifiers

Classifier Description
SupervisedOPF MST-based prototype detection and cost competition
KNNSupervisedOPF k-NN density clustering with validation-driven k selection
SemiSupervisedOPF Labeled and unlabeled sample propagation
UnsupervisedOPF Density clustering with normalized-cut selection

All classifiers retain fit(), predict(), save(), and load() support. The package also includes 47 distance metrics, OPF data loaders and converters, train/test split helpers, tensor-backed subgraphs, and the public DeviceManager API.

See examples/applications for complete classifier workflows.

Development

uv run pytest
uv run pre-commit run --all-files
uv build

Citation

If you use OPForch, please also cite the original LibOPF authors:

J. P. Papa, A. X. Falcão and C. T. N. Suzuki.
Supervised Pattern Classification based on Optimum-Path Forest.
International Journal of Imaging Systems and Technology (2009).

Support

Open an issue for bug reports, questions, and suggestions.

Download files

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

Source Distribution

opforch-2.1.0.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

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

opforch-2.1.0-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file opforch-2.1.0.tar.gz.

File metadata

  • Download URL: opforch-2.1.0.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for opforch-2.1.0.tar.gz
Algorithm Hash digest
SHA256 8fe8e55e82c08e6ca5894ca9d0c3d1c3746bc080b871a9f93333ef421288647e
MD5 e850b6813061bef7ba4763a975b1ab64
BLAKE2b-256 71161f5683816b205449e39490814a14fb1c6473828bb8f7bfbb1a67020606e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for opforch-2.1.0.tar.gz:

Publisher: build-publish-to-pypi.yml on gugarosa/opforch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opforch-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: opforch-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for opforch-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d73b5d5c01089da1d39950abfc831e6f7a57bb31a09aad82fd1f863e67e177
MD5 4cd73f205b66e9010eb00f50e0d6bf16
BLAKE2b-256 3f1e7a497564c6c5abb9f3f107d10c98da6482e4f12f49d3c37d5d17ac82e160

See more details on using hashes here.

Provenance

The following attestation bundles were made for opforch-2.1.0-py3-none-any.whl:

Publisher: build-publish-to-pypi.yml on gugarosa/opforch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 files

2.0.0

2 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