gaussian_process
gaussian_process_precompute
Source code in src/gpytoolbox/gaussian_process.py
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 |
|
__init__(X_train, y_train, X_induced=None, grad_y_train=None, kernel=None, verbose=False, sigma_n=0.02, lump_K3=False, compact_kernel=False)
Fits a gaussian process to existing training data, storing all necessary information to later evaluate it at any given test points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_train |
(num_train, num_dim) numpy array
|
Training data points coordinates. |
required |
y_train |
(num_train, 1) numpy array
|
Value of the function at the training data points. |
required |
kernel |
function, optional (default None)
|
Kernel function that takes two coordinate matrices as input and returns a vector of values; e.g., k = kernel(X1,X2). If |
None
|
X_induced |
(num_induced, num_dim) numpy array, optional (default None)
|
Inducing points coordinates (see e.g., https://ludwigwinkler.github.io/blog/InducingPoints/). If None, the training data points are used as inducing points. |
None
|
grad_y_train |
(num_train, num_dim) numpy array, optional (default None)
|
Observed gradient of the function at the training data points. If None, the gradient is not used. |
None
|
verbose |
bool, optional (default False)
|
If True, prints information about the training. |
False
|
sigma_n |
float, optional (default 0.02)
|
Noise standard deviation. |
0.02
|
lump_K3 |
bool, optional (default False)
|
If True, lump the sample covariance matrix K3. Useful if the number of training points is large. |
False
|
compact_kernel |
bool, optional (default False)
|
If True, will try to find the kernel's compact support and only evaluate it for points in that neighborhood, to save time. Kernel must be radially symmetric, isotropic, and positive definite. |
False
|
Returns:
Name | Type | Description |
---|---|---|
precomputed_gaussian_process |
instance of class gaussian_process_precompute
|
Object that stores all necessary information to later evaluate the gaussian process at any given test points. |
Source code in src/gpytoolbox/gaussian_process.py
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 |
|
predict(X_test, mean_only=False)
Evaluates a precomputed gaussian process at the points X_test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_test |
(num_test, dim) numpy array
|
The points at which to evaluate the gaussian process. |
required |
mean_only |
bool
|
If True, only the mean of the gaussian process is computed (this is significantly faster). The var output is None. |
False
|
Returns |
required | ||
mean |
(num_test,) numpy array
|
The mean of the gaussian process at the points X_test. |
required |
var |
(num_test,num_test) numpy array
|
The covariance matrix of the gaussian process at the points X_test. |
required |
Source code in src/gpytoolbox/gaussian_process.py
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 |
|
gaussian_process(X_train, y_train, X_test, kernel=None, X_induced=None, grad_y_train=None, verbose=False, lump_K3=False, compact_kernel=False, sigma_n=0.02)
Uses a gaussian process to fit existing training data and evaluates it at new test points, returning a vector of means and a covariance matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_train |
(num_train, num_dim) numpy array
|
Training data points coordinates. |
required |
y_train |
(num_train, 1) numpy array
|
Value of the function at the training data points. |
required |
X_test |
(num_test, num_dim) numpy array
|
Test data points coordinates. |
required |
kernel |
function, optional (default None)
|
Kernel function that takes two coordinate matrices as input and returns a vector of values; e.g., k = kernel(X1,X2). If |
None
|
X_induced |
(num_induced, num_dim) numpy array, optional (default None)
|
Inducing points coordinates (see e.g., https://ludwigwinkler.github.io/blog/InducingPoints/). If None, the training data points are used as inducing points. |
None
|
grad_y_train |
(num_train, num_dim) numpy array, optional (default None)
|
Observed gradient of the function at the training data points. If None, the gradient is not used. |
None
|
verbose |
bool, optional (default False)
|
If True, prints information about the training. |
False
|
sigma_n |
float, optional (default 0.02)
|
Noise standard deviation. |
0.02
|
lump_K3 |
bool, optional (default False)
|
If True, lump the sample covariance matrix K3. Useful if the number of training points is large. |
False
|
compact_kernel |
bool, optional (default False)
|
If True, will try to find the kernel's compact support and only evaluate it for points in that neighborhood, to save time. Kernel must be radially symmetric, isotropic, and positive definite. |
False
|
Returns:
Name | Type | Description |
---|---|---|
mu |
(num_test,) numpy array
|
Mean of the gaussian process at the test data points. |
sigma |
(num_test, num_test) numpy array
|
Covariance matrix of the gaussian process at the test data points. |
See also
squared_exponential_kernel, compactly_supported_normal
Notes
This function is a wrapper for the gaussian_process_precompute
class, which stores all necessary information to later evaluate the gaussian process at any given test points. This is useful if the same training data is used to evaluate the gaussian process at multiple test points, as it avoids recomputing the same quantities multiple times.
Examples:
import numpy as np
import gpytoolbox
# Choose a simple function
def true_fun(x):
return 10*x
def true_grad(x):
return 10 + 0*x
# Trye to fit it with a gaussian process to a limited training set
x_train = np.linspace(0,1,5)
y_train = true_fun(x_train)
y_grad = true_grad(x_train)
# Test points
x_test = np.linspace(0,1,140)
# Call to Gaussian Process
y_test_mean,y_test_cov = gpytoolbox.gaussian_process(np.reshape(x_train,(-1,1)),y_train,np.reshape(x_test,(-1,1)),grad_y_train=y_grad,verbose=True)
Source code in src/gpytoolbox/gaussian_process.py
8 9 10 11 12 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 |
|