OPForch: PyTorch Optimum-Path Forest Classifiers
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fe8e55e82c08e6ca5894ca9d0c3d1c3746bc080b871a9f93333ef421288647e
|
|
| MD5 |
e850b6813061bef7ba4763a975b1ab64
|
|
| BLAKE2b-256 |
71161f5683816b205449e39490814a14fb1c6473828bb8f7bfbb1a67020606e3
|
Provenance
The following attestation bundles were made for opforch-2.1.0.tar.gz:
Publisher:
build-publish-to-pypi.yml on gugarosa/opforch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opforch-2.1.0.tar.gz -
Subject digest:
8fe8e55e82c08e6ca5894ca9d0c3d1c3746bc080b871a9f93333ef421288647e - Sigstore transparency entry: 2677809384
- Sigstore integration time:
-
Permalink:
gugarosa/opforch@ac8c968d3427d4c7f9d215e509abe6a155607697 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/gugarosa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-publish-to-pypi.yml@ac8c968d3427d4c7f9d215e509abe6a155607697 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4d73b5d5c01089da1d39950abfc831e6f7a57bb31a09aad82fd1f863e67e177
|
|
| MD5 |
4cd73f205b66e9010eb00f50e0d6bf16
|
|
| BLAKE2b-256 |
3f1e7a497564c6c5abb9f3f107d10c98da6482e4f12f49d3c37d5d17ac82e160
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opforch-2.1.0-py3-none-any.whl -
Subject digest:
f4d73b5d5c01089da1d39950abfc831e6f7a57bb31a09aad82fd1f863e67e177 - Sigstore transparency entry: 2677809454
- Sigstore integration time:
-
Permalink:
gugarosa/opforch@ac8c968d3427d4c7f9d215e509abe6a155607697 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/gugarosa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-publish-to-pypi.yml@ac8c968d3427d4c7f9d215e509abe6a155607697 -
Trigger Event:
release
-
Statement type: