Truncated multivariate beta distribution on unit hypercube
Project description
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
.
- 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)
- 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)
- 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tmvbeta-1.0.1.tar.gz
.
File metadata
- Download URL: tmvbeta-1.0.1.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84982979909edc2431e07b6ca380d00e54fa4ffae31906ab2a9e61cbb4d0ed9d |
|
MD5 | b9e0938302aef8c054101aca4494e2ba |
|
BLAKE2b-256 | e1a660cf7b30d4e8b74ec7e5a21a4d7bbfdce052e4a77e3f64b0c9f4d2b1a160 |
File details
Details for the file tmvbeta-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: tmvbeta-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 790a325edc33335192075713f5dda6d53ffa0f593222c64843a143b62c2b1621 |
|
MD5 | 351d6879d8b69355f75e8993c13592d7 |
|
BLAKE2b-256 | feb641c674ad9c379b60a9d845333d049e104cbcd8c6ddbb7b3df7da2f7723d0 |