API
AbstractGP
AbstractGP(seqs, num_tasks, default_task, solo_task, scale, lengthscales, noise, factor_task_kernel, rank_factor_task_kernel, noise_task_kernel, device, tfs_scale, tfs_lengthscales, tfs_noise, tfs_factor_task_kernel, tfs_noise_task_kernel, requires_grad_scale, requires_grad_lengthscales, requires_grad_noise, requires_grad_factor_task_kernel, requires_grad_noise_task_kernel, shape_batch, shape_scale, shape_lengthscales, shape_noise, shape_factor_task_kernel, shape_noise_task_kernel, derivatives, derivatives_coeffs, adaptive_nugget)
Bases: Module
Source code in fastgps/abstract_gp.py
13 14 15 16 17 18 19 20 21 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 |
|
scale
property
scale
Kernel scale parameter.
lengthscales
property
lengthscales
Kernel lengthscale parameter.
noise
property
noise
Noise parameter.
factor_task_kernel
property
factor_task_kernel
Factor for the task kernel parameter.
noise_task_kernel
property
noise_task_kernel
Noise for the task kernel parameter.
gram_matrix_tasks
property
gram_matrix_tasks
Gram matrix for the task kernel.
coeffs
property
coeffs
Coefficients \(\mathsf{K}^{-1} \boldsymbol{y}\).
x
property
x
Current sampling locations.
A torch.Tensor
for single task problems.
A list
for multitask problems.
y
property
y
Current sampling values.
A torch.Tensor
for single task problems.
A list
for multitask problems.
fit
fit(loss_metric='MLL', iterations=5000, lr=None, optimizer=None, stop_crit_improvement_threshold=0.05, stop_crit_wait_iterations=10, store_hists=False, store_loss_hist=False, store_scale_hist=False, store_lengthscales_hist=False, store_noise_hist=False, store_task_kernel_hist=False, verbose=5, verbose_indent=4, masks=None, cv_weights=1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss_metric
|
str
|
either "MLL" (Marginal Log Likelihood) or "CV" (Cross Validation) or "GCV" (Generalized CV) |
'MLL'
|
iterations
|
int
|
number of optimization iterations |
5000
|
lr
|
float
|
learning rate for default optimizer |
None
|
optimizer
|
Optimizer
|
optimizer defaulted to |
None
|
stop_crit_improvement_threshold
|
float
|
stop fitting when the maximum number of iterations is reached or the best loss is note reduced by |
0.05
|
stop_crit_wait_iterations
|
int
|
number of iterations to wait for improved loss before early stopping, see the argument description for |
10
|
store_hists
|
bool
|
if True then store all hists, otherwise specify individually with the following arguments |
False
|
store_loss_hist
|
bool
|
if |
False
|
store_scale_hist
|
bool
|
if |
False
|
store_lengthscales_hist
|
bool
|
if |
False
|
store_noise_hist
|
bool
|
if |
False
|
store_task_kernel_hist
|
bool
|
if |
False
|
verbose
|
int
|
log every |
5
|
verbose_indent
|
int
|
size of the indent to be applied when logging, helpful for logging multiple models |
4
|
masks
|
Tensor
|
only optimize outputs corresponding to |
None
|
cv_weights
|
Union[str, Tensor]
|
weights for cross validation |
1
|
Returns:
Name | Type | Description |
---|---|---|
data |
dict
|
iteration data which, dependeing on storage arguments, may include keys in
|
Source code in fastgps/abstract_gp.py
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 |
|
get_x_next
get_x_next(n, task=None)
Get the next sampling locations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
Union[int, Tensor]
|
maximum sample index per task |
required |
task
|
Union[int, Tensor]
|
task index |
None
|
Returns:
Name | Type | Description |
---|---|---|
x_next |
Union[Tensor, List]
|
next samples in the sequence |
Source code in fastgps/abstract_gp.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
add_y_next
add_y_next(y_next, task=None)
Add samples to the GP.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_next
|
Union[Tensor, List]
|
new function evaluations at next sampling locations |
required |
task
|
Union[int, Tensor]
|
task index |
None
|
Source code in fastgps/abstract_gp.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
post_mean
post_mean(x, task=None, eval=True)
Posterior mean.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor[N, d]
|
sampling locations |
required |
task
|
Union[int, Tensor[T]]
|
task index |
None
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pmean |
Tensor[..., T, N]
|
posterior mean |
Source code in fastgps/abstract_gp.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
post_var
post_var(x, task=None, n=None, eval=True)
Posterior variance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor[N, d]
|
sampling locations |
required |
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
n
|
Union[int, Tensor[num_tasks]]
|
number of points at which to evaluate the posterior cubature variance. |
None
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pvar |
Tensor[T, N]
|
posterior variance |
Source code in fastgps/abstract_gp.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
post_cov
post_cov(x0, x1, task0=None, task1=None, n=None, eval=True)
Posterior covariance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
Tensor[N, d]
|
left sampling locations |
required |
x1
|
Tensor[M, d]
|
right sampling locations |
required |
task0
|
Union[int, Tensor[T1]]
|
left task index |
None
|
task1
|
Union[int, Tensor[T2]]
|
right task index |
None
|
n
|
Union[int, Tensor[num_tasks]]
|
number of points at which to evaluate the posterior cubature variance. |
None
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pcov |
Tensor[T1, T2, N, M]
|
posterior covariance matrix |
Source code in fastgps/abstract_gp.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
post_error
post_error(x, task=None, n=None, confidence=0.99, eval=True)
Posterior error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor[N, d]
|
sampling locations |
required |
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
n
|
Union[int, Tensor[num_tasks]]
|
number of points at which to evaluate the posterior cubature variance. |
None
|
eval
|
bool
|
if |
True
|
confidence
|
float
|
confidence level in \((0,1)\) for the credible interval |
0.99
|
Returns:
Name | Type | Description |
---|---|---|
cvar |
Tensor[T]
|
posterior variance |
quantile |
float64
|
|
perror |
Tensor[T]
|
posterior error |
Source code in fastgps/abstract_gp.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
post_ci
post_ci(x, task=None, confidence=0.99, eval=True)
Posterior credible interval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor[N, d]
|
sampling locations |
required |
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
confidence
|
float
|
confidence level in \((0,1)\) for the credible interval |
0.99
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pmean |
Tensor[..., T, N]
|
posterior mean |
pvar |
Tensor[T, N]
|
posterior variance |
quantile |
float64
|
|
pci_low |
Tensor[..., T, N]
|
posterior credible interval lower bound |
pci_high |
Tensor[..., T, N]
|
posterior credible interval upper bound |
Source code in fastgps/abstract_gp.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
|
post_cubature_mean
post_cubature_mean(task=None, eval=True)
Posterior cubature mean.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eval
|
bool
|
if |
True
|
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
Returns:
Name | Type | Description |
---|---|---|
pcmean |
Tensor[..., T]
|
posterior cubature mean |
Source code in fastgps/abstract_gp.py
527 528 529 530 531 532 533 534 535 536 537 538 |
|
post_cubature_var
post_cubature_var(task=None, n=None, eval=True)
Posterior cubature variance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
n
|
Union[int, Tensor[num_tasks]]
|
number of points at which to evaluate the posterior cubature variance. |
None
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pcvar |
Tensor[T]
|
posterior cubature variance |
Source code in fastgps/abstract_gp.py
539 540 541 542 543 544 545 546 547 548 549 550 551 |
|
post_cubature_cov
post_cubature_cov(task0=None, task1=None, n=None, eval=True)
Posterior cubature covariance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task0
|
Union[int, Tensor[T1]]
|
task indices |
None
|
task1
|
Union[int, Tensor[T2]]
|
task indices |
None
|
n
|
Union[int, Tensor[num_tasks]]
|
number of points at which to evaluate the posterior cubature covariance. |
None
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pcvar |
Tensor[T1, T2]
|
posterior cubature covariance |
Source code in fastgps/abstract_gp.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
post_cubature_error
post_cubature_error(task=None, n=None, confidence=0.99, eval=True)
Posterior cubature error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
n
|
Union[int, Tensor[num_tasks]]
|
number of points at which to evaluate the posterior cubature variance. |
None
|
eval
|
bool
|
if |
True
|
confidence
|
float
|
confidence level in \((0,1)\) for the credible interval |
0.99
|
Returns:
Name | Type | Description |
---|---|---|
pcvar |
Tensor[T]
|
posterior cubature variance |
quantile |
float64
|
|
pcerror |
Tensor[T]
|
posterior cubature error |
Source code in fastgps/abstract_gp.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
post_cubature_ci
post_cubature_ci(task=None, confidence=0.99, eval=True)
Posterior cubature credible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Union[int, Tensor[T]]
|
task indices |
None
|
confidence
|
float
|
confidence level in \((0,1)\) for the credible interval |
0.99
|
eval
|
bool
|
if |
True
|
Returns:
Name | Type | Description |
---|---|---|
pcmean |
Tensor[..., T]
|
posterior cubature mean |
pcvar |
Tensor[T]
|
posterior cubature variance |
quantile |
float64
|
|
pcci_low |
Tensor[..., T]
|
posterior cubature credible interval lower bound |
pcci_high |
Tensor[..., T]
|
posterior cubature credible interval upper bound |
Source code in fastgps/abstract_gp.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
|
StandardGP
StandardGP(seqs, num_tasks=None, seed_for_seq=None, scale=1.0, lengthscales=1.0, noise=0.0001, factor_task_kernel=1.0, rank_factor_task_kernel=None, noise_task_kernel=1.0, device='cpu', tfs_scale=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_lengthscales=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_noise=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_factor_task_kernel=(lambda x: x, lambda x: x), tfs_noise_task_kernel=(lambda x: torch.log(x), lambda x: torch.exp(x)), requires_grad_scale=True, requires_grad_lengthscales=True, requires_grad_noise=False, requires_grad_factor_task_kernel=None, requires_grad_noise_task_kernel=None, shape_batch=torch.Size([]), shape_scale=torch.Size([1]), shape_lengthscales=None, shape_noise=torch.Size([1]), shape_factor_task_kernel=None, shape_noise_task_kernel=None, derivatives=None, derivatives_coeffs=None, kernel_class='Gaussian', adaptive_nugget=True)
Bases: AbstractGP
Standard Gaussian process regression
Examples:
>>> torch.set_default_dtype(torch.float64)
>>> def f_ackley(x, a=20, b=0.2, c=2*np.pi, scaling=32.768):
... # https://www.sfu.ca/~ssurjano/ackley.html
... assert x.ndim==2
... x = 2*scaling*x-scaling
... t1 = a*torch.exp(-b*torch.sqrt(torch.mean(x**2,1)))
... t2 = torch.exp(torch.mean(torch.cos(c*x),1))
... t3 = a+np.exp(1)
... y = -t1-t2+t3
... return y
>>> n = 2**6
>>> d = 2
>>> sgp = StandardGP(qmcpy.DigitalNetB2(dimension=d,seed=7))
>>> x_next = sgp.get_x_next(n)
>>> y_next = f_ackley(x_next)
>>> sgp.add_y_next(y_next)
>>> rng = torch.Generator().manual_seed(17)
>>> x = torch.rand((2**7,d),generator=rng)
>>> y = f_ackley(x)
>>> pmean = sgp.post_mean(x)
>>> pmean.shape
torch.Size([128])
>>> torch.linalg.norm(y-pmean)/torch.linalg.norm(y)
tensor(0.0771)
>>> torch.linalg.norm(sgp.post_mean(sgp.x)-sgp.y)/torch.linalg.norm(y)
tensor(0.0559)
>>> data = sgp.fit(verbose=0)
>>> list(data.keys())
['iterations']
>>> torch.linalg.norm(y-sgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0562)
>>> z = torch.rand((2**8,d),generator=rng)
>>> pcov = sgp.post_cov(x,z)
>>> pcov.shape
torch.Size([128, 256])
>>> pcov = sgp.post_cov(x,x)
>>> pcov.shape
torch.Size([128, 128])
>>> assert (pcov.diagonal()>=0).all()
>>> pvar = sgp.post_var(x)
>>> pvar.shape
torch.Size([128])
>>> assert torch.allclose(pcov.diagonal(),pvar)
>>> pmean,pstd,q,ci_low,ci_high = sgp.post_ci(x,confidence=0.99)
>>> ci_low.shape
torch.Size([128])
>>> ci_high.shape
torch.Size([128])
>>> sgp.post_cubature_mean()
tensor(20.0279)
>>> sgp.post_cubature_var()
tensor(0.0043)
>>> pcmean,pcvar,q,pcci_low,pcci_high = sgp.post_cubature_ci(confidence=0.99)
>>> pcci_low
tensor(19.8582)
>>> pcci_high
tensor(20.1976)
>>> pcov_future = sgp.post_cov(x,z,n=2*n)
>>> pvar_future = sgp.post_var(x,n=2*n)
>>> pcvar_future = sgp.post_cubature_var(n=2*n)
>>> x_next = sgp.get_x_next(2*n)
>>> y_next = f_ackley(x_next)
>>> sgp.add_y_next(y_next)
>>> torch.linalg.norm(y-sgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.1060)
>>> assert torch.allclose(sgp.post_cov(x,z),pcov_future)
>>> assert torch.allclose(sgp.post_var(x),pvar_future)
>>> assert torch.allclose(sgp.post_cubature_var(),pcvar_future)
>>> data = sgp.fit(verbose=False)
>>> torch.linalg.norm(y-sgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0740)
>>> x_next = sgp.get_x_next(4*n)
>>> y_next = f_ackley(x_next)
>>> sgp.add_y_next(y_next)
>>> torch.linalg.norm(y-sgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0722)
>>> data = sgp.fit(verbose=False)
>>> torch.linalg.norm(y-sgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0516)
>>> pcov_16n = sgp.post_cov(x,z,n=16*n)
>>> pvar_16n = sgp.post_var(x,n=16*n)
>>> pcvar_16n = sgp.post_cubature_var(n=16*n)
>>> x_next = sgp.get_x_next(16*n)
>>> y_next = f_ackley(x_next)
>>> sgp.add_y_next(y_next)
>>> assert torch.allclose(sgp.post_cov(x,z),pcov_16n)
>>> assert torch.allclose(sgp.post_var(x),pvar_16n)
>>> assert torch.allclose(sgp.post_cubature_var(),pcvar_16n)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seqs
|
Union[int,qmcpy.DiscreteDistribution,List]]
|
list of sequence generators. If an int
qmcpy.DiscreteDistribution docs for more info.
|
required |
num_tasks
|
int
|
number of tasks |
None
|
seed_for_seq
|
int
|
seed used for digital net randomization |
None
|
scale
|
float
|
kernel global scaling parameter |
1.0
|
lengthscales
|
Union[Tensor[d], float]
|
vector of kernel lengthscales.
If a scalar is passed in then |
1.0
|
noise
|
float
|
positive noise variance i.e. nugget term |
0.0001
|
factor_task_kernel
|
Union[Tensor[num_tasks, rank_factor_task_kernel], int]
|
for \(F\) the |
1.0
|
rank_factor_task_kernel
|
int
|
see the description of |
None
|
noise_task_kernel
|
Union[Tensor[num_tasks], float]
|
see the description of |
1.0
|
device
|
device
|
torch device which is required to support |
'cpu'
|
tfs_scale
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_lengthscales
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_noise
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_factor_task_kernel
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: x, lambda x: x)
|
tfs_noise_task_kernel
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
requires_grad_scale
|
bool
|
wheather or not to optimize the scale parameter |
True
|
requires_grad_lengthscales
|
bool
|
wheather or not to optimize lengthscale parameters |
True
|
requires_grad_noise
|
bool
|
wheather or not to optimize the noise parameter |
False
|
requires_grad_factor_task_kernel
|
bool
|
wheather or not to optimize the factor for the task kernel |
None
|
requires_grad_noise_task_kernel
|
bool
|
wheather or not to optimize the noise for the task kernel |
None
|
shape_batch
|
Size
|
shape of the batch output for each task |
Size([])
|
shape_scale
|
Size
|
shape of the scale parameter, defaults to |
Size([1])
|
shape_lengthscales
|
Size
|
shape of the lengthscales parameter, defaults to |
None
|
shape_noise
|
Size
|
shape of the noise parameter, defaults to |
Size([1])
|
shape_factor_task_kernel
|
Size
|
shape of the factor for the task kernel, defaults to |
None
|
shape_noise_task_kernel
|
Size
|
shape of the noise for the task kernel, defaults to |
None
|
derivatives
|
list
|
list of derivative orders e.g. to include a function and its gradient set
|
None
|
derivatives_coeffs
|
list
|
list of derivative coefficients where if |
None
|
adaptive_nugget
|
bool
|
if True, use the adaptive nugget which modifies noises based on trace ratios. |
True
|
Source code in fastgps/standard_gp.py
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 |
|
AbstractFastGP
AbstractFastGP(alpha, ft, ift, *args, **kwargs)
Bases: AbstractGP
Source code in fastgps/abstract_fast_gp.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
ft
ft(x)
One dimensional fast transform along the last dimenions.
For FastGPLattice
this is the orthonormal Fast Fourier Transform (FFT).
For FastGPDigitalNetB2
this is the orthonormal Fast Walsh Hadamard Transform (FWHT).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
inputs to be transformed along the last dimension. Require |
required |
Returns:
Name | Type | Description |
---|---|---|
y |
Tensor
|
transformed inputs with the same shape as |
Source code in fastgps/abstract_fast_gp.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
ift
ift(x)
One dimensional inverse fast transform along the last dimenions.
For FastGPLattice
this is the orthonormal Inverse Fast Fourier Transform (IFFT).
For FastGPDigitalNetB2
this is the orthonormal Fast Walsh Hadamard Transform (FWHT).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
inputs to be transformed along the last dimension. Require |
required |
Returns:
Name | Type | Description |
---|---|---|
y |
Tensor
|
transformed inputs with the same shape as |
Source code in fastgps/abstract_fast_gp.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
FastGPLattice
FastGPLattice(seqs, num_tasks=None, seed_for_seq=None, alpha=2, scale=1.0, lengthscales=1.0, noise=1e-08, factor_task_kernel=1.0, rank_factor_task_kernel=None, noise_task_kernel=1.0, device='cpu', tfs_scale=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_lengthscales=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_noise=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_factor_task_kernel=(lambda x: x, lambda x: x), tfs_noise_task_kernel=(lambda x: torch.log(x), lambda x: torch.exp(x)), requires_grad_scale=True, requires_grad_lengthscales=True, requires_grad_noise=False, requires_grad_factor_task_kernel=None, requires_grad_noise_task_kernel=None, shape_batch=torch.Size([]), shape_scale=torch.Size([1]), shape_lengthscales=None, shape_noise=torch.Size([1]), shape_factor_task_kernel=None, shape_noise_task_kernel=None, derivatives=None, derivatives_coeffs=None, compile_fts=False, compile_fts_kwargs={}, adaptive_nugget=False)
Bases: AbstractFastGP
Fast Gaussian process regression using lattice points and shift invariant kernels
Examples:
>>> torch.set_default_dtype(torch.float64)
>>> def f_ackley(x, a=20, b=0.2, c=2*np.pi, scaling=32.768):
... # https://www.sfu.ca/~ssurjano/ackley.html
... assert x.ndim==2
... x = 2*scaling*x-scaling
... t1 = a*torch.exp(-b*torch.sqrt(torch.mean(x**2,1)))
... t2 = torch.exp(torch.mean(torch.cos(c*x),1))
... t3 = a+np.exp(1)
... y = -t1-t2+t3
... return y
>>> n = 2**10
>>> d = 2
>>> fgp = FastGPLattice(seqs = qmcpy.Lattice(dimension=d,seed=7))
>>> x_next = fgp.get_x_next(n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> rng = torch.Generator().manual_seed(17)
>>> x = torch.rand((2**7,d),generator=rng)
>>> y = f_ackley(x)
>>> pmean = fgp.post_mean(x)
>>> pmean.shape
torch.Size([128])
>>> torch.linalg.norm(y-pmean)/torch.linalg.norm(y)
tensor(0.0348)
>>> assert torch.allclose(fgp.post_mean(fgp.x),fgp.y,atol=1e-3)
>>> fgp.post_cubature_mean()
tensor(20.1842)
>>> fgp.post_cubature_var()
tensor(7.0015e-09)
>>> data = fgp.fit(verbose=0)
>>> list(data.keys())
['iterations']
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0361)
>>> z = torch.rand((2**8,d),generator=rng)
>>> pcov = fgp.post_cov(x,z)
>>> pcov.shape
torch.Size([128, 256])
>>> pcov = fgp.post_cov(x,x)
>>> pcov.shape
torch.Size([128, 128])
>>> assert (pcov.diagonal()>=0).all()
>>> pvar = fgp.post_var(x)
>>> pvar.shape
torch.Size([128])
>>> assert torch.allclose(pcov.diagonal(),pvar)
>>> pmean,pstd,q,ci_low,ci_high = fgp.post_ci(x,confidence=0.99)
>>> ci_low.shape
torch.Size([128])
>>> ci_high.shape
torch.Size([128])
>>> fgp.post_cubature_mean()
tensor(20.1842)
>>> fgp.post_cubature_var()
tensor(3.1129e-06)
>>> pcmean,pcvar,q,pcci_low,pcci_high = fgp.post_cubature_ci(confidence=0.99)
>>> pcci_low
tensor(20.1797)
>>> pcci_high
tensor(20.1888)
>>> pcov_future = fgp.post_cov(x,z,n=2*n)
>>> pvar_future = fgp.post_var(x,n=2*n)
>>> pcvar_future = fgp.post_cubature_var(n=2*n)
>>> x_next = fgp.get_x_next(2*n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0304)
>>> assert torch.allclose(fgp.post_cov(x,z),pcov_future)
>>> assert torch.allclose(fgp.post_var(x),pvar_future)
>>> assert torch.allclose(fgp.post_cubature_var(),pcvar_future)
>>> data = fgp.fit(verbose=False)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0274)
>>> x_next = fgp.get_x_next(4*n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0277)
>>> data = fgp.fit(verbose=False)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0276)
>>> pcov_16n = fgp.post_cov(x,z,n=16*n)
>>> pvar_16n = fgp.post_var(x,n=16*n)
>>> pcvar_16n = fgp.post_cubature_var(n=16*n)
>>> x_next = fgp.get_x_next(16*n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> assert torch.allclose(fgp.post_cov(x,z),pcov_16n)
>>> assert torch.allclose(fgp.post_var(x),pvar_16n)
>>> assert torch.allclose(fgp.post_cubature_var(),pcvar_16n)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seqs
|
[int, Lattice, List]
|
list of lattice sequence generators
with order="NATURAL" and randomize in
qmcpy.Lattice docs for more info
|
required |
num_tasks
|
int
|
number of tasks |
None
|
seed_for_seq
|
int
|
seed used for lattice randomization |
None
|
alpha
|
int
|
smoothness parameter |
2
|
scale
|
float
|
kernel global scaling parameter |
1.0
|
lengthscales
|
Union[Tensor[d], float]
|
vector of kernel lengthscales.
If a scalar is passed in then |
1.0
|
noise
|
float
|
positive noise variance i.e. nugget term |
1e-08
|
factor_task_kernel
|
Union[Tensor[num_tasks, rank_factor_task_kernel], int]
|
for \(F\) the |
1.0
|
rank_factor_task_kernel
|
int
|
see the description of |
None
|
noise_task_kernel
|
Union[Tensor[num_tasks], float]
|
see the description of |
1.0
|
device
|
device
|
torch device which is required to support |
'cpu'
|
tfs_scale
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_lengthscales
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_noise
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_factor_task_kernel
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: x, lambda x: x)
|
tfs_noise_task_kernel
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
requires_grad_scale
|
bool
|
wheather or not to optimize the scale parameter |
True
|
requires_grad_lengthscales
|
bool
|
wheather or not to optimize lengthscale parameters |
True
|
requires_grad_noise
|
bool
|
wheather or not to optimize the noise parameter |
False
|
requires_grad_factor_task_kernel
|
bool
|
wheather or not to optimize the factor for the task kernel |
None
|
requires_grad_noise_task_kernel
|
bool
|
wheather or not to optimize the noise for the task kernel |
None
|
shape_batch
|
Size
|
shape of the batch output for each task |
Size([])
|
shape_scale
|
Size
|
shape of the scale parameter, defaults to |
Size([1])
|
shape_lengthscales
|
Size
|
shape of the lengthscales parameter, defaults to |
None
|
shape_noise
|
Size
|
shape of the noise parameter, defaults to |
Size([1])
|
shape_factor_task_kernel
|
Size
|
shape of the factor for the task kernel, defaults to |
None
|
shape_noise_task_kernel
|
Size
|
shape of the noise for the task kernel, defaults to |
None
|
derivatives
|
list
|
list of derivative orders e.g. to include a function and its gradient set
|
None
|
derivatives_coeffs
|
list
|
list of derivative coefficients where if |
None
|
compile_fts
|
bool
|
if |
False
|
compile_fts_kwargs
|
dict
|
keyword arguments to |
{}
|
adaptive_nugget
|
bool
|
if True, use the adaptive nugget which modifies noises based on trace ratios. |
False
|
Source code in fastgps/fast_gp_lattice.py
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 |
|
FastGPDigitalNetB2
FastGPDigitalNetB2(seqs, num_tasks=None, seed_for_seq=None, alpha=2, scale=1.0, lengthscales=1.0, noise=1e-16, factor_task_kernel=1.0, rank_factor_task_kernel=None, noise_task_kernel=1.0, device='cpu', tfs_scale=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_lengthscales=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_noise=(lambda x: torch.log(x), lambda x: torch.exp(x)), tfs_factor_task_kernel=(lambda x: x, lambda x: x), tfs_noise_task_kernel=(lambda x: torch.log(x), lambda x: torch.exp(x)), requires_grad_scale=True, requires_grad_lengthscales=True, requires_grad_noise=False, requires_grad_factor_task_kernel=None, requires_grad_noise_task_kernel=None, shape_batch=torch.Size([]), shape_scale=torch.Size([1]), shape_lengthscales=None, shape_noise=torch.Size([1]), shape_factor_task_kernel=None, shape_noise_task_kernel=None, derivatives=None, derivatives_coeffs=None, compile_fts=False, compile_fts_kwargs={}, adaptive_nugget=False)
Bases: AbstractFastGP
Fast Gaussian process regression using digitally shifted digital nets paired with digitally shift invariant kernels
Examples:
>>> torch.set_default_dtype(torch.float64)
>>> def f_ackley(x, a=20, b=0.2, c=2*np.pi, scaling=32.768):
... # https://www.sfu.ca/~ssurjano/ackley.html
... assert x.ndim==2
... x = 2*scaling*x-scaling
... t1 = a*torch.exp(-b*torch.sqrt(torch.mean(x**2,1)))
... t2 = torch.exp(torch.mean(torch.cos(c*x),1))
... t3 = a+np.exp(1)
... y = -t1-t2+t3
... return y
>>> n = 2**10
>>> d = 2
>>> fgp = FastGPDigitalNetB2(qmcpy.DigitalNetB2(dimension=d,seed=7))
>>> x_next = fgp.get_x_next(n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> rng = torch.Generator().manual_seed(17)
>>> x = torch.rand((2**7,d),generator=rng)
>>> y = f_ackley(x)
>>> pmean = fgp.post_mean(x)
>>> pmean.shape
torch.Size([128])
>>> torch.linalg.norm(y-pmean)/torch.linalg.norm(y)
tensor(0.0336)
>>> assert torch.allclose(fgp.post_mean(fgp.x),fgp.y)
>>> data = fgp.fit(verbose=0)
>>> list(data.keys())
['iterations']
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0355)
>>> z = torch.rand((2**8,d),generator=rng)
>>> pcov = fgp.post_cov(x,z)
>>> pcov.shape
torch.Size([128, 256])
>>> pcov = fgp.post_cov(x,x)
>>> pcov.shape
torch.Size([128, 128])
>>> assert (pcov.diagonal()>=0).all()
>>> pvar = fgp.post_var(x)
>>> pvar.shape
torch.Size([128])
>>> assert torch.allclose(pcov.diagonal(),pvar)
>>> pmean,pstd,q,ci_low,ci_high = fgp.post_ci(x,confidence=0.99)
>>> ci_low.shape
torch.Size([128])
>>> ci_high.shape
torch.Size([128])
>>> fgp.post_cubature_mean()
tensor(20.1896)
>>> fgp.post_cubature_var()
tensor(0.0002)
>>> pcmean,pcvar,q,pcci_low,pcci_high = fgp.post_cubature_ci(confidence=0.99)
>>> pcci_low
tensor(20.1564)
>>> pcci_high
tensor(20.2228)
>>> pcov_future = fgp.post_cov(x,z,n=2*n)
>>> pvar_future = fgp.post_var(x,n=2*n)
>>> pcvar_future = fgp.post_cubature_var(n=2*n)
>>> x_next = fgp.get_x_next(2*n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0258)
>>> assert torch.allclose(fgp.post_cov(x,z),pcov_future)
>>> assert torch.allclose(fgp.post_var(x),pvar_future)
>>> assert torch.allclose(fgp.post_cubature_var(),pcvar_future)
>>> data = fgp.fit(verbose=False)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0259)
>>> x_next = fgp.get_x_next(4*n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0191)
>>> data = fgp.fit(verbose=False)
>>> torch.linalg.norm(y-fgp.post_mean(x))/torch.linalg.norm(y)
tensor(0.0187)
>>> pcov_16n = fgp.post_cov(x,z,n=16*n)
>>> pvar_16n = fgp.post_var(x,n=16*n)
>>> pcvar_16n = fgp.post_cubature_var(n=16*n)
>>> x_next = fgp.get_x_next(16*n)
>>> y_next = f_ackley(x_next)
>>> fgp.add_y_next(y_next)
>>> assert torch.allclose(fgp.post_cov(x,z),pcov_16n)
>>> assert torch.allclose(fgp.post_var(x),pvar_16n)
>>> assert torch.allclose(fgp.post_cubature_var(),pcvar_16n)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seqs
|
Union[int,qmcpy.DigitalNetB2,List]]
|
list of digital sequence generators in base \(b=2\)
with order="NATURAL" and randomize in
qmcpy.DigitalNetB2 docs for more info.
If num_tasks==1 then randomize may be in ["FALSE","DS","LMS","LMS_DS"] .
|
required |
num_tasks
|
int
|
number of tasks |
None
|
seed_for_seq
|
int
|
seed used for digital net randomization |
None
|
alpha
|
int
|
smoothness parameter |
2
|
scale
|
float
|
kernel global scaling parameter |
1.0
|
lengthscales
|
Union[Tensor[d], float]
|
vector of kernel lengthscales.
If a scalar is passed in then |
1.0
|
noise
|
float
|
positive noise variance i.e. nugget term |
1e-16
|
factor_task_kernel
|
Union[Tensor[num_tasks, rank_factor_task_kernel], int]
|
for \(F\) the |
1.0
|
rank_factor_task_kernel
|
int
|
see the description of |
None
|
noise_task_kernel
|
Union[Tensor[num_tasks], float]
|
see the description of |
1.0
|
device
|
device
|
torch device which is required to support |
'cpu'
|
tfs_scale
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_lengthscales
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_noise
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
tfs_factor_task_kernel
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: x, lambda x: x)
|
tfs_noise_task_kernel
|
Tuple[callable, callable]
|
the first argument transforms to the raw value to be optimized, the second applies the inverse transform |
(lambda x: log(x), lambda x: exp(x))
|
requires_grad_scale
|
bool
|
wheather or not to optimize the scale parameter |
True
|
requires_grad_lengthscales
|
bool
|
wheather or not to optimize lengthscale parameters |
True
|
requires_grad_noise
|
bool
|
wheather or not to optimize the noise parameter |
False
|
requires_grad_factor_task_kernel
|
bool
|
wheather or not to optimize the factor for the task kernel |
None
|
requires_grad_noise_task_kernel
|
bool
|
wheather or not to optimize the noise for the task kernel |
None
|
shape_batch
|
Size
|
shape of the batch output for each task |
Size([])
|
shape_scale
|
Size
|
shape of the scale parameter, defaults to |
Size([1])
|
shape_lengthscales
|
Size
|
shape of the lengthscales parameter, defaults to |
None
|
shape_noise
|
Size
|
shape of the noise parameter, defaults to |
Size([1])
|
shape_factor_task_kernel
|
Size
|
shape of the factor for the task kernel, defaults to |
None
|
shape_noise_task_kernel
|
Size
|
shape of the noise for the task kernel, defaults to |
None
|
derivatives
|
list
|
list of derivative orders e.g. to include a function and its gradient set
|
None
|
derivatives_coeffs
|
list
|
list of derivative coefficients where if |
None
|
compile_fts
|
bool
|
if |
False
|
compile_fts_kwargs
|
dict
|
keyword arguments to |
{}
|
adaptive_nugget
|
bool
|
if True, use the adaptive nugget which modifies noises based on trace ratios. |
False
|
Source code in fastgps/fast_gp_digital_net_b2.py
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 |
|