queens.parameters.random_fields package#
Random fields.
Modules for random fields.
Submodules#
queens.parameters.random_fields.fourier module#
Fourier Random fields class.
- class DimensionMethods1D[source]#
Bases:
object1D 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 (ndarray) – 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 (ndarray) – Transform of covariance matrix
index (ndarray) – Array indexing valid basis terms in accordance to the truncation threshold
- Returns:
Transformed and truncated fourier basis
- Return type:
ndarray
- 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:
Cosine transform of covariance matrix
- Return type:
ndarray
- 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:
Array indexing the covariance values below the truncation limit
Array indexing the basis terms corresponding to valid covariance values
Dimension of the complete Fourier basis up to the truncation threshold
Dimension of the latent space
- Return type:
tuple[ndarray, ndarray, int, int]
- class DimensionMethods2D[source]#
Bases:
object2D 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 (ndarray) – 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 (ndarray) – Transform of covariance matrix
index (ndarray) – Array indexing valid basis terms in accordance to the truncation threshold
- Returns:
Transformed and truncated fourier basis
- Return type:
ndarray
- 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:
Cosine transform of covariance matrix
- Return type:
ndarray
- 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:
Array indexing the covariance values below the truncation limit
Array indexing the basis terms corresponding to valid covariance values
Dimension of the complete Fourier basis up to the truncation threshold
Dimension of the latent space
- Return type:
tuple[ndarray, ndarray, int, int]
- class DimensionMethods3D[source]#
Bases:
object3D 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 (ndarray) – 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 (ndarray) – Transform of covariance matrix
index (ndarray) – Array indexing valid basis terms in accordance to the truncation threshold
- Returns:
Transformed and truncated fourier basis
- Return type:
ndarray
- 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:
Cosine transform of covariance matrix
- Return type:
ndarray
- 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:
Array indexing the covariance values below the truncation limit
Array indexing the basis terms corresponding to valid covariance values
Dimension of the complete Fourier basis up to the truncation threshold
Dimension of the latent space
- Return type:
tuple[ndarray, ndarray, int, int]
- class Fourier[source]#
Bases:
RandomFieldFOURIER expansion of random fields class.
- mean#
Mean vector at nodes
- std#
Hyperparameter for standard-deviation of random field
- corr_length#
Hyperparameter for the correlation length
- variability#
Explained variance by the fourier decomposition
- trunc_threshold#
Truncation threshold for Fourier series
- basis_dimension#
Dimension of the complete Fourier basis up to the truncation threshold (not the latent space)
- latent_index#
Index array mapping latent space variables to covariance values
- covariance_index#
Array indexing the covariance values below the truncation threshold
- covariance#
Fourier transformed covariance kernel
- basis#
Inverse cosine transformed fourier basis
- coordinates#
Vector of all coordinates in random field
- field_dimension#
Physical dimension of the random field
- number_expansion_terms#
Number of frequencies in all directions
- dimension#
Dimension of latent space
- convex_hull_size#
Euclidean distance between furthest apart coordinates in the field
- __init__(coords, mean=0.0, std=1.0, corr_length=0.3, variability=0.98, trunc_threshold=64)[source]#
Initialize Fourier object.
- Parameters:
coords (dict) – Dictionary with coordinates of discretized random field and the corresponding keys
mean (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Mean vector at nodes
std (float) – Hyperparameter for standard-deviation of random field
corr_length (float) – Hyperparameter for the correlation length
variability (float) – Explained variance of by the eigen
trunc_threshold (int) – Truncation threshold for Fourier series.
- draw(num_samples)[source]#
Draw samples from the latent representation of the random field.
- Parameters:
num_samples (int) – Number of draws of latent random samples
- Returns:
Drawn samples
- Return type:
ndarray
- expanded_representation(samples)[source]#
Expand latent representation of samples.
- Parameters:
samples (ndarray) – Latent representation of samples
- Returns:
Expanded representation of samples
- Return type:
ndarray
- grad_logpdf(samples)[source]#
Get gradient of joint log-PDF of latent space.
- Parameters:
samples (ndarray) – Samples for evaluating the gradient of the log-PDF
- Returns:
Gradient of the log-PDF
- Return type:
ndarray
- latent_gradient(upstream_gradient)[source]#
Gradient with respect to the latent parameters.
- Parameters:
upstream_gradient (ndarray) – Gradient with respect to all coords of the field
- Returns:
Gradient of the realization of the random field with respect to the latent space – variables
- Return type:
ndarray
queens.parameters.random_fields.karhunen_loeve module#
Karhunen-Loève Random fields class.
- class KarhunenLoeve[source]#
Bases:
RandomFieldKarhunen Loeve RandomField class.
- nugget_variance#
Nugget variance for the random field (lower bound for diagonal values of the covariance matrix).
- explained_variance#
Explained variance by the eigen decomposition.
- std#
Hyperparameter for standard-deviation of random field
- corr_length#
Hyperparameter for the correlation length
- cut_off#
Lower value limit of covariance matrix entries
- mean#
Mean at coordinates of random field, can be a single constant
- cov_matrix#
Covariance matrix to compute eigendecomposition on
- eigenbasis#
Eigenvectors of covariance matrix, weighted by the eigenvalues
- eigenvalues#
Eigenvalues of covariance matrix
- eigenvectors#
Eigenvectors of covariance matrix
- dimension#
Dimension of the latent space
- __init__(coords, mean=0.0, std=1.0, corr_length=0.3, explained_variance=None, latent_dimension=None, cut_off=0.0)[source]#
Initialize KL object.
- Parameters:
coords (dict) – Dictionary with coordinates of discretized random field and the
mean (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Mean at coordinates of random field, can be a single constant
std (float) – Hyperparameter for standard-deviation of random field
corr_length (float) – Hyperparameter for the correlation length
explained_variance (float | None) – Explained variance of by the eigen decomposition, mutually exclusive argument with latent_dimension
latent_dimension (int | None) – Dimension of the latent space, mutually exclusive argument with explained_variance
cut_off (float) – Lower value limit of covariance matrix entries
- 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.
- Return type:
None
- draw(num_samples)[source]#
Draw samples from the latent representation of the random field.
- Parameters:
num_samples (int) – Number of draws of latent random samples
- Returns:
Drawn samples
- Return type:
ndarray
- eigendecomp_cov_matrix(latent_dimension=None)[source]#
Decompose and then truncate the random field.
According to desired variance fraction that should be covered/explained by the truncation. Also computes the dimension of the latent space if it is not provided.
- Parameters:
latent_dimension (int | None) – Dimension of the latent space
- Returns:
Dimension of the latent space
- Return type:
int
- expanded_representation(samples)[source]#
Expand latent representation of samples.
- Parameters:
samples (ndarray) – Latent representation of samples
- Returns:
Expanded representation of samples
- Return type:
ndarray
- grad_logpdf(samples)[source]#
Get gradient of joint log-PDF of latent space.
- Parameters:
samples (ndarray) – Samples for evaluating the gradient of the log-PDF
- Returns:
Gradient of the log-PDF
- Return type:
ndarray
queens.parameters.random_fields.piece_wise module#
Piece-wise random fields class.
- class PieceWise[source]#
Bases:
RandomFieldPiece-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
- latent_1d_distribution#
QUEENS distribution object of latent space variables
- __init__(coords, latent_1d_distribution)[source]#
Initialize RF object.
- Parameters:
coords (dict) – Dictionary with coordinates of discretized random field and the corresponding keys
latent_1d_distribution (Continuous | Discrete) – Latent 1d distribution that is used for all variables.
- draw(num_samples)[source]#
Draw samples from the latent representation of the random field.
- Parameters:
num_samples (int) – Number of draws of latent random samples
- Returns:
Drawn samples
- Return type:
ndarray
- expanded_representation(samples)[source]#
Expand latent representation of samples.
- Parameters:
samples (ndarray) – Latent representation of samples
- Returns:
Expanded representation of samples
- Return type:
ndarray
- grad_logpdf(samples)[source]#
Get gradient of joint log-PDF of latent space.
- Parameters:
samples (ndarray) – Latent space samples
- Returns:
Gradient of the log-PDF of the samples
- Return type:
ndarray