Inference
GaussianProcess.condition(dataset) returns a ConditionedPosterior.
For a complete example, start with First posterior.
The posterior accepts a FunctionalQuery for prediction and sampling.
Prediction methods
| Method | Result |
|---|---|
predict_mean(query) |
Named means |
predict_variance(query) |
Named marginal variances |
predict_marginals(query) |
Means and marginal variances together |
predict_covariance(query) |
Full joint covariance |
predict(query) |
Means and full joint covariance together |
sample(key, query, sample_count=...) |
Joint Gaussian draws at the query |
The marginal methods avoid constructing a full query covariance. Use
predict_marginals for pointwise uncertainty bands. Use a full covariance
when correlations between query outputs matter.
Named results and shapes
For a query block named "target" with public shape s:
| Access | Shape |
|---|---|
prediction.mean["target"] |
s |
marginals.variance["target"] |
s |
prediction.covariance.variance["target"] |
s |
prediction.covariance.block("left", "right") |
(*left_shape, *right_shape) |
samples["target"] |
(sample_count, *s) |
A block at n locations has shape (n, *operator_output_shape).
For a joint query with a scalar block and a gradient block in d dimensions,
their cross-covariance has shape (n, n, d). Sample rows correspond to the
same joint draw across blocks. Query predictions describe latent functionals.
To obtain a covariance for future noisy readings, add their measurement-error
variances to the appropriate diagonal entries.
Prediction results can cross an outer jit. Under vmap, named arrays retain
the leading batch axes. Dataset and query input dimensions must agree.
Conditioning and numerical options
gp.condition(dataset, jitter=1e-6) adds jitter to the observation covariance
diagonal before solving. Jitter is an absolute covariance quantity and must be
finite and nonnegative. Choose it in the units of your model and keep it
consistent between fitting and conditioning. Observation noise is specified
by the dataset's design. Sampling has its own jitter argument for stabilizing
the query covariance factorization.
The default dense solver supports first-order forward and reverse derivatives through conditioning and updates. Higher-order derivatives through its factorization and updates are unsupported. Failed Cholesky factorizations can produce non-finite results, including under JIT. Check outputs before using them. Use consistent floating precision, sensible units, and explicit regularization for redundant measurements. A jitter too small relative to the covariance diagonal can round away.
GaussianProcess(kernel, covariance_tile_size=1024) evaluates observation
covariances in smaller tiles. Tile size counts scalar outputs, with at least
one location's complete output per tile. Smaller tiles reduce temporary memory
at the cost of more loop overhead. The final dense covariance and its
factorization still have to fit in memory. The default is None.
See numerical backends for solver configuration and interfaces.
Proposed measurements and posterior updates
gp.prepare_conditioning(design) returns a ConditioningState for covariance
calculations before outcomes are available. PreparedQuery(conditioning, query)
reuses a fixed target when comparing proposed measurements. Preparation stores
the full target covariance, including for subsequent variance-only requests.
Rebuild it after changing the GP, existing design, jitter, or target.
posterior.append(locations, readings, block="name") updates an existing
posterior within a declared block's capacity. posterior.conditioning.append
performs a covariance update without readings. See
Experimental design and
Sequential observations for their use,
and observation capacity for compilation and
model-reuse conditions.
Classes and methods
gpex.gp
Exact Gaussian-process inference.
GaussianProcess
GaussianProcess(
kernel: KernelType,
mean: Mean | ScalarFunction | None = None,
*,
covariance_tile_size: int | None = None,
solver: SolverConfiguration | None = None,
)
Bases: Module
A scalar latent GP whose observations and queries may use linear operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
KernelType
|
Scalar covariance kernel evaluated on points of shape |
required |
mean
|
Mean | ScalarFunction | None
|
Scalar mean function. |
None
|
covariance_tile_size
|
int | None
|
Positive tile size for materialized covariance
construction. Defaults to |
None
|
solver
|
SolverConfiguration | None
|
Numerical backend, such as |
None
|
Source code in src/gpex/gp.py
covariance_tile_size
class-attribute
instance-attribute
solver
instance-attribute
solver: SolverConfiguration = (
DenseBackend() if solver is None else solver
)
prior_mean
prior_mean(query: FunctionalQuery) -> StructuredValues
Return prior means for a query, with named arrays in each block's shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Locations and linear operators to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Structured means with |
Source code in src/gpex/gp.py
prior_covariance
prior_covariance(
query: FunctionalQuery,
) -> CovarianceResult
Return prior covariance for a query, without observation noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Locations and linear operators to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
CovarianceResult
|
Full covariance of shape |
Source code in src/gpex/gp.py
prior_variance
prior_variance(query: FunctionalQuery) -> StructuredValues
Return latent marginal variances without forming a full covariance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Locations and linear operators to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Variances accessible by block name, in each block's output shape. |
Source code in src/gpex/gp.py
sample_prior
sample_prior(
key: PRNGKeyArray,
query: FunctionalQuery,
*,
sample_count: int = 1,
jitter: float = 1e-06,
) -> StructuredValues
Draw joint samples at a fixed query from the latent prior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key; supply a fresh key for independent draws. |
required |
query
|
FunctionalQuery
|
Locations and linear operators to sample jointly. |
required |
sample_count
|
int
|
Number of draws. Defaults to 1. |
1
|
jitter
|
float
|
Diagonal stabilization for sampling. Defaults to |
1e-06
|
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Samples with |
Source code in src/gpex/gp.py
prepare_conditioning
prepare_conditioning(
design: ObservationDesign | FunctionalDataset,
*,
jitter: float = 1e-06,
) -> ConditioningState[KernelType]
Prepare conditional covariance without using observation outcomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
design
|
ObservationDesign | FunctionalDataset
|
Measurement locations, operators, and noise. A dataset is also accepted; its observed values are ignored. |
required |
jitter
|
float
|
Diagonal stabilization of the observation covariance.
Defaults to |
1e-06
|
Returns:
| Type | Description |
|---|---|
ConditioningState[KernelType]
|
Reusable conditioning state for solves, covariance prediction, and |
ConditioningState[KernelType]
|
design updates. |
Source code in src/gpex/gp.py
condition
condition(
dataset: FunctionalDataset, *, jitter: float = 1e-06
) -> ConditionedPosterior[KernelType]
Condition on a dataset with gp.condition(dataset, jitter=1e-6).
The callable captures this immutable GP and can be compiled directly:
condition = eqx.filter_jit(gp.condition). Reuse it across datasets
with the same reserved block structure and dtypes. Values, locations,
noise and active counts may change without compiling again. To change
or differentiate model parameters, pass the GP into a compiled function.
Returns a posterior for the current contents on every call. This does not reuse a previous factorization. Dense work scales with the reserved scalar capacity, including unused slots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
FunctionalDataset
|
Named observation blocks with reserved locations, observed operator outputs, active counts and scalar noise variances. |
required |
jitter
|
float
|
Diagonal stabilization of the observation covariance.
Defaults to |
1e-06
|
Returns:
| Type | Description |
|---|---|
ConditionedPosterior[KernelType]
|
A posterior supporting prediction and sampling. Failed dense factorization propagates non-finite numerical results. |
Source code in src/gpex/gp.py
ConditioningState
ConditioningState(
gp: GaussianProcess[KernelType],
system: CovarianceSystem,
linear_system: LinearSystem,
index_map: IndexMap,
block_layout: tuple[tuple[int, int], ...],
)
Bases: Module
Outcome-independent covariance state created by prepare_conditioning.
Use GaussianProcess.prepare_conditioning to construct this state from a
design or dataset. Its solves act on flattened scalar observation outputs.
Source code in src/gpex/gp.py
block_layout
class-attribute
instance-attribute
solve
Solve the stabilized observation covariance system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
right_hand_side
|
FunctionalVector
|
Array with shape |
required |
Returns:
| Type | Description |
|---|---|
FunctionalVector
|
Solution with the same shape as |
Source code in src/gpex/gp.py
predict_covariance
predict_covariance(
query: FunctionalQuery,
) -> CovarianceResult
Return conditional latent covariance at a query, without outcome values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Locations and operators with the training input dimension. |
required |
Returns:
| Type | Description |
|---|---|
CovarianceResult
|
Full covariance of shape |
Source code in src/gpex/gp.py
predict_variance
predict_variance(
query: FunctionalQuery,
) -> StructuredValues
Return conditional latent variances without a full query covariance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Locations and operators with the training input dimension. |
required |
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Variances accessible by block name, without observation noise. Storage still includes the observation-query cross-covariance. |
Source code in src/gpex/gp.py
append
append(
locations: Locations, *, block: str
) -> ConditioningState[KernelType]
Activate locations in a declared block, retaining its operator/noise.
Existing measurements and numerical settings stay fixed. Shapes and index maps retain their reserved sizes. Unknown names and capacity overflow raise, including overflow under JIT.
Source code in src/gpex/gp.py
append_solve
append_solve(
locations: Locations,
solution: ObservationVector,
right_hand_side: ObservationVector,
*,
block: str,
) -> tuple[
ConditioningState[KernelType], ObservationVector
]
Activate locations and update a canonical-order vector solution.
solution and the new RHS both have the reserved scalar size. The
RHS must retain all existing active entries and be zero in unused slots.
Dense updates reuse the factor and update the existing coefficients.
Source code in src/gpex/gp.py
ConditionedPosterior
Bases: Module
An immutable posterior state supporting streaming updates.
observation_size
property
Number of flattened scalar observation functionals in the state.
predict_mean
predict_mean(query: FunctionalQuery) -> StructuredValues
Return posterior means in each query block's output shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Locations and operators with the training input dimension. |
required |
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Structured means with |
Source code in src/gpex/gp.py
predict_covariance
predict_covariance(
query: FunctionalQuery,
) -> CovarianceResult
predict_variance
predict_variance(
query: FunctionalQuery,
) -> StructuredValues
predict_marginals
predict_marginals(
query: FunctionalQuery,
) -> MarginalPrediction
Return latent means and marginal variances, sharing cross-covariance work.
The result contains named arrays in each query block's output shape and
can cross an outer jit or vmap boundary. Storage includes the
observation/query cross-covariance, but no full query covariance.
Observation noise is excluded.
Source code in src/gpex/gp.py
predict
predict(query: FunctionalQuery) -> Prediction
Return the joint latent mean and covariance at a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
FunctionalQuery
|
Named blocks of locations and linear operators to predict. |
required |
Returns:
| Type | Description |
|---|---|
Prediction
|
A |
Source code in src/gpex/gp.py
sample
sample(
key: PRNGKeyArray,
query: FunctionalQuery,
*,
sample_count: int = 1,
jitter: float = 1e-06,
) -> StructuredValues
Draw joint latent posterior samples at a fixed query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key; supply a fresh key for independent draws. |
required |
query
|
FunctionalQuery
|
Locations and linear operators to sample jointly. |
required |
sample_count
|
int
|
Number of draws. Defaults to 1. |
1
|
jitter
|
float
|
Diagonal stabilization for sampling. Defaults to |
1e-06
|
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Samples with |
Source code in src/gpex/gp.py
append
append(
locations: Locations,
values: FunctionalValues,
*,
block: str,
) -> ConditionedPosterior[KernelType]
Add observations to a declared block without enlarging storage.
locations has shape (m, d). values has shape
(m, *operator_output_shape) for the selected block. Its operator,
noise variance, model parameters and previous observations remain fixed.
Returns a new posterior; overflow raises instead of resizing.
Repeated fixed-shape batches into the same block reuse an outer JIT. Dense systems update their factor and coefficients through the Schur complement.
Source code in src/gpex/gp.py
gpex.results
Structured latent predictions and covariance results.
Prediction
Bases: Module
Joint latent predictions returned by ConditionedPosterior.predict.
Attributes:
| Name | Type | Description |
|---|---|---|
mean |
StructuredValues
|
Means accessible as |
covariance |
CovarianceResult
|
Full covariance, named cross-blocks, and marginal variances. |
MarginalPrediction
Bases: Module
Latent means and variances without a full query covariance.
Both fields contain flat arrays of shape (q,) and named views matching
each query block. Leading batch axes from vmap are preserved.
CovarianceResult
CovarianceResult(
full: CovarianceMatrix, index_map: IndexMap
)
Bases: Module
Covariance of the latent query outputs, without observation noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full
|
CovarianceMatrix
|
Dense covariance with shape |
required |
index_map
|
IndexMap
|
Static map between named blocks and flattened output indices. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
full |
CovarianceMatrix
|
Dense latent covariance. |
variance |
StructuredValues
|
Diagonal entries, accessible by block name in each block's shape. |
index_map |
IndexMap
|
Mapping used for named covariance blocks and variances. |
Source code in src/gpex/results.py
block
Return a named cross-covariance with shape (*left.shape, *right.shape).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_name
|
str
|
Row block name from the query. |
required |
right_name
|
str
|
Column block name from the query. |
required |
Returns:
| Type | Description |
|---|---|
CovarianceBlock
|
The covariance between the two blocks, preserving their output axes.
Leading batch axes introduced by |
Source code in src/gpex/results.py
gpex.prepared_query.PreparedQuery
PreparedQuery(
conditioning: ConditioningState, query: FunctionalQuery
)
Bases: Module
A fixed target and conditioning state cached for comparing measurements.
Construct with PreparedQuery(conditioning, query). Each *_after call
evaluates one proposal against the original conditioning state;
calls do not accumulate measurements. Prepare a new query after changing
the GP, observation design, or target. The cache is an immutable PyTree.
Candidate noise and the conditioning's jitter enter the small conditional
measurement system. Target covariance remains latent.
Storage is O(N*q + q*q) for N observations and q target outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conditioning
|
ConditioningState
|
Original conditioning state. |
required |
query
|
FunctionalQuery
|
Fixed target locations and operators. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
conditioning |
ConditioningState
|
Original conditioning state. |
covariance |
CovarianceResult
|
Target covariance before a proposed measurement. |
projection |
CovarianceProjection
|
Cached backend factors for observation-query reductions. |
Source code in src/gpex/prepared_query.py
covariance
instance-attribute
covariance: CovarianceResult = CovarianceResult(
symmetrize(prior - projection.gram()), query.index_map
)
predict_covariance_after
predict_covariance_after(
block: ObservationDesignBlock,
) -> CovarianceResult
Return target covariance after assimilating a proposed measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ObservationDesignBlock
|
Proposed measurement design, including its shared noise
variance. For observed data, pass |
required |
Returns:
| Type | Description |
|---|---|
CovarianceResult
|
Full latent target covariance, equivalent to appending the block and predicting at the target, up to numerical solver accuracy. Candidate coordinates, operator parameters, and noise can be differentiated through this operation. |
Source code in src/gpex/prepared_query.py
predict_variance_after
predict_variance_after(
block: ObservationDesignBlock,
) -> StructuredValues
Return target variances after a proposal without a full update matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ObservationDesignBlock
|
Proposed measurement design, including its shared noise
variance. For observed data, pass |
required |
Returns:
| Type | Description |
|---|---|
StructuredValues
|
Differentiable latent variances by target block name. Initial query preparation still stores the current full target covariance. |
Source code in src/gpex/prepared_query.py
Feature-based callable draws require a FeatureKernel. RBF and Matérn families
provide Fourier features, while custom feature kernels can use other bases.
GaussianProcess, ConditioningState, and ConditionedPosterior preserve the
kernel type so this requirement is visible to static type checkers.
gpex.feature_paths
Callable posterior draws using kernel-provided finite features.
FeaturePosteriorPath
FeaturePosteriorPath(
posterior: ConditionedPosterior[KernelType],
key: PRNGKeyArray,
*,
feature_count: int = 1024,
)
Bases: Module
A callable posterior draw built from a finite kernel feature map.
The path uses the kernel's random features for the prior and a pathwise
conditioning correction for the observations. Repeated calls evaluate the
same draw, so the object can be vectorized, differentiated, or passed to a
LinearOperator. Construct with
FeaturePosteriorPath(posterior, key). For exact samples at a fixed finite query,
use posterior.sample(key, query). Differentiating a finite feature
expansion beyond the GP's smoothness does not define a valid GP derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior
|
ConditionedPosterior[KernelType]
|
Conditioned GP whose kernel implements |
required |
key
|
PRNGKeyArray
|
JAX random key for this draw. |
required |
feature_count
|
int
|
Number of features. Defaults to 1024. For the built-in kernels, larger maps improve the prior approximation statistically. |
1024
|