Skip to main content

OPFython

PyPI CI Documentation DOI License

OPFython is a Python implementation of the Optimum-Path Forest family of classifiers. It provides supervised, semi-supervised, unsupervised, and KNN-supervised models backed by NumPy and Numba.

This implementation follows LibOPF. Please cite the original LibOPF authors as well as OPFython when using it in research.

OPFython requires Python 3.6.1 or newer.

Installation

uv add opfython

Quick start

import numpy as np

from opfython.models import SupervisedOPF

X_train = np.asarray([[0.0, 0.0], [0.1, 0.2], [1.0, 1.0], [1.1, 0.9]])
Y_train = np.asarray([0, 0, 1, 1])
X_test = np.asarray([[0.05, 0.1], [1.05, 1.0]])

classifier = SupervisedOPF()
classifier.fit(X_train, Y_train)
predictions = classifier.predict(X_test)

Labels must be zero-based and sequential. Pre-computed distance matrices can be supplied through each classifier's pre_computed_distance constructor argument.

Classifiers

Class Purpose
SupervisedOPF Complete-graph supervised classification
KNNSupervisedOPF Supervised classification with learned KNN adjacency
SemiSupervisedOPF Learning from labeled and unlabeled samples
UnsupervisedOPF Density-based clustering and label propagation

The package also includes 47 distance metrics, random generators, OPF evaluation measures, dataset loaders and splitters, package logging and exception helpers, and converters for LibOPF binary datasets.

See the documentation and the examples/applications directory for complete workflows.

Development

uv sync --all-groups
uv run pytest
uv run pre-commit run --all-files
uv run --group docs sphinx-build -W -b html docs docs/_build/html
uv build --no-sources

Citation

@article{rosa2021simpa,
    title = {OPFython: A Python implementation for Optimum-Path Forest},
    author = {Gustavo H. {de Rosa} and Joao P. Papa},
    journal = {Software Impacts},
    pages = {100113},
    year = {2021},
    issn = {2665-9638},
    doi = {https://doi.org/10.1016/j.simpa.2021.100113}
}
@misc{rosa2021speedup,
    title = {Speeding Up OPFython with Numba},
    author = {Gustavo H. de Rosa and Joao Paulo Papa},
    year = {2021},
    eprint = {2106.11828},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG}
}

OPFython is licensed under the Apache License 2.0.

Release files for opfython 1.0.15

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

Source distribution (sdist)

Source distribution for opfython 1.0.15
File Size Uploaded
opfython-1.0.15.tar.gz 26.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opfython 1.0.15
File Interpreter ABI Platform
opfython-1.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 62.8 kB

Release files / opfython-1.0.15.tar.gz

Download URL opfython-1.0.15.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cfcbabf9980a69a764246c55d1b39a666653475abd48bd35f3541329e673f4ab
BLAKE2b-256 checksum
How to use checksums
34d015742f4693ee8153fb0c8e0545fe678667d12d8a78c7dbdc7858a6ca7b02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / opfython-1.0.15-py3-none-any.whl

Download URL opfython-1.0.15-py3-none-any.whl
Size 36.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ac21af4a5a9a0e72de834767a701dc8995209db1107a8932eb54e69bfa2e343
BLAKE2b-256 checksum
How to use checksums
4153904339ff1ffc2a7ac1f7766421402c0b303c87afc2e1703fe94b4235efbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

This release

1.0.15 This release

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

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