uqregressors.bayesian.bbmm_gp
A wrapper for GPyTorch is created which implements BlackBox Matrix-Matrix Inference Gaussian Process regression (BBMM-GP) as described in Gardner et al., 2018
BBMM_GP
A wrapper around GPyTorch's ExactGP for regression with uncertainty quantification.
Supports custom kernels, optimizers, learning schedules, and logging. Outputs mean predictions and confidence intervals using predictive variance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the model instance. |
'BBMM_GP_Regressor'
|
kernel
|
Kernel
|
Covariance kernel. |
ScaleKernel(RBFKernel())
|
likelihood
|
Likelihood
|
Likelihood function used in GP. |
GaussianLikelihood()
|
alpha
|
float
|
Significance level for predictive intervals (e.g. 0.1 = 90% CI). |
0.1
|
requires_grad
|
bool
|
If True, returns tensors requiring gradients during prediction. |
False
|
learning_rate
|
float
|
Optimizer learning rate. |
0.001
|
epochs
|
int
|
Number of training epochs. |
200
|
optimizer_cls
|
Callable
|
Optimizer class (e.g., torch.optim.Adam). |
Adam
|
optimizer_kwargs
|
dict
|
Extra keyword arguments for the optimizer. |
None
|
scheduler_cls
|
Callable or None
|
Learning rate scheduler class. |
None
|
scheduler_kwargs
|
dict
|
Extra keyword arguments for the scheduler. |
None
|
loss_fn
|
Callable or None
|
Custom loss function. Defaults to negative log marginal likelihood. |
None
|
device
|
str
|
Device to train the model on ("cpu" or "cuda"). |
'cpu'
|
use_wandb
|
bool
|
If True, enables wandb logging. |
False
|
wandb_project
|
str or None
|
Name of the wandb project. |
None
|
wandb_run_name
|
str or None
|
Name of the wandb run. |
None
|
random_seed
|
int or None
|
Random seed for reproducibility. |
None
|
tuning_loggers
|
List[Logger]
|
Optional list of loggers from hyperparameter tuning. |
[]
|
Attributes:
Name | Type | Description |
---|---|---|
_loggers |
[list]
|
Logger of training loss |
Source code in uqregressors\bayesian\bbmm_gp.py
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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
fit(X, y)
Fits the GP model to training data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray or Tensor
|
Training features of shape (n_samples, n_features). |
required |
y
|
ndarray or Tensor
|
Training targets of shape (n_samples,). |
required |
Source code in uqregressors\bayesian\bbmm_gp.py
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 |
|
load(path, device='cpu', load_logs=False)
classmethod
Loads a saved BBMM_GP model from disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Path to saved model directory. |
required |
device
|
str
|
Device to map model to ("cpu" or "cuda"). |
'cpu'
|
load_logs
|
bool
|
If True, also loads training/tuning logs. |
False
|
Returns:
Type | Description |
---|---|
BBMM_GP
|
Loaded model instance. |
Source code in uqregressors\bayesian\bbmm_gp.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
mll_loss(preds, y)
Computes the negative log marginal likelihood (default loss function).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
preds
|
MultivariateNormal
|
GP predictive distribution. |
required |
y
|
Tensor
|
Ground truth targets. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Negative log marginal likelihood loss. |
Source code in uqregressors\bayesian\bbmm_gp.py
207 208 209 210 211 212 213 214 215 216 217 218 |
|
predict(X)
Predicts the target values with uncertainty estimates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Feature matrix of shape (n_samples, n_features). |
required |
Returns:
Type | Description |
---|---|
Union[Tuple[ndarray, ndarray, ndarray], Tuple[Tensor, Tensor, Tensor]]
|
Tuple containing: mean predictions, lower bound of the prediction interval, upper bound of the prediction interval. |
Note
If requires_grad
is False, all returned arrays are NumPy arrays.
Otherwise, they are PyTorch tensors with gradients.
Source code in uqregressors\bayesian\bbmm_gp.py
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 194 195 196 197 198 199 200 201 202 203 204 205 |
|
save(path)
Saves model configuration, weights, and training data to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Path to save directory. |
required |
Source code in uqregressors\bayesian\bbmm_gp.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
ExactGP
Bases: ExactGP
A custom GPyTorch Exact Gaussian Process model using a constant mean and a user-specified kernel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel
|
Kernel
|
Kernel defining the covariance structure of the GP. |
required |
train_x
|
Tensor
|
Training inputs of shape (n_samples, n_features). |
required |
train_y
|
Tensor
|
Training targets of shape (n_samples,). |
required |
likelihood
|
Likelihood
|
Likelihood function (e.g., GaussianLikelihood). |
required |
Source code in uqregressors\bayesian\bbmm_gp.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|