Skip to main content

This package serves as a computational framework for Bézier distributions.

Project description

bezierv logo

bezierv

Fit smooth Bézier random variables to empirical data

PyPI Python License Docs CI


Why Bézier Random Variables?

Traditional parametric distributions (normal, exponential, etc.) can be too rigid for real-world data. bezierv bridges the gap between non-parametric and parametric approaches by using Bézier curves to create smooth, flexible distributions that can fit virtually any shape.

Key advantages:

  • 📈 Flexible: Fit any continuous distribution shape
  • 🎛️ Controllable: Intuitive control points for fine-tuning
  • 🔄 Composable: Built-in convolution for sums of random variables
  • Fast: Multiple efficient fitting algorithms
  • 🎨 Visual: Interactive tools for exploration

Quick Start

Installation

pip install bezierv

Basic Usage

import numpy as np
from bezierv import DistFit

# Generate or load your data
rng = np.random.default_rng(42)
data = rng.beta(2, 5, 1000)  # Example: skewed data

# Fit a Bézier distribution (MSE objective, projected-gradient solver)
fitter = DistFit(data, n=5)  # 5 control segments
bezier_rv, mse = fitter.fit(method='mse', algorithm='projected_gradient')

# Use the fitted distribution
samples = bezier_rv.random(10000)      # Generate new samples
q90 = bezier_rv.quantile(0.90)         # 90th percentile
mean = bezier_rv.mean()            # Distribution mean
prob = bezier_rv.cdf_x(0.5)            # P(X <= 0.5)

# Visualize the fit
bezier_rv.plot_cdf(data)  # Compare with empirical CDF
bezier_rv.plot_pdf()      # Show probability density

Advanced: Convolution of Random Variables

from bezierv import DistFit, Convolver

# Fit two distributions
rv1, _ = DistFit(data1, n=4).fit(method='mse', algorithm='projected_gradient')
rv2, _ = DistFit(data2, n=4).fit(method='mse', algorithm='projected_gradient')

# Compute their sum: Z = X + Y
convolver = Convolver([rv1, rv2])
sum_mc, _ = convolver.convolve(n_sims=10000, rng=42)

Documentation

Resource Description
📖 User Guide Complete tutorials and examples
🔧 API Reference Detailed function documentation
🎮 Interactive Demo Browser-based curve editor
📚 Tutorials Step-by-step examples and guides

Interactive Tool

Launch an interactive Bézier curve editor in your browser:

from bezierv.classes.bezierv import InteractiveBezierv
from bokeh.plotting import curdoc

# Create interactive editor
editor = InteractiveBezierv(
    controls_x=[0.0, 0.25, 0.75, 1.0],
    controls_z=[0.0, 0.1, 0.9, 1.0]
)

curdoc().add_root(editor.layout)

Then run: bokeh serve --show your_app.py


Algorithms

bezierv includes multiple fitting algorithms optimized for different scenarios:

Objective Algorithm Call
MSE Projected Gradient method='mse', algorithm='projected_gradient'
MSE Solver (IPOPT) method='mse', algorithm='solver'
MSE Nelder-Mead method='mse', algorithm='nelder_mead'
MLE Primal Gradient method='mle'

method='mse' returns (bezierv, mse). method='mle' returns (bezierv, nll).

Citation

If you use bezierv in your research, please cite the accompanying paper (forthcoming on arXiv):

@article{leiva2026bezierv,
  title   = {Computational Framework for {B\'{e}zier} Distributions},
  author  = {Leiva, Esteban and Medaglia, Andr\'{e}s L. and Zuluaga, Luis F.},
  year    = {2026},
  note    = {Forthcoming on arXiv}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distribution

bezierv-1.3.1.tar.gz (855.1 kB view details)

Uploaded Source

Built Distribution

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

bezierv-1.3.1-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file bezierv-1.3.1.tar.gz.

File metadata

  • Download URL: bezierv-1.3.1.tar.gz
  • Upload date:
  • Size: 855.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for bezierv-1.3.1.tar.gz
Algorithm Hash digest
SHA256 97a72a437e531b915ca6c948f1c0183f3a9708a57855af87d8ec228089f38fb1
MD5 239d14e74422f1bfef251a4bf5e694ef
BLAKE2b-256 e5aaad048922e665c77ffe7046ba9a61ea3014a249789eda8f48dbd28e326b1f

See more details on using hashes here.

File details

Details for the file bezierv-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: bezierv-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for bezierv-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a775bd6804eb7e43e5d740fe99aeffdd6291125222dcd93f4446788c6bc3f72d
MD5 79394e0b72092272887e047dd206151d
BLAKE2b-256 d009b5414c7561749d454f2f58f477339b222e0ab191ef0c30280c0485ef078b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page