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
projsubgrad
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.2.0.tar.gz (844.4 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.2.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bezierv-1.2.0.tar.gz
  • Upload date:
  • Size: 844.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for bezierv-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d2c8b19f761aa94c5acb298a84be004a96534cd43e0c0707f3538d11330c22a3
MD5 2841b99d84958c5cc55c90a006df9eb8
BLAKE2b-256 ac718859745a817d93a607c8b97a1bb2db2aa0fe3c8f828a6401033cec9be8ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bezierv-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for bezierv-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cae6cde083d8c1ce52acff78bae34ff050d0182dd7d65cbdaaeb23ed891f666d
MD5 85d6c16f03a9306537dc486138eaf1d4
BLAKE2b-256 d2d2eba3851720cc6fbf238e5d2dc797fcacc1264fc4912b67f51f94b2d88a65

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