Advanced
gpplus.kernels.CompositeKernel
¤
Bases: Kernel
Custom kernel where inputs are transformed using a provided transformation module before applying a base kernel.
The transformation (input_transform) can be any valid mapping function, such as:
- Polynomial expansion
- Neural network module
- Other custom transformations
As long as input_transform is a callable or torch.nn.Module that
takes in x and returns a transformed tensor, it can be used here.
Source code in gpplus/kernels/advanced_kernels.py
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 | |
base_kernel = base_kernel
instance-attribute
¤
input_transform = input_transform
instance-attribute
¤
__init__(base_kernel, input_transform, **kwargs)
¤
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_kernel
|
Kernel
|
The base kernel to apply on the transformed inputs. |
required |
input_transform
|
callable or Module
|
A user-defined module/function for transforming inputs (e.g., polynomial feature expansion, MLP, etc.). |
required |
Source code in gpplus/kernels/advanced_kernels.py
24 25 26 27 28 29 30 31 32 33 | |
forward(x1, x2, **params)
¤
Transforms inputs and computes the base kernel matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
Tensor
|
First input tensor. |
required |
x2
|
Tensor
|
Second input tensor. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Kernel matrix after transforming the inputs. |
Source code in gpplus/kernels/advanced_kernels.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
gpplus.kernels.NeuralKernel
¤
Bases: Kernel
Custom kernel where inputs are transformed using an internally constructed neural network.
For example, a valid layer_config could look like:
layer_config = {
0: {"dims": 64, "activation": nn.ReLU},
1: {"dims": 32, "activation": nn.ReLU},
2: {"dims": 16, "activation": nn.Tanh},
}
This will create a feedforward network with the specified layer sizes and activations in sequence.
Source code in gpplus/kernels/advanced_kernels.py
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 | |
base_kernel = base_kernel
instance-attribute
¤
input_transform = InputTransformNet(input_dim, layer_config)
instance-attribute
¤
__init__(base_kernel, input_dim, layer_config, **kwargs)
¤
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_kernel
|
Kernel
|
The base kernel. |
required |
input_dim
|
int
|
Input dimension if constructing a network. |
required |
layer_config
|
dict
|
Layer configuration to construct a network. |
required |
Source code in gpplus/kernels/advanced_kernels.py
70 71 72 73 74 75 76 77 78 79 | |
forward(x1, x2, **params)
¤
Transforms inputs and computes the base kernel matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
Tensor
|
First input tensor. |
required |
x2
|
Tensor
|
Second input tensor. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Kernel matrix after transforming the inputs. |
Source code in gpplus/kernels/advanced_kernels.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
gpplus.kernels.NeuralScaleKernel
¤
Bases: Kernel
Custom kernel that constructs an InputTransformNet internally based on a layer configuration and computes the dot product between transformed inputs.
The kernel function is defined as
k(x, x') = f(x) . f(x')
where f is the internally constructed input transformation network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int
|
Input dimension of the data. |
required |
layer_config
|
dict
|
Configuration dictionary for constructing the InputTransformNet. |
required |
**kwargs
|
Additional keyword arguments for the Kernel base class. |
{}
|
Source code in gpplus/kernels/advanced_kernels.py
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 | |
input_transform = InputTransformNet(input_dim, layer_config)
instance-attribute
¤
__init__(input_dim, layer_config, **kwargs)
¤
Source code in gpplus/kernels/advanced_kernels.py
115 116 117 | |
forward(x1, x2, **params)
¤
Compute the dot product kernel matrix between transformed inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
Tensor
|
First input tensor of shape (n1, d). |
required |
x2
|
Tensor
|
Second input tensor of shape (n2, d). |
required |
**params
|
Additional parameters (unused). |
{}
|
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Kernel matrix of shape (n1, n2). |
Source code in gpplus/kernels/advanced_kernels.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
gpplus.kernels.CompositeScaleKernel
¤
Bases: Kernel
Custom kernel that applies an input transformation and computes the dot product between transformed inputs.
The kernel function is defined as
k(x, x') = f(x) . f(x')
where f is the input_transform neural network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_transform
|
callable or Module
|
The transformation to apply to inputs. |
required |
**kwargs
|
Additional keyword arguments for the Kernel base class. |
{}
|
Source code in gpplus/kernels/advanced_kernels.py
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 | |
input_transform = input_transform
instance-attribute
¤
__init__(input_transform, **kwargs)
¤
Source code in gpplus/kernels/advanced_kernels.py
156 157 158 | |
forward(x1, x2, **params)
¤
Compute the dot product kernel matrix between transformed inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
Tensor
|
First input tensor of shape (n1, d). |
required |
x2
|
Tensor
|
Second input tensor of shape (n2, d). |
required |
**params
|
Additional parameters (unused). |
{}
|
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Kernel matrix of shape (n1, n2). |
Source code in gpplus/kernels/advanced_kernels.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
gpplus.kernels.GibbsKernel
¤
Bases: Kernel
A custom Gibbs (nonstationary) kernel in D dimensions with ARD. Each input x in R^D maps to a lengthscale vector ell(x) in R^D.
Source code in gpplus/kernels/advanced_kernels.py
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 | |
has_lengthscale = False
class-attribute
instance-attribute
¤
input_dim = input_dim
instance-attribute
¤
input_transform = InputTransformNet(input_dim, layer_config)
instance-attribute
¤
__init__(input_dim=None, layer_config=None, input_transform=None, **kwargs)
¤
Source code in gpplus/kernels/advanced_kernels.py
191 192 193 194 195 196 197 198 199 200 201 202 | |
forward(x1, x2, diag=False, last_dim_is_batch=False, **params)
¤
Computes the ARD Gibbs covariance between sets of points x1 and x2. x1, x2: [..., N, D] or [N, D]
Source code in gpplus/kernels/advanced_kernels.py
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 | |
gpplus.kernels.ExponentialKernel
¤
Bases: Kernel
Source code in gpplus/kernels/advanced_kernels.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
base_kernel = base_kernel
instance-attribute
¤
__init__(base_kernel=None, **kwargs)
¤
Source code in gpplus/kernels/advanced_kernels.py
258 259 260 | |
forward(x1, x2, diag=False, **params)
¤
Source code in gpplus/kernels/advanced_kernels.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
gpplus.kernels.SinhKernel
¤
Bases: Kernel
Source code in gpplus/kernels/advanced_kernels.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
base_kernel = base_kernel
instance-attribute
¤
__init__(base_kernel=None, **kwargs)
¤
Source code in gpplus/kernels/advanced_kernels.py
281 282 283 | |
forward(x1, x2, diag=False, **params)
¤
Source code in gpplus/kernels/advanced_kernels.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
gpplus.kernels.CoshKernel
¤
Bases: Kernel
Source code in gpplus/kernels/advanced_kernels.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
base_kernel = base_kernel
instance-attribute
¤
__init__(base_kernel=None, **kwargs)
¤
Source code in gpplus/kernels/advanced_kernels.py
304 305 306 | |
forward(x1, x2, diag=False, **params)
¤
Source code in gpplus/kernels/advanced_kernels.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |