queens.parameters.fields package#

Random fields.

Modules for random fields.

Submodules#

queens.parameters.fields.fourier_field module#

Fourier Random fields class.

class DimensionMethods1D[source]#

Bases: object

1D FOURIER expansion helper methods.

static calculate_basis(coordinates, basis_dimension, number_expansion_terms, convex_hull_size, covariance, index)[source]#

Calculate the fourier basis.

Parameters:
  • coordinates (np.array) – Vector with coordinates of field

  • basis_dimension (int) – Dimension of the complete Fourier basis (not the latent space)

  • number_expansion_terms (int) – Number of frequencies

  • convex_hull_size (float) – Maximum length on the mesh

  • covariance (np.array) – Transform of covariance matrix

  • index (np.array) – Array indexing valid basis terms in accordance to the truncation threshold

Returns:

basis (np.array) – Transformed and truncated fourier basis

static calculate_covariance(number_expansion_terms, corr_length, convex_hull_size)[source]#

Calculate discrete fourier transform of the covariance kernel.

Based on the kernel description of the random field, build its covariance matrix using the external geometry and coordinates.

Parameters:
  • number_expansion_terms (int) – Number of frequencies

  • corr_length (float) – Typical length in the field

  • convex_hull_size (float) – Max distance on the grid

Returns:

covariance (np.array) – Cosine transform of covariance matrix

static get_dim(trunc_threshold, number_expansion_terms)[source]#

Calculate dimension of latent space.

Parameters:
  • trunc_threshold (int) – Truncation threshold

  • number_expansion_terms (int) – Number of frequencies in the expansion

Returns:
  • covariance_index (np.array) – Array indexing the covariance values below the truncation limit

  • latent_index (np.array) – Array indexing the basis terms corresponding to valid covariance values

  • basis_dimension (int) – Dimension of the complete Fourier basis up to the truncation threshold

  • dimension (int) – Dimension of the latent space

class DimensionMethods2D[source]#

Bases: object

2D FOURIER expansion helper methods.

static calculate_basis(coordinates, basis_dimension, number_expansion_terms, convex_hull_size, covariance, index)[source]#

Calculate the fourier basis.

Parameters:
  • coordinates (np.array) – Vector with coordinates of field

  • basis_dimension (int) – Dimension of the complete Fourier basis (not the latent space)

  • number_expansion_terms (int) – Number of frequencies

  • convex_hull_size (float) – Maximum length on the mesh

  • covariance (np.array) – Transform of covariance matrix

  • index (np.array) – Array indexing valid basis terms in accordance to the truncation threshold

Returns:

basis (np.array) – Transformed and truncated fourier basis

static calculate_covariance(number_expansion_terms, corr_length, convex_hull_size)[source]#

Calculate discrete fourier transform of the covariance kernel.

Based on the kernel description of the random field, build its covariance matrix using the external geometry and coordinates.

Parameters:
  • number_expansion_terms (int) – Number of frequencies

  • corr_length (float) – Typical length in the field

  • convex_hull_size (float) – Max distance on the grid

Returns:

covariance (np.array) – Cosine transform of covariance matrix

static get_dim(trunc_threshold, number_expansion_terms)[source]#

Calculate dimension of latent space.

Parameters:
  • trunc_threshold (int) – Truncation threshold

  • number_expansion_terms (int) – Number of frequencies in the expansion

Returns:
  • covariance_index (np.array) – Array indexing the covariance values below the truncation limit

  • latent_index (np.array) – Array indexing the basis terms corresponding to valid covariance values

  • basis_dimension (int) – Dimension of the complete Fourier basis up to the truncation threshold

  • dimension (int) – Dimension of the latent space

class DimensionMethods3D[source]#

Bases: object

3D FOURIER expansion helper methods.

static calculate_basis(coordinates, basis_dimension, number_expansion_terms, convex_hull_size, covariance, index)[source]#

Calculate the fourier basis.

Parameters:
  • coordinates (np.array) – Vector with coordinates of field

  • basis_dimension (int) – Dimension of the complete Fourier basis (not the latent space)

  • number_expansion_terms (int) – Number of frequencies

  • convex_hull_size (float) – Maximum length on the mesh

  • covariance (np.array) – Transform of covariance matrix

  • index (np.array) – Array indexing valid basis terms in accordance to the truncation threshold

Returns:

basis (np.array) – Transformed and truncated fourier basis

static calculate_covariance(number_expansion_terms, corr_length, convex_hull_size)[source]#

Calculate discrete fourier transform of the covariance kernel.

Based on the kernel description of the random field, build its covariance matrix using the external geometry and coordinates.

Parameters:
  • number_expansion_terms (int) – Number of frequencies

  • corr_length (float) – Typical length in the field

  • convex_hull_size (float) – Max distance on the grid

Returns:

covariance (np.array) – Cosine transform of covariance matrix

static get_dim(trunc_threshold, number_expansion_terms)[source]#

Calculate dimension of latent space.

Parameters:
  • trunc_threshold (int) – Truncation threshold

  • number_expansion_terms (int) – Number of frequencies in the expansion

Returns:
  • covariance_index (np.array) – Array indexing the covariance values below the truncation limit

  • latent_index (np.array) – Array indexing the basis terms corresponding to valid covariance values

  • basis_dimension (int) – Dimension of the complete Fourier basis up to the truncation threshold

  • dimension (int) – Dimension of the latent space

class FourierRandomField(coords, mean=0.0, std=1.0, corr_length=0.3, variability=0.98, trunc_threshold=64)[source]#

Bases: RandomField

FOURIER expansion of random fields class.

mean#

Mean vector at nodes

Type:

np.array

std#

Hyperparameter for standard-deviation of random field

Type:

float

corr_length#

Hyperparameter for the correlation length

Type:

float

variability#

Explained variance by the fourier decomposition

Type:

float

trunc_threshold#

Truncation threshold for Fourier series

Type:

int

basis_dimension#

Dimension of the complete Fourier basis up to the truncation threshold (not the latent space)

Type:

int

latent_index#

Index array mapping latent space variables to covariance values

Type:

np.array

covariance_index#

Array indexing the covariance values below the truncation threshold

Type:

np.array

covariance#

Fourier transformed covariance kernel

Type:

np.array

basis#

Inverse cosine transformed fourier basis

Type:

np.array

coordinates#

Vector of all coordinates in random field

Type:

np.array

field_dimension#

Physical dimension of the random field

Type:

int

number_expansion_terms#

Number of frequencies in all directions

Type:

int

dimension#

Dimension of latent space

Type:

int

convex_hull_size#

Eucledian distance between furthest apart coordinates in the field

Type:

float

check_convergence()[source]#

Check if truncated terms converge to variability.

draw(num_samples)[source]#

Draw samples from the latent representation of the random field.

Parameters:

num_samples – Number of draws of latent random samples

Returns:

samples (np.ndarray) – Drawn samples

expanded_representation(samples)[source]#

Expand latent representation of sample.

Parameters:

samples (np.ndarray) – Latent representation of sample

Returns:

sample_expanded (np.ndarray) – Expanded representation of samples

grad_logpdf(samples)[source]#

Get gradient of joint logpdf of latent space.

Parameters:

samples (np.array) – Samples for evaluating the gradient of the logpdf

Returns:

gradient (np.array) – Gradient of the logpdf

latent_gradient(upstream_gradient)[source]#

Gradient with respect to the latent parameters.

Parameters:

upstream_gradient (np.ndarray) – Gradient with respect to all coords of the field

Returns:

latent_grad (np.ndarray) – Gradient of the realization of the random field with respect to the latent space variables

logpdf(samples)[source]#

Get joint logpdf of latent space.

Parameters:

samples (np.array) – Samples for evaluating the logpdf

Returns:

logpdf (np.array) – Logpdf of the samples

queens.parameters.fields.kl_field module#

KL Random fields class.

class KarhunenLoeveRandomField(coords, mean=0.0, std=1.0, corr_length=0.3, explained_variance=None, latent_dimension=None, cut_off=0.0)[source]#

Bases: RandomField

Karhunen Loeve RandomField class.

nugget_variance#

Nugget variance for the random field (lower bound for diagonal values of the covariance matrix).

Type:

float

explained_variance#

Explained variance by the eigen decomposition.

Type:

float

std#

Hyperparameter for standard-deviation of random field

Type:

float

corr_length#

Hyperparameter for the correlation length

Type:

float

cut_off#

Lower value limit of covariance matrix entries

Type:

float

mean#

Mean at coordinates of random field, can be a single constant

Type:

np.array

cov_matrix#

Covariance matrix to compute eigendecomposition on

Type:

np.array

eigenbasis#

Eigenvectors of covariance matrix, weighted by the eigenvalues

