cagpjax
Computation-Aware Gaussian Processes for GPJax.
BlockDiagonalSparse
Bases: LinearOperator
Block-diagonal sparse linear operator.
This operator represents a block-diagonal matrix structure where the blocks are contiguous, and each contains a row vector, so that exactly one value is non-zero in each column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nz_values
|
Float[Array, N]
|
Non-zero values to be distributed across diagonal blocks. |
required |
n_blocks
|
int
|
Number of diagonal blocks in the matrix. |
required |
Examples
>>> import jax.numpy as jnp
>>> from cagpjax.operators import BlockDiagonalSparse
>>>
>>> # Create a 3x6 block-diagonal matrix with 3 blocks
>>> nz_values = jnp.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
>>> op = BlockDiagonalSparse(nz_values, n_blocks=3)
>>> print(op.shape)
(3, 6)
>>>
>>> # Apply to a vector
>>> x = jnp.ones(6)
>>> result = op @ x
Source code in src/cagpjax/operators/block_diagonal_sparse.py
BlockSparsePolicy
Bases: AbstractBatchLinearSolverPolicy
Block-sparse linear solver policy.
This policy uses a fixed block-diagonal sparse structure to define independent learnable actions. The matrix has the following structure:
These are stacked and stored as a single trainable parameter nz_values
.
Source code in src/cagpjax/policies/block_sparse.py
n_actions
property
Number of actions to be used.
__init__(n_actions, n=None, nz_values=None, key=None, **kwargs)
Initialize the block sparse policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_actions
|
int
|
Number of actions to use. |
required |
n
|
int | None
|
Number of rows and columns of the full operator. Must be provided if |
None
|
nz_values
|
Float[Array, N] | Variable[Float[Array, N]] | None
|
Non-zero values of the block-diagonal sparse matrix (shape |
None
|
key
|
PRNGKeyArray | None
|
Random key for sampling actions if |
None
|
**kwargs
|
Additional keyword arguments for |
{}
|
Source code in src/cagpjax/policies/block_sparse.py
to_actions(A)
Convert to block diagonal sparse action operators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
LinearOperator
|
Linear operator (unused). |
required |
Returns:
Type | Description |
---|---|
LinearOperator
|
Transposed[BlockDiagonalSparse]: Sparse action structure representing the blocks. |
Source code in src/cagpjax/policies/block_sparse.py
ComputationAwareGP
Bases: AbstractComputationAwareGP
Computation-aware Gaussian Process model.
This model implements scalable GP inference by using batch linear solver policies to project the kernel and data to a lower-dimensional subspace, while accounting for the extra uncertainty imposed by observing only this subspace.
Attributes:
Name | Type | Description |
---|---|---|
posterior |
The original (exact) posterior. |
|
policy |
AbstractBatchLinearSolverPolicy
|
The batch linear solver policy. |
jitter |
ScalarFloat
|
Numerical jitter for stability. |
Notes
- Only single-output models are currently supported.
Source code in src/cagpjax/models/cagp.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
is_conditioned
property
Whether the model has been conditioned on training data.
__init__(posterior, policy, jitter=1e-06)
Initialize the Computation-Aware GP model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
posterior
|
ConjugatePosterior
|
GPJax conjugate posterior. |
required |
policy
|
AbstractBatchLinearSolverPolicy
|
The batch linear solver policy that defines the subspace into which the data is projected. |
required |
jitter
|
ScalarFloat
|
A small positive constant added to the diagonal of a covariance matrix when necessary to ensure numerical stability. |
1e-06
|
Source code in src/cagpjax/models/cagp.py
condition(train_data)
Compute and store the projected quantities of the conditioned GP posterior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_data
|
Dataset
|
The training data used to fit the GP. |
required |
Source code in src/cagpjax/models/cagp.py
predict(test_inputs=None)
Compute the predictive distribution of the GP at the test inputs.
condition
must be called before this method can be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_inputs
|
Float[Array, 'N D'] | None
|
The test inputs at which to make predictions. If not provided, predictions are made at the training inputs. |
None
|
Returns:
Name | Type | Description |
---|---|---|
GaussianDistribution |
GaussianDistribution
|
The predictive distribution of the GP at the test inputs. |
Source code in src/cagpjax/models/cagp.py
prior_kl()
Compute KL divergence between CaGP posterior and GP prior..
Calculates \(\mathrm{KL}[q(f) || p(f)]\), where \(q(f)\) is the CaGP posterior approximation and \(p(f)\) is the GP prior.
condition
must be called before this method can be used.
Returns:
Type | Description |
---|---|
ScalarFloat
|
KL divergence value (scalar). |
Source code in src/cagpjax/models/cagp.py
LanczosPolicy
Bases: AbstractBatchLinearSolverPolicy
Lanczos-based policy for eigenvalue decomposition approximation.
This policy uses the Lanczos algorithm to compute the top n_actions
eigenvectors
of the linear operator \(A\).
Attributes:
Name | Type | Description |
---|---|---|
n_actions |
int
|
Number of Lanczos vectors/actions to compute. |
key |
PRNGKeyArray | None
|
Random key for reproducible Lanczos iterations. |
Source code in src/cagpjax/policies/lanczos.py
__init__(n_actions, key=None)
Initialize the Lanczos policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_actions
|
int
|
Number of Lanczos vectors to compute. |
required |
key
|
PRNGKeyArray | None
|
Random key for initialization. |
None
|
Source code in src/cagpjax/policies/lanczos.py
to_actions(A)
Compute action matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
LinearOperator
|
Symmetric linear operator representing the linear system. |
required |
Returns:
Type | Description |
---|---|
LinearOperator
|
Linear operator containing the Lanczos vectors as columns. |