Skip to main content

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.

Metadata

Release files for bezierv 1.3.1

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

Source distribution (sdist)

Source distribution for bezierv 1.3.1
File Size Uploaded
bezierv-1.3.1.tar.gz 855.1 kB Details

Built distribution (wheel)

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

Total release size: 886.7 kB

Release files / bezierv-1.3.1.tar.gz

Download URL bezierv-1.3.1.tar.gz
Size 855.1 kB
Tags Source
SHA-256 checksum
How to use checksums
97a72a437e531b915ca6c948f1c0183f3a9708a57855af87d8ec228089f38fb1
BLAKE2b-256 checksum
How to use checksums
e5aaad048922e665c77ffe7046ba9a61ea3014a249789eda8f48dbd28e326b1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / bezierv-1.3.1-py3-none-any.whl

Download URL bezierv-1.3.1-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a775bd6804eb7e43e5d740fe99aeffdd6291125222dcd93f4446788c6bc3f72d
BLAKE2b-256 checksum
How to use checksums
d009b5414c7561749d454f2f58f477339b222e0ab191ef0c30280c0485ef078b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.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