Skip to main content

TMVBeta

Truncated Multivariate Beta Distribution on Unit Hypercube

Description

Python implementation of the following distributions

  • Truncated beta distribution
  • Truncated multivariate normal distribution
  • Truncated multivariate beta distribution on unit hypercube

All distributions support common methods, such as, pdf, cdf, logpdf, etc. In addition, convenient methods are provided to

  • efficiently draw samples
  • estimate parameters using maximum likelihood based on homogeneously or heterogeneously truncated samples

Maximum likelihood estimation is performed using a grid-restrained version of the Nelder-Mead algorithm, which is guarantee to converge to a stationary point. See the documentation in src/tmvbeta/tmvbeta.py for details.

Implementation Details

There is no unique definition of the multivariate beta distribution on the hypercube. The distribution implemented here is generated from a standard normal distribution via a Gaussian copula: $$ \boldsymbol{X} = F_{\boldsymbol{\alpha}, \boldsymbol{\beta}}^{-1} \bigl( \Phi(\boldsymbol{Z}) \bigr), \quad \text{with} \quad \boldsymbol{Z} = \mathcal{N}(\boldsymbol{0}, \boldsymbol{\Sigma}), $$ where $F_{\alpha, \beta}$ and $\Phi$ denote the CDF of the beta distribution and the standard normal distribution, respectively, and the covariance matrix of $\boldsymbol{Z}$ has ones on its diagonal, $[\boldsymbol{\Sigma}]_{ii} = 1$

Acknowledgment

The library uses Paul Brunzema's implementation of the minimax tilting algorithm in Botev (2016) for sampling.

Installation

TMVBeta is available on PyPI and can be installed, for example, using pip:

pip install tmvbeta

Getting Started

Three examples of how to use the distributions in this library are given below. For more details see the documentation in src/tmvbeta/tmvbeta.py.

  1. Sample from beta distribution truncated to interval $[0.2, 0.75]$, and estimate parameters from the sample:
from tmvbeta import TBeta

# parameters
a, b = 2, 4
x_min, x_max = 0.2, 0.75

# initialize distribution
tbeta = TBeta(a, b, x_min, x_max)

# generate sample
x = tbeta.rvs(size=100)

# estimate parameters
tbeta.fit(x)

# print estimated parameters
print(tbeta.a, tbeta.b)
  1. Sample from 2D standard normal distribution truncated to rectangle $[-1, 2]^2$, and estimate parameters from the sample:
import numpy as np
from tmvbeta import TMVNormal

# parameters
mean = np.zeros(2)
cov = np.eye(2)
x_min = np.full(-1, 2)
x_max = np.full(2, 2)

# initialize distribution
tmvnorm = TMVNormal(a, b, x_min, x_max)

# generate sample
x = tmvnorm.rvs(size=100)

# estimate parameters
tmvnorm.fit(x)

# print estimated parameters
print(tmvnorm.mean, tmvnorm.cov)
  1. Sample from 2D beta distribution on hypercube truncated to rectangle $[0.1, 0.9]^2$, and estimate parameters from the sample:
import numpy as np
from tmvbeta import TMVBeta

# parameters
a = np.full(2, 2)
b = np.full(4, 2)
cov = np.eye(2)
x_min = np.full(0.1, 2)
x_max = np.full(0.9, 2)

# initialize distribution
tmvbeta = TMVBeta(a, b, cov, x_min, x_max)

# generate sample
x = tmvbeta.rvs(size=100)

# estimate parameters
tmvbeta.fit(x)

# print estimated parameters
print(tmvbeta.a, tmvbeta.b, tmvbeta.cov)

Metadata

Release files for tmvbeta 1.0.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 tmvbeta 1.0.1
File Size Uploaded
tmvbeta-1.0.1.tar.gz 14.0 kB Details

Built distribution (wheel)

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

Total release size: 25.4 kB

Release files / tmvbeta-1.0.1.tar.gz

Download URL tmvbeta-1.0.1.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
84982979909edc2431e07b6ca380d00e54fa4ffae31906ab2a9e61cbb4d0ed9d
BLAKE2b-256 checksum
How to use checksums
e1a660cf7b30d4e8b74ec7e5a21a4d7bbfdce052e4a77e3f64b0c9f4d2b1a160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / tmvbeta-1.0.1-py3-none-any.whl

Download URL tmvbeta-1.0.1-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
790a325edc33335192075713f5dda6d53ffa0f593222c64843a143b62c2b1621
BLAKE2b-256 checksum
How to use checksums
feb641c674ad9c379b60a9d845333d049e104cbcd8c6ddbb7b3df7da2f7723d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

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