sampling
This package provides tools to efficiently sample from covariance models on grids using circulant embeddings and the Fast Fourier Transform.
simulation
SamplerOnRectangularGrid(model: CovarianceModel, grid: RectangularGrid, exact: bool = True)
Class that allows to define efficient samplers on rectangular grids for fixed models.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
CovarianceModel
|
Covariance model used for sampling. |
grid |
RectangularGrid
|
Grid on which we wish to sample |
n_sims |
int
|
Simulations can be carried out in 'blocks'. This parameter allows to choose how many i.i.d. samples are generated in each block computation. |
f |
ndarray
|
Spectral amplitudes |
Notes
This sampler accounts for the grid's mask by setting missing values to zero.
Examples:
>>> from debiased_spatial_whittle.models.univariate import ExponentialModel
>>> from debiased_spatial_whittle.grids.base import RectangularGrid
>>> model = ExponentialModel(rho=12., sigma=1.)
>>> grid = RectangularGrid((256, 128))
>>> sampler = SamplerOnRectangularGrid(model, grid)
>>> sample = sampler()
>>> sample.shape
(256, 128)
model: CovarianceModel
property
writable
Model from which we sample
grid: RectangularGrid
property
writable
Sampling grid
n_sims
property
writable
number of simulations in each block computation. By increasing this value, one allows parallel simulation, at the expense of increased memory usage.
spectral_amplitudes
property
Spectral amplitudes of the covariance matrix on the circulant embedded grid.
__call__()
Samples a realization of a Gaussian Process specified by the provided covariance model, on the provided rectangular grid.
Returns:
| Name | Type | Description |
|---|---|---|
sample |
ndarray
|
Sample values corresponding to the grid and covariance model. Shape is equal to the n attribute of grid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a non-negative definite circulant embedding could not be achieved. In that case a solution is to increase the grid size. |
MultivariateSamplerOnRectangularGrid(model: CovarianceModel, grid: RectangularGrid, p: int)
Implements circulant embedding for multivariate random fields, as proposed by Chan & Wood (1999).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CovarianceModel
|
Model from which we sample |
required |
grid
|
RectangularGrid
|
Sampling grid |
required |
p
|
int
|
Number of variates of the model |
required |
model: CovarianceModel
property
writable
Model from which we sample
grid: RectangularGrid
property
writable
Sampling grid
__call__() -> xp.ndarray
Generate a realization from the specified covariance model on the grid.
Returns:
| Type | Description |
|---|---|
sample
|
Simulated sample. |
SamplerSeparable(model: SeparableModel, grid: RectangularGrid, n_sim: int = 100)
Class for approximate sampling of Separable models.
SamplerBUCOnRectangularGrid(model: BivariateUniformCorrelation, grid: RectangularGrid)
Class to sample from the BivariateUniformCorrelation model on a rectangular grid with nvars=2.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
RectangularGrid
|
Sampling grid. Should have attribute nvars=2. |
model |
BivariateUniformCorrelation
|
Bivariate covariance model |
f |
ndarray
|
Spectral amplitudes |
__call__(periodic: bool = False, return_spectral: bool = False) -> xp.ndarray
Sample a realization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
periodic
|
bool
|
if true, returns a periodic sample on an embedding grid |
False
|
return_spectral
|
bool
|
if true, returns the spectral amplitudes as well |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
sample |
ndarray
|
shape (n1, ..., nd, 2) where the last dimension indexes the two variates. |
samples
Sample(grid: RectangularGrid, values: np.ndarray)
General class for the definition of a sampled random field. Allows to store computed quantities such as periodograms etc.
SampleOnRectangularGrid(grid: RectangularGrid, values: np.ndarray)
Bases: Sample
Class for a sample on a Rectangular grid. In the case of a grid with missing observations, the values at missing locations are not used.