Skip to content

uncertainty.draws

Correlated draws of the variables of an uncertainty analysis.

The points of the unit cube are quasi-random (scrambled Sobol points, the default, Owen 1998; Joe & Kuo 2008), a Latin hypercube or random. Their normal scores z = Φ⁻¹(u) are correlated with the Cholesky factor of the correlation of the normal scores, z L^T, mapped back to the unit interval, Φ(z), and through the inverse distribution function of every marginal (a Gaussian copula, Nelsen 2006). For normal marginals this is the multivariate normal of the covariance, for log-normal marginals the multivariate normal of their logarithms; for other marginals the correlation is the one of the normal scores, about the same rank correlation.

The correlation of the normal scores comes from the covariances of the analysis (normal_score_correlation):

  • a correlation: the coefficients between the normal scores (for log-normal marginals between the logarithms)
  • a covariance of normal marginals: Σ_ij / (sd_i sd_j)
  • a covariance on the log scale of log-normal marginals: Σ_ij / (σ_i σ_j) with the standard deviations σ of the logarithms
  • a covariance on the linear scale of log-normal marginals: the exact conversion ln(1 + Σ_ij / (μ_i μ_j)) / (σ_i σ_j) with the means μ

The variances of a covariance must be the variances of the marginals (a relative tolerance of 1e-6), which the marginals define.

Owen AB (1998). Scrambling Sobol' and Niederreiter-Xing points. J Complexity 14:466-489. Joe S, Kuo FY (2008). Constructing Sobol sequences with better two-dimensional projections. SIAM J Sci Comput 30:2635-2654. Nelsen RB (2006). An Introduction to Copulas, 2nd ed. Springer.

normal_score_correlation

normal_score_correlation(variables, covariance)

Get the correlation of the normal scores of the variables, see the module.

Parameters:

Name Type Description Default
variables Sequence[Variable]

the variables, in the order of the columns.

required
covariance Sequence[Covariance]

the covariances and correlations, by the keys.

required

Returns:

Type Description
ndarray

The correlation matrix of the normal scores.

Raises:

Type Description
ValueError

for a target of a covariance which is no variable, a variable in two covariances, variances which disagree with the marginals, or a correlation which is not positive semi-definite.

unit_points

unit_points(d, n, *, design='sobol', seed, start=0)

Get n points of the unit cube of d dimensions.

Sobol points and random points continue their sequence from start, so the batches of a propagation are the first points of one sequence; a Latin hypercube has no continuation, a hypercube of more points is another one.

Parameters:

Name Type Description Default
d int

the number of dimensions.

required
n int

the number of points.

required
design Literal['sobol', 'lhs', 'random']

sobol, lhs or random.

'sobol'
seed int

the seed.

required
start int

the index of the first point.

0

Returns:

Type Description
ndarray

The points, n rows of d columns.

Raises:

Type Description
ValueError

for another design, or a Latin hypercube after start.

draw

draw(
    variables,
    covariance,
    n,
    *,
    design="sobol",
    seed,
    start=0,
    model=None,
    simulation=None,
    scenario=None,
)

Get n correlated draws of the variables, see the module.

Parameters:

Name Type Description Default
variables Sequence[Variable]

the variables.

required
covariance Sequence[Covariance]

their covariances and correlations.

required
n int

the number of draws.

required
design Literal['sobol', 'lhs', 'random']

sobol, lhs or random, see unit_points.

'sobol'
seed int

the seed.

required
start int

the index of the first draw of the sequence.

0
model Any

the model, which a relative distribution needs.

None
simulation Simulation | None

the simulation whose pre-initialization gives the references of relative distributions.

None
scenario str | None

the scenario of the marginals of the variables, see Variable.by_scenario; the same points give the same quantiles in every scenario.

None

Returns:

Type Description
dict[str, ndarray | Quantity]

Key -> the values of the variable, a quantity where it has a unit.

Raises:

Type Description
ValueError

see normal_score_correlation, or a relative distribution without a model.