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.classes.distfit import DistFit

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

# Fit a Bézier distribution
fitter = DistFit(data, n=5)  # 5 control segments
bezier_rv, mse = fitter.fit(method="projgrad")

# Use the fitted distribution
samples = bezier_rv.random(10000)      # Generate new samples
q90 = bezier_rv.quantile(0.90)         # 90th percentile  
mean = bezier_rv.get_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.classes.convolver import Convolver

# Fit two distributions
rv1 = DistFit(data1, n=4).fit()[0]
rv2 = DistFit(data2, n=4).fit()[0]

# Compute their sum: Z = X + Y
convolver = Convolver([rv1, rv2])

# Monte Carlo
sum_mc = convolver.convolve(n_sims=10000)

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:

Algorithm
projgrad
nonlinear
neldermead

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.0.tar.gz (846.5 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.0-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bezierv-1.3.0.tar.gz
Algorithm Hash digest
SHA256 06dd208b862462dc242b17fa76a2cec2fcee6ed295faa0fa78293045f82cf7a3
MD5 85d12aba988627d5ea49bb50d171e39e
BLAKE2b-256 d7c394d7bfcff907651bda8ae15bd4037f67464b21c6c32fbd94c46d156b23fd

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bezierv-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e101d98756913e1d07be972b5734a7207d0aa7568aec17e6b136a529f5c8aaa6
MD5 9b2104b8ad5a0fd487c2227ed74efd3a
BLAKE2b-256 eebaec8d7dab5d6cb1677fab116d89e0674bc7fd1498e803e136ef59acefbe38

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