Discretisation¶
How accurately a FourierGP represents its kernel, and the modes and padding
an accuracy needs. See Geometry and discretisation.
spectracles.discretisation.discretisation_error(gp_or_kernel, *, domain=None, n_modes=None, padding=None, length_scale=None, has_mean=False)
¶
The truncation and aliasing errors of a FourierGP, or of a kernel on a given grid.
Every setting can be overridden, to ask what the error would be with other modes, padding or length scale:
discretisation_error(gp) # as it is
discretisation_error(gp, length_scale=40.0) # if ℓ were 40
discretisation_error(gp, n_modes=201) # with 201 x 201 modes
discretisation_error(kernel, domain=d, n_modes=301, padding=0.15)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gp_or_kernel
|
FourierGP | Kernel
|
A FourierGP, or a kernel (then |
required |
domain
|
Domain | None
|
The data region; the GP's own by default. |
None
|
n_modes
|
int | tuple[int, int] | None
|
Modes per side (an int, or two odd ints); the GP's by default. |
None
|
padding
|
float | None
|
Padding as a fraction of the extent; the GP's by default, or 0.15. |
None
|
length_scale
|
float | ArrayLike | None
|
The kernel's length scale; its current value by default. An array gives the errors at each value. |
None
|
has_mean
|
bool
|
For a kernel: whether the field has a mean (its k = 0 mode is then dropped). A FourierGP's own setting is used otherwise. |
False
|
Returns:
| Type | Description |
|---|---|
DiscretisationError
|
A DiscretisationError. |
spectracles.discretisation.DiscretisationError
dataclass
¶
A FourierGP's errors against its kernel, relative to the field's variance.
Attributes:
| Name | Type | Description |
|---|---|---|
truncation |
float | ndarray
|
Relative Frobenius error from the finite mode grid. |
aliasing |
float | ndarray
|
Worst-case error from the box's periodic images. |
truncation_max |
float | ndarray
|
Worst-case truncation error (≈ tau). |
tau |
float | ndarray
|
Fraction of the kernel's variance at scales below the grid. It turns negative when aliasing is large, since the grid then also picks up the periodic images' variance. |
length_scale |
float | ndarray | None
|
The length scale the errors are for (None if the kernel has none). |
n_modes |
tuple[int, int]
|
Modes in each direction. |
padding |
float
|
Padding on each side, as a fraction of the domain's extent. |
With an array of length scales, the error fields are arrays of the same shape.
worst
property
¶
The larger of the truncation and aliasing errors.
spectracles.discretisation.required_modes(kernel, domain, *, length_scale=None, padding=DEFAULT_PADDING, tol=DEFAULT_TOL, has_mean=False)
¶
The fewest modes per side (odd) with a truncation error at most tol.
Truncation is worst at the shortest length scale, so pass the smallest one you expect (the kernel's current value by default).
spectracles.discretisation.required_padding(kernel, domain, *, length_scale=None, tol=DEFAULT_TOL)
¶
The least padding (a fraction of the extent, to 1%) with an aliasing error at most tol.
Aliasing is worst at the longest length scale, so pass the largest one you expect (the kernel's current value by default).
spectracles.discretisation.report(model_or_latent, samples=None, *, tol=None, space='latent', print_table=True)
¶
Check every FourierGP in a model against its tolerance, at its current hyperparameters or at every sample.
Truncation is checked at the shortest length scale across the samples and
aliasing at the longest, which is where each is worst. A GP whose modes
were chosen for you is checked against its own tol (and its design
range of length scales is shown); others against 1e-3, or tol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_or_latent
|
Any
|
A built model, a LatentSpace or a Posterior. |
required |
samples
|
Any
|
Samples (as for |
None
|
tol
|
float | None
|
The tolerance for every GP, instead of each GP's own. |
None
|
space
|
str
|
Whether |
'latent'
|
print_table
|
bool
|
Whether to print the table. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
{path: {"n_modes", "padding", "length_scale" (shortest, longest), |
dict[str, dict[str, Any]]
|
"design" (or None), "truncation", "aliasing", "tol", "ok"}}. |
spectracles.discretisation.plot_discretisation(gp, length_scales=None, *, tol=None, ax=None)
¶
Plot a FourierGP's truncation and aliasing errors against the length scale.
Shows the tolerance, the range of length scales the GP was designed for (if its modes were chosen for you) and, optionally, the length scales found in a fit (e.g. posterior samples), as ticks along the bottom.
Returns:
| Type | Description |
|---|---|
Any
|
The matplotlib Axes. |
spectracles.discretisation.realised_covariance(gp, dx, dy)
¶
The field's covariance at lags (dx, dy), in the coordinates' units: exact, from the kernel's weights (no data or NUFFT needed).