Type:

np.array

eigenvalues#

Eigenvalues of covariance matrix

Type:

np.array

eigenvectors#

Eigenvectors of covariance matrix

Type:

np.array

dimension#

Dimension of the latent space

Type:

int

calculate_covariance_matrix()[source]#

Calculate discretized covariance matrix.

Based on the kernel description of the random field, build its covariance matrix using the external geometry and coordinates.

draw(num_samples)[source]#

Draw samples from the latent representation of the random field.

Parameters:

num_samples – Number of draws of latent random samples

Returns:

samples (np.ndarray) – Drawn samples

eigendecomp_cov_matrix()[source]#

Decompose and then truncate the random field.

According to desired variance fraction that should be covered/explained by the truncation.

expanded_representation(samples)[source]#

Expand latent representation of sample.

Parameters:

samples (np.ndarray) – Latent representation of sample

Returns:

samples_expanded (np.ndarray) – Expanded representation of sample

grad_logpdf(samples)[source]#

Get gradient of joint logpdf of latent space.

Parameters:

samples (np.array) – Samples for evaluating the gradient of the logpdf

Returns:

gradient (np.array) – Gradient of the logpdf

latent_gradient(upstream_gradient)[source]#

Gradient of the field with respect to the latent parameters.

Parameters:

upstream_gradient (np.ndarray) – Gradient with respect to all coords of the field

Returns:
  • latent_grad (np.ndarray) – Graident of the field with respect to the latent

  • parameters

logpdf(samples)[source]#

Get joint logpdf of latent space.

Parameters:

samples (np.array) – Samples for evaluating the logpdf

Returns:

logpdf (np.array) – Logpdf of the samples

queens.parameters.fields.piece_wise_field module#

Piece-wise random fields class.

class PieceWiseRandomField(coords, distribution)[source]#

Bases: RandomField

Piece-wise random field class.

The field is constructed at each node or element which is given by the coordinates. Each piece is assumed independently. Equals creating random variables for each point in coords.

distribution#

Dummy distribution with correct dimension

Type:

obj

latent_1d_distribution#

(obj): QUEENS distribution object of latent space variables

create_latent_distribution(latent_dict)[source]#

Create a distribution object for the latent space.

Create one distribution of the same kind for all pieces. To save on resourcess only a 1D distribution is created and used for all variables.

Parameters:

latent_dict (dict) – Dict with parameters of latent space

Returns:

distribution (obj) – QUEENS distribution object of latent space

draw(num_samples)[source]#

Draw samples from the latent representation of the random field.

Parameters:

num_samples – Number of draws of latent random samples

Returns:

samples (np.ndarray) – Drawn samples

expanded_representation(samples)[source]#

Expand latent representation of sample.

Parameters:

samples (np.ndarray) – latent representation of sample

Returns:

samples (np.ndarray) – Expanded representation of sample

grad_logpdf(samples)[source]#

Get gradient of joint logpdf of latent space.

latent_gradient(upstream_gradient)[source]#

Gradient of the field with respect to the latent parameters.

Parameters:

upstream_gradient (np.ndarray) – Gradient with respect to all coords of the field

Returns:
  • upstream_gradient (np.ndarray) – Graident of the field with respect to the latent

  • parameters

logpdf(samples)[source]#

Get joint logpdf of latent space.

queens.parameters.fields.random_fields module#

Random fields module.

class RandomField(coords)[source]#

Bases: object

RandomField meta class.

dimension#

Dimension of the latent space.

Type:

int

coords#

Coordinates at which the random field is evaluated.

Type:

np.ndarray

dim_coords#

Dimension of the random field (number of coordinates)

Type:

int

distribution#

QUEENS distribution object of latent space variables

Type:

obj

abstract draw(num_samples)[source]#

Draw samples of the latent space.

Parameters:

num_samples (int) – Batch size of samples to draw

abstract expanded_representation(samples)[source]#

Expand the random field realization.

Parameters:

samples (np.array) – Latent space variables to be expanded into a random field

abstract grad_logpdf(samples)[source]#

Get gradient of joint logpdf of latent space.

Parameters:

samples (np.array) – Sample to evaluate gradient of logpdf

latent_gradient(upstream_gradient)[source]#

Graident of the field with respect to the latent variables.

abstract logpdf(samples)[source]#

Get joint logpdf of latent space.

Parameters:

samples (np.array) – Sample to evaluate logpdf