Skip to main content

PyTorch-BSF

PyTorch-BSF — Bézier Simploid Fitting

PyPI Python versions PyTest Documentation codecov License: MIT

Bézier Simploid Fitting in PyTorch.

PyTorch-BSF is a Python library for fitting parametric curves, surfaces and higher-dimensional models to data. It is useful for approximating Pareto fronts in multi-objective optimization, building surrogate response models and interpolating observations on meshes.

A Bézier simplex generalizes a Bézier curve to a simplex, such as a triangle or tetrahedron. A simploid is a product of simplices, allowing domains such as squares and prisms. Cells can also be joined along shared faces. These geometries use the same BezierSpace, BezierModel and regression API.

Documentation · PyPI · Changelog · Issue tracker

Features

  • Regression and point cloud fitting: fit known parameter-response pairs, or estimate unknown coordinates for points on a single Bézier simplex.
  • Controlled geometry: use simplex, product and joined-cell domains, with shared control points, exact fixed controls and quadratic regularization.
  • Interpolation and optimization: construct shape-preserving interpolants on simplicial meshes or optimize coefficients against a differentiable cost.
  • Numerical diagnostics: solve least-squares problems with dense SVD or optional sparse LSMR, and inspect errors, conditioning and termination state.
  • Model evaluation and reuse: cross-validation, degree selection, ensembles, random/Sobol/grid sampling, plotting and versioned model archives.
  • Optional integrations: scikit-learn estimators, Lightning execution and explicit MLflow experiment recording.

Installation

Requires Python 3.10 or later and PyTorch 2.3 or later (below 3.0). Install the package and its core dependencies with:

python -m pip install pytorch-bsf

Add integrations as needed, for example:

python -m pip install 'pytorch-bsf[sparse,plot]'
Extra Provides
sparse SciPy LSMR least-squares solver
plot Matplotlib visualization
sklearn scikit-learn estimator
lightning Lightning execution adapter
mlflow Opt-in experiment recording
all All of the integrations above

Dense fitting and random, Sobol and grid sampling work with the core installation. See the installation guide for details and alternative environments.

Quickstart

Fit the quadratic response y = 4x² from three observations on 0 ≤ x ≤ 1, then predict at two new locations. A segment uses barycentric coordinates [1-x, x]: each row contains two nonnegative weights that sum to one.

import torch
from torch_bsf import BezierSpace, Samples, fit

space = BezierSpace.simplex(dimension=1, degree=2)
parameters = torch.tensor([[1.0, 0.0], [0.5, 0.5], [0.0, 1.0]], dtype=torch.float64)
result = fit(space, Samples(parameters, [[0.0], [1.0], [4.0]]))
result.require_success()

# x = 0.25 and x = 0.75
query = torch.tensor([[0.75, 0.25], [0.25, 0.75]], dtype=torch.float64)
with torch.no_grad():
    print(result.model(query))
# tensor([[0.2500],
#         [2.2500]], dtype=torch.float64)

fit returns a FitResult containing a model, metrics, diagnostics and termination state. require_success() raises if the numerical solve failed. Predictions have shape (n_points, n_outputs); result.model is a PyTorch module supporting automatic differentiation. Core least-squares fitting runs on CPU in float64, with both dense and sparse solvers.

Choose a different entry point when your inputs differ:

Your inputs Entry point Guide
Known parameter coordinates and measured responses fit(space, Samples(...)) Regression
Points with unknown parameter coordinates on a single simplex fit_point_cloud(space, values) Point cloud fitting
An initial model and a differentiable cost function minimize(initial_model, loss, ...) Objective minimization

Command line

The same fitting and prediction operations are available from the CLI. First create params.csv and values.csv using the Quickstart CSV example, then run in the directory containing those files:

python -m torch_bsf fit --params params.csv --values values.csv --degree 2 --save model.bsf
python -m torch_bsf predict --model model.bsf --params params.csv --save predictions.csv

Fitting saves a reusable model archive to model.bsf; prediction writes one output row per parameter row to predictions.csv. Use python -m torch_bsf --help or see the CLI guide for more operations and options.

Documentation

Start at the documentation home and choose the tag matching your installed version under Other Versions. Guide links in this README target development (master) and may describe unreleased changes. Before 1.0, minor releases may include breaking API changes; consult the migration guide when upgrading.

Resource What you will find
Quickstart Python examples, CSV inputs and saved-model prediction
Geometry Bézier simplices and the mathematical background
User guide Domains, solvers, regularization, interpolation, sampling and model selection
Applications Worked examples with reproducible figures
API reference Public classes, functions and arguments
Migration guide Replacements for earlier APIs

Runnable scripts are available in examples. With a repository checkout and Bash, run bash examples/quickstart/run.sh from the repository root for the complete CLI walkthrough.

Contributing and support

Bug reports, documentation improvements and code contributions are welcome. Use the issue tracker for bugs and feature requests; include a minimal reproducer and environment details when reporting a bug. The FAQ covers common usage questions.

See the contributing guide for development setup, running tests and pull request requirements.

Research references

For research using Bézier simplex fitting, cite the relevant methodological papers:

See the bibliography for further background and references for individual methods.

License

PyTorch-BSF is distributed under the MIT License.

Metadata

Release files for pytorch-bsf 0.24.0

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

Source distribution (sdist)

Source distribution for pytorch-bsf 0.24.0
File Size Uploaded Provenance Actions
pytorch_bsf-0.24.0.tar.gz 204.9 kB Without provenance Details for pytorch_bsf-0.24.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytorch-bsf 0.24.0
File Interpreter ABI Platform Actions
pytorch_bsf-0.24.0-py3-none-any.whl Python 3 none any Details for pytorch_bsf-0.24.0-py3-none-any.whl

Total release size: 393.3 kB

Release files / pytorch_bsf-0.24.0.tar.gz

Download URL pytorch_bsf-0.24.0.tar.gz
Size 204.9 kB
Tags Source
SHA-256 checksum
How to use checksums
eccc5c847bb47babb5e2141b6f5aea181ab582d219ab5d4e3c8d94b4a39cd21d
BLAKE2b-256 checksum
How to use checksums
777d692d216b8ebcd795f929b556f6696c921593df79190f40d5490eee8451e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / pytorch_bsf-0.24.0-py3-none-any.whl

Download URL pytorch_bsf-0.24.0-py3-none-any.whl
Size 188.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df888060c9eaf5e6f3d79c999474f5d9be0a19a9617cf3a6c334258667f2fac4
BLAKE2b-256 checksum
How to use checksums
0352ad5b652803a3e942d4aea33c7aec27c24a14c47b2b2ee38fd53f677e777d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for pytorch-bsf 0.24.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.24.0 This release

2 release files No provenance

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