Sampling methods¶
Capabilities for sampling of random input parameters.
This module contains functions to sample random input parameters.
-
econsa.sampling.
cond_mvn
(mean, cov, dependent_ind, given_ind=None, given_value=None, check_cov=True)[source]¶ Conditional mean and variance function.
This function provides the conditional mean and variance-covariance matrix of [\(Y\) given \(X\)], where \(Z = (X,Y)\) is the fully-joint multivariate normal distribution with mean equal to
mean
and covariance matrixcov
.This is a translation of the main function of R package condMVNorm.
- Parameters
mean (array_like) – The mean vector of the multivariate normal distribution.
cov (array_like) – Symmetric and positive-definite covariance matrix of the multivariate normal distribution.
dependent_ind (int or array_like) – The indices of dependent variables.
given_ind (array_like, optional) – The indices of independent variables (default value is None). If not specified return unconditional values.
given_value (array_like, optional) – The conditioning values (default value is None). Should be the same length as
given_ind
, otherwise throw an error.check_cov (bool, optional) – Check that
cov
is symmetric, and all eigenvalue is positive (default value is True).
- Returns
cond_mean (array_like) – The conditional mean of dependent variables.
cond_cov (arrray_like) – The conditional covariance matrix of dependent variables.
Examples
>>> mean = np.array([1, 1, 1]) >>> cov = np.array([[4.0677098, -0.9620331, 0.9897267], ... [-0.9620331, 2.2775449, 0.7475968], ... [0.9897267, 0.7475968, 0.7336631]]) >>> dependent_ind = [0, ] >>> given_ind = [1, 2] >>> given_value = [1, -1] >>> cond_mean, cond_cov = cond_mvn(mean, cov, dependent_ind, given_ind, given_value) >>> np.testing.assert_almost_equal(cond_mean, -4.347531, decimal=6) >>> np.testing.assert_almost_equal(cond_cov, 0.170718, decimal=6)