banquo.numpyro¶
The module contains Numpyro Nonparanormal models implementation.
Classes¶
Bernstein polynomial-based model. |
|
Nonparanormal model with Bernstein polynomial-based marginals. |
Module Contents¶
- class banquo.numpyro.Bernstein(weights, *, validate_args=None)¶
Bases:
numpyro.distributions.DistributionBernstein polynomial-based model.
The Bernstein class implements a probability distribution for nonparametric modeling densities with Bernstein polynomials. It uses a set of weights as coefficients for the basis functions and supports computing the log-probability density and cumulative distribution function (CDF).
- Parameters:
weights (array) – Array of weights (simplex) with shape (d, k), where d is the number of dimensions, and k is the number of basis functions (Bernstein polynomial order). If the shape is k, the system will be considered as a one-dimensional array. The weights are, for each dimension d, a k-dimensional unit simplex. The weights are applied as coefficients for the Bernstein polynomial basis in each dimension.
validate_args (bool | None, optional) – If True, validates the input parameters. By default, None (no validation is applied).
- Raises:
ValueError – If weights is not at least one-dimensional.
Notes
Bernstein.log_prob()andBernstein.cdf()usebanquo.bernstein_lpdf()andbanquo.bernstein_cdf()respectively, with Beta distribution based Bernstein basis functions.The weights must sum to 1 across each dimension, fulfilling the Dirichlet distribution constraint.
- arg_constraints¶
- reparametrized_params = ['weights']¶
- support¶
- weights¶
- sample(key, sample_shape=())¶
Sample from Bernstein distribution.
Returns a sample from the distribution with the shape specified by sample_shape + batch_shape + event_shape. Exchangeable draws from the distribution instance will fill the leading dimensions (of size sample_shape) of the returned sample when sample_shape is not empty.
- Parameters:
key (random.PRNGKey) – The rng_key to be used for generating random numbers.
sample_shape (tuple[int, ...], optional) – The desired shape of independent samples to draw, by default (). If it is set to an empty tuple, it corresponds to a single sample.
- Returns:
Samples drawn from the distribution with shape sample_shape + self.batch_shape + self.event_shape.
- Return type:
array
- Raises:
ValueError – If the provided key is not a valid PRNG key.
- log_prob(value)¶
Compute the lpdf of value using the Bernstein polynomial model.
- Parameters:
value (array) – The observed data or values to evaluate the lpdf. The array should have shape (n, d), where n is the number of samples, and d is the number of dimensions. If value is one-dimensional with shape (n,), it will be reshaped to (n, 1). Each element represents a sample to be evaluated under the Bernstein polynomial model.
- Returns:
The log-probability density function of value under the Bernstein model.
- Return type:
array
Notes
The
banquo.bernstein_lpdf()function is used to calculate the lpdf, based on Beta distribution for Bernstein basis functions.
- cdf(value)¶
Compute the cdf of value using the Bernstein polynomial model.
- Parameters:
value (array) – The observed data or values to evaluate the cdf. The array should have shape (n, d), where n is the number of samples, and d is the number of dimensions. If value is one-dimensional with shape (n,), it will be reshaped to (n, 1). Each element represents a sample to be evaluated under the Bernstein polynomial model.
- Returns:
The cumulative distribution function of value under the Bernstein model.
- Return type:
array
Notes
The
banquo.bernstein_cdf()function is used to calculate the cdf, based on Beta distribution for Bernstein basis functions.
- icdf(value)¶
Compute the icdf of value using the Bernstein polynomial model.
- Parameters:
value (array) – The observed data or values to evaluate the icdf. The array should have shape (n, d), where n is the number of samples, and d is the number of dimensions. If value is one-dimensional with shape (n,), it will be reshaped to (n, 1). Each element represents a value in the interval [0, 1] to return quantile under the Bernstein polynomial model.
- Returns:
The quantile function of value under the Bernstein model.
- Return type:
array
Notes
The
banquo.bernstein_icdf()function is used to calculate the icdf, based on Beta distribution for Bernstein basis functions.
- class banquo.numpyro.NonparanormalBernstein(weights, correlation_matrix=None, correlation_cholesky=None, *, validate_args=None)¶
Bases:
numpyro.distributions.GaussianCopulaNonparanormal model with Bernstein polynomial-based marginals.
The NonparanormalBernstein class implements a probability distribution for nonparametric marginal densities modeling with Bernstein polynomials. It uses a set of weights as coefficients for the basis functions and supports computing the log-probability density and cumulative distribution function (CDF). A Gaussian copula is used to create the joint distribution. The nonparanormal model is formed up of both the nonparametric marginals and the Gaussian copula, and its probability density function is as follows:
\[p(\mathbf{x}) = \lvert\mathbf{\Sigma}\rvert^{-1/2} \, \exp \left( -\frac{1}{2} \mathbf{\Psi}(\mathbf{x})^\mathrm{T} \, \left(\mathbf{\Sigma}^{-1} - \mathbf{I}\right) \, \mathbf{\Psi}(\mathbf{x})\right) \prod_{i=1}^d \lvert p(x_i)\rvert,\]with \(\mathbf{\Psi}(\mathbf{x}) = (\Psi_1(x_1), \ldots, \Psi_d(x_d))^\mathrm{T}\), where \(\Psi_i = \Phi^{-1} \circ F_i\). In this case, \(F_i\) are Bernstein cdf estimators given by:
\[F_i(x) \approx \mathbf{w_i}^\mathrm{T} \mathbf{B}(x),\]and the marginal density estimators are given by:
\[p_i(x) \approx \mathbf{w_i}^\mathrm{T} \mathbf{\beta}(x).\]Both functions are implemented by
Bernsteinmodel.- Parameters:
weights (array) – Array of weights (simplex) with shape (d, k), where d is the number of dimensions, and k is the number of basis functions (Bernstein polynomial order). If the shape is k, the system will be considered as a one-dimensional array. The weights are, for each dimension d, a k-dimensional unit simplex. The weights are applied as coefficients for the Bernstein polynomial basis in each dimension.
correlation_matrix (array | None, optional) – Correlation matrix of coupling multivariate normal distribution, by default None.
correlation_cholesky (array | None, optional) – Correlation Cholesky factor of coupling multivariate normal distribution, by default None.
validate_args (bool | None, optional) – If True, validates the input parameters. By default, None (no validation is applied).
- Raises:
ValueError – If weights is not at least one-dimensional.
- arg_constraints¶
- support¶
- pytree_data_fields = 'weights'¶
- weights¶