mlmc.random

Subpackage provides random field generation and GSTools library interface

Submodules

mlmc.random.correlated_field module

class mlmc.random.correlated_field.Field(name, field=None, param_fields=[], regions=[])[source]

Bases: object

sample()[source]

Internal method to generate/compute new sample. :return:

set_points(points)[source]

Internal method to set evaluation points. See Fields.set_points.

class mlmc.random.correlated_field.Fields(fields)[source]

Bases: object

sample()[source]

Return dictionary of sampled fields. :return: { ‘field_name’: sample, …}

set_outer_fields(outer)[source]

Set fields that will be in a dictionary produced by FieldSet.sample() call. :param outer: A list of names of fields that are sampled. :return:

set_points(points, region_ids=[], region_map={})[source]

Set mesh related data to fields. - set points for sample evaluation - translate region names to region ids in fields - create maps from region constraned point sets of fields to full point set :param points: np array of points for field evaluation :param regions: regions of the points;

empty means no points for fields restricted to regions and all points for unrestricted fields
Returns:
names
class mlmc.random.correlated_field.FourierSpatialCorrelatedField(corr_exp='gauss', dim=2, corr_length=1.0, aniso_correlation=None, mu=0.0, sigma=1.0, log=False, **kwargs)[source]

Bases: mlmc.random.correlated_field.RandomFieldBase

Generate spatial random fields

exp(mode_no=1000)[source]

Compute an exponential spectrum :param mode_no: int, Number of Fourier modes :return: numpy.ndarray

gau(mode_no=1000)[source]

Compute a gaussian spectrum :param mode_no: int, Number of Fourier modes :return: numpy.ndarray

get_normal_distr()[source]

Normal distributed arrays :return: np.ndarray

random_field()[source]

Calculates the random modes for the randomization method.

class mlmc.random.correlated_field.GSToolsSpatialCorrelatedField(model, mode_no=1000, log=False, sigma=1)[source]

Bases: mlmc.random.correlated_field.RandomFieldBase

change_srf(seed)[source]

Spatial random field with new seed :param seed: int, random number generator seed :return: None

random_field()[source]

Generate the spatial random field :return: field, np.ndarray

sample()[source]
Returns:Random field evaluated in points given by ‘set_points’
class mlmc.random.correlated_field.RandomFieldBase(corr_exp='gauss', dim=2, corr_length=1.0, aniso_correlation=None, mu=0.0, sigma=1.0, log=False, **kwargs)[source]

Bases: object

Base class for various methods for generating random fields.

Generating realizations of a spatially correlated random field F for a fixed set of points at X. E[F(x)] = mu(x) Cov_ij = Cov[x_i,x_j] = E[(F(x_i) - mu(x))(F(x_j) - mu(x))]

We assume stationary random field with covariance matrix Cov_ij:
Cov_i,j = c(x_i - x_j)
where c(X) is the “stationary covariance” function. We assume:
c(X) = sigma^2 exp( -|X^t K X|^(alpha/2) )

for spatially heterogeneous sigma(X) we consider particular non-stationary generalization: Cov_i,i = sigma(x_i)*sigma(x_j) exp( -|X^t K X|^(alpha/2) ); X = x_i - x_j

where:
  • sigma(X) is the standard deviance of the single uncorrelated value
  • K is a positive definite tensor with eigen vectors corresponding to main directions and eigen values equal to (1/l_i)^2, where l_i is correlation length in singel main direction.
  • alpha is =1 for “exponential” and =2 for “Gauss” correlation
SVD decomposition:
Considering first m vectors, such that lam(m)/lam(0) <0.1

Example: ```

field = SpatialCorrelatedField(corr_exp=’exp’, corr_length=1.5) X, Y = np.mgrid[0:1:10j, 0:1:10j] points = np.vstack([X.ravel(), Y.ravel()]) field.set_points(points) sample = field.sample()

```

sample()[source]
Parameters:uncorelated – Random samples from standard normal distribution. Removed as the spectral method do not support it.
Returns:Random field evaluated in points given by ‘set_points’.
set_points(points, mu=None, sigma=None)[source]
Parameters:
  • points – N x d array. Points X_i where the field will be evaluated. d is the dimension.
  • mu – Scalar or N array. Mean value of uncorrelated field: E( F(X_i)).
  • sigma – Scalar or N array. Standard deviance of uncorrelated field: sqrt( E ( F(X_i) - mu_i )^2 )
Returns:

None

class mlmc.random.correlated_field.SpatialCorrelatedField(corr_exp='gauss', dim=2, corr_length=1.0, aniso_correlation=None, mu=0.0, sigma=1.0, log=False, **kwargs)[source]

Bases: mlmc.random.correlated_field.RandomFieldBase

cov_matrix()[source]

Setup dense covariance matrix for given set of points. :return: None.

svd_dcmp(precision=0.01, n_terms_range=(1, inf))[source]

Does decomposition of covariance matrix defined by set of points :param precision: Desired accuracy of the KL approximation, smaller eigen values are dropped. :param n_terms_range: (min, max) number of terms in KL expansion to use. The number of terms estimated from given precision is snapped to the given interval.

truncated SVD:
cov_mat = U*diag(ev) * V, _cov_l_factor = U[:,0:m]*sqrt(ev[0:m])

Note on number of terms: According to: C. Schwab and R. A. Todor: KL Approximation of Random Fields by Generalized Fast Multiploe Method the eigen values should decay as (Proposition 2.18):

lambda_m ~ sigma^2 * ( 1/gamma ) **( m**(1/d) + alpha ) / Gamma(0.5 * m**(1/d) )

where gamma = correlation length / domain diameter ans alpha is the correlation exponent. Gamma is the gamma function. … should be checked experimantaly and generalized for sigma(X)

Returns:
mlmc.random.correlated_field.kozeny_carman(porosity, m, factor, viscosity)[source]

Kozeny-Carman law. Empirical relationship between porosity and conductivity. :param porosity: Porosity value. :param m: Power. Suitable values are 1 < m < 4 :param factor: [m^2]

E.g. 1e-7 , m = 3.48; juta fibers
2.2e-8 , 1.46; glass fibers 1.8e-13, 2.89; erruptive material 1e-12 2.76; erruptive material 1.8e-12 1.99; basalt
Parameters:viscosity – [Pa . s], water: 8.90e-4
Returns:
mlmc.random.correlated_field.positive_to_range(exp, a, b)[source]

Mapping a positive parameter ‘exp’ from the interval <0, infty) to the interval <a,b). Suitable e.g. to generate meaningful porosity from a variable with lognormal distribution. :param exp: A positive parameter. (LogNormal distribution.) :param a, b: Range interval.

mlmc.random.frac_geom module

mlmc.random.gstools_wrapper module

Module contents

Subpackage provides random field generation and GSTools library interface