# 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 matrix cov.

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)


Conditional sampling from Gaussian copula.

This module contains functions to sample random input parameters from a Gaussian copula.

econsa.copula.cond_gaussian_copula(cov, dependent_ind, given_ind, given_value_u, size=1)[source]

Conditional sampling from Gaussian copula.

This function provides the probability distribution of conditional sample drawn from a Gaussian copula, given covariance matrix and a uniform random vector.

Parameters
• cov (array_like) – Covariance matrix of the desired sample.

• dependent_ind (int or array_like) – The indices of dependent variables.

• given_ind (array_like) – The indices of independent variables.

• given_value_u (array_like) – The given random vector ($$u$$) that is uniformly distributed between 0 and 1.

• size (int) – Number of draws from the conditional distribution. (default value is 1)

Returns

cond_quan – The conditional sample ($$G(u)$$) that is between 0 and 1, and has the same length as dependent_ind.

Return type

numpy.ndarray

Examples

>>> np.random.seed(123)
>>> cov = np.array([[ 3.290887,  0.465004, -3.411841],
...                 [ 0.465004,  3.962172, -0.574745],
...                 [-3.411841, -0.574745,  4.063252]])
>>> dependent_ind = 2
>>> given_ind = [0, 1]
>>> given_value_u = [0.0596779, 0.39804426]
>>> condi_value_u = cond_gaussian_copula(cov, dependent_ind, given_ind, given_value_u)
>>> np.testing.assert_almost_equal(condi_value_u[0], 0.856504, decimal=6)