banquo.numpyro ============== .. py:module:: banquo.numpyro .. autoapi-nested-parse:: The module contains Numpyro Nonparanormal models implementation. Classes ------- .. autoapisummary:: banquo.numpyro.Bernstein banquo.numpyro.NonparanormalBernstein Module Contents --------------- .. py:class:: Bernstein(weights, *, validate_args = None) Bases: :py:obj:`numpyro.distributions.Distribution` Bernstein 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). :param weights: 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. :type weights: array :param validate_args: If True, validates the input parameters. By default, None (no validation is applied). :type validate_args: bool | None, optional :raises ValueError: If `weights` is not at least one-dimensional. .. rubric:: Notes - :func:`Bernstein.log_prob` and :func:`Bernstein.cdf` use :func:`banquo.bernstein_lpdf` and :func:`banquo.bernstein_cdf` respectively, with Beta distribution based Bernstein basis functions. - The weights must sum to 1 across each dimension, fulfilling the Dirichlet distribution constraint. .. py:attribute:: arg_constraints .. py:attribute:: reparametrized_params :value: ['weights'] .. py:attribute:: support .. py:attribute:: weights .. py:method:: 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. :param key: The rng_key to be used for generating random numbers. :type key: random.PRNGKey :param sample_shape: The desired shape of independent samples to draw, by default (). If it is set to an empty tuple, it corresponds to a single sample. :type sample_shape: tuple[int, ...], optional :returns: Samples drawn from the distribution with shape `sample_shape + self.batch_shape + self.event_shape`. :rtype: array :raises ValueError: If the provided key is not a valid PRNG key. .. py:method:: log_prob(value) Compute the lpdf of `value` using the Bernstein polynomial model. :param value: 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. :type value: array :returns: The log-probability density function of `value` under the Bernstein model. :rtype: array .. rubric:: Notes The :func:`banquo.bernstein_lpdf` function is used to calculate the lpdf, based on Beta distribution for Bernstein basis functions. .. py:method:: cdf(value) Compute the cdf of `value` using the Bernstein polynomial model. :param value: 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. :type value: array :returns: The cumulative distribution function of `value` under the Bernstein model. :rtype: array .. rubric:: Notes The :func:`banquo.bernstein_cdf` function is used to calculate the cdf, based on Beta distribution for Bernstein basis functions. .. py:method:: icdf(value) Compute the icdf of `value` using the Bernstein polynomial model. :param value: 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. :type value: array :returns: The quantile function of `value` under the Bernstein model. :rtype: array .. rubric:: Notes The :func:`banquo.bernstein_icdf` function is used to calculate the icdf, based on Beta distribution for Bernstein basis functions. .. py:class:: NonparanormalBernstein(weights, correlation_matrix = None, correlation_cholesky = None, *, validate_args = None) Bases: :py:obj:`numpyro.distributions.GaussianCopula` Nonparanormal 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: .. math:: 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 :math:`\mathbf{\Psi}(\mathbf{x}) = (\Psi_1(x_1), \ldots, \Psi_d(x_d))^\mathrm{T}`, where :math:`\Psi_i = \Phi^{-1} \circ F_i`. In this case, :math:`F_i` are Bernstein cdf estimators given by: .. math:: F_i(x) \approx \mathbf{w_i}^\mathrm{T} \mathbf{B}(x), and the marginal density estimators are given by: .. math:: p_i(x) \approx \mathbf{w_i}^\mathrm{T} \mathbf{\beta}(x). Both functions are implemented by :class:`Bernstein` model. :param weights: 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. :type weights: array :param correlation_matrix: Correlation matrix of coupling multivariate normal distribution, by default None. :type correlation_matrix: array | None, optional :param correlation_cholesky: Correlation Cholesky factor of coupling multivariate normal distribution, by default None. :type correlation_cholesky: array | None, optional :param validate_args: If True, validates the input parameters. By default, None (no validation is applied). :type validate_args: bool | None, optional :raises ValueError: If `weights` is not at least one-dimensional. .. py:attribute:: arg_constraints .. py:attribute:: support .. py:attribute:: pytree_data_fields :value: 'weights' .. py:attribute:: weights