Skip to main content

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} \sim F_{\boldsymbol{\alpha}, \boldsymbol{\beta}}^{-1} \bigl( \Phi(\boldsymbol{Z}) \bigr), \quad \text{with}\quad \boldsymbol{Z} \sim \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)

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

tmvbeta-1.0.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

tmvbeta-1.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file tmvbeta-1.0.0.tar.gz.

File metadata

  • Download URL: tmvbeta-1.0.0.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

Hashes for tmvbeta-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ac2a1bfaf92c8df8a810f25ab8ded5be7af590b282685a7d440932b65fdeb8fa
MD5 d130511a1139bf3d93ac3f4b8209cc18
BLAKE2b-256 1772c077ee4ccdacc9f0650fdab95c8b28e89f4ef62bbf12eb84d676348d33e6

See more details on using hashes here.

File details

Details for the file tmvbeta-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tmvbeta-1.0.0-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

Hashes for tmvbeta-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5eebf287ef6757f7e49fa6179a3e39171906fbc0a72deddf7726141327cbfd75
MD5 5e2902407ce33826dd9669403b46dfd3
BLAKE2b-256 d4cb3c36fac2497d457916e9a157e774b60e3c75cace52265538765c0b3e4aa7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page