Kernels¶
Physics-aware scikit-learn kernels for fingerprint, composition, and structure similarity.
matgpr.kernels
¶
ElementFractionKernel
¶
Bases: Kernel
Kernel for elemental composition fraction or count vectors.
The kernel first projects non-negative element vectors onto the composition simplex by normalizing each row to sum to one. It then compares normalized compositions with either an L1 Laplacian kernel or an L2 RBF kernel.
The default L1 form is:
k(x, y) = exp(-sum_i |c_i - c'_i| / length_scale)
where c and c' are element-fraction vectors. This is useful when
the physical idea of similarity is the amount of composition substitution
needed to move from one material to another.
Source code in matgpr/kernels.py
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 | |
__call__(X, Y=None, eval_gradient=False)
¶
Return the element-fraction composition kernel matrix.
Source code in matgpr/kernels.py
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 | |
diag(X)
¶
Return the diagonal of the kernel matrix.
Source code in matgpr/kernels.py
89 90 91 92 | |
is_stationary()
¶
Return whether the kernel is stationary.
Source code in matgpr/kernels.py
94 95 96 | |
StructureFeatureKernel
¶
Bases: Kernel
Kernel for continuous structure descriptors.
This kernel is intended for global crystal-structure descriptors such as
lattice-shape, volume-per-atom, and density features from
matgpr.structure_fingerprint. It compares descriptor vectors after
optional fixed feature scaling using either an L2 RBF kernel or an L1
Laplacian kernel.
Source code in matgpr/kernels.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 167 168 169 170 | |
__call__(X, Y=None, eval_gradient=False)
¶
Return the structure-feature kernel matrix.
Source code in matgpr/kernels.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
diag(X)
¶
Return the diagonal of the kernel matrix.
Source code in matgpr/kernels.py
160 161 162 163 | |
is_stationary()
¶
Return whether the kernel is stationary.
Source code in matgpr/kernels.py
165 166 167 | |
TanimotoKernel
¶
Bases: Kernel
Tanimoto kernel for binary or non-negative count fingerprints.
For vectors x and y, the generalized Tanimoto similarity is:
k(x, y) = dot(x, y) / (||x||^2 + ||y||^2 - dot(x, y)).
This is commonly used for molecular fingerprints and polymer fingerprints. Inputs must be binary or non-negative count descriptors.
Source code in matgpr/kernels.py
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 | |
__call__(X, Y=None, eval_gradient=False)
¶
Return the Tanimoto kernel matrix.
Source code in matgpr/kernels.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
diag(X)
¶
Return the diagonal of the kernel matrix.
Source code in matgpr/kernels.py
203 204 205 206 207 208 | |
is_stationary()
¶
Return whether the kernel is stationary.
Source code in matgpr/kernels.py
210 211 212 | |
FeatureSubsetKernel
¶
Bases: Kernel
Apply a scikit-learn kernel to selected feature columns.
This wrapper is useful for mixed materials descriptors. For example, a Tanimoto kernel can act on fingerprint columns while an RBF or Matern kernel acts on continuous physics descriptors, then the kernels can be added or multiplied.
Source code in matgpr/kernels.py
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 | |
clone_with_theta(theta)
¶
Return a clone with updated wrapped-kernel hyperparameters.
Source code in matgpr/kernels.py
247 248 249 250 251 | |
__call__(X, Y=None, eval_gradient=False)
¶
Return the wrapped-kernel matrix on selected columns.
Source code in matgpr/kernels.py
253 254 255 256 257 | |
diag(X)
¶
Return the wrapped-kernel diagonal on selected columns.
Source code in matgpr/kernels.py
259 260 261 | |
is_stationary()
¶
Return whether the wrapped kernel is stationary.
Source code in matgpr/kernels.py
263 264 265 | |
pairwise_tanimoto_similarity(X, Y=None, *, eps=1e-12, validate_nonnegative=True)
¶
Return pairwise generalized Tanimoto similarities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Two-dimensional arrays of binary or non-negative count fingerprints. If
|
required | |
Y
|
Two-dimensional arrays of binary or non-negative count fingerprints. If
|
required | |
eps
|
float
|
Small denominator threshold used to identify all-zero fingerprints. |
1e-12
|
validate_nonnegative
|
bool
|
If |
True
|
Source code in matgpr/kernels.py
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 | |
pairwise_composition_distance(X, Y=None, *, metric='l1', normalize=True, eps=1e-12)
¶
Return pairwise distances between non-negative composition vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Two-dimensional arrays of elemental amount, count, or fraction vectors.
If |
required | |
Y
|
Two-dimensional arrays of elemental amount, count, or fraction vectors.
If |
required | |
metric
|
str
|
|
'l1'
|
normalize
|
bool
|
If |
True
|
eps
|
float
|
Small threshold used to reject all-zero composition rows. |
1e-12
|
Source code in matgpr/kernels.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
pairwise_structure_distance(X, Y=None, *, metric='l2', feature_scales=None)
¶
Return pairwise distances between continuous structure descriptor rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Two-dimensional arrays of structure descriptors. |
required | |
Y
|
Two-dimensional arrays of structure descriptors. |
required | |
metric
|
str
|
|
'l2'
|
feature_scales
|
Optional positive per-feature scales. When supplied, descriptor columns are divided by these scales before distances are computed. |
None
|
Source code in matgpr/kernels.py
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 381 382 383 384 385 | |
build_element_fraction_gpr_kernel(*, constant_value=1.0, constant_value_bounds=(0.001, 1000.0), length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), noise_level=1e-06, noise_level_bounds=(1e-10, 0.1), metric='l1', normalize=True)
¶
Build a scikit-learn GPR kernel for element-fraction composition vectors.
Source code in matgpr/kernels.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
build_structure_gpr_kernel(*, constant_value=1.0, constant_value_bounds=(0.001, 1000.0), length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), noise_level=1e-06, noise_level_bounds=(1e-10, 0.1), metric='l2', feature_scales=None)
¶
Build a scikit-learn GPR kernel for continuous structure descriptors.
Source code in matgpr/kernels.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
build_tanimoto_gpr_kernel(*, constant_value=1.0, constant_value_bounds=(0.001, 1000.0), noise_level=1e-06, noise_level_bounds=(1e-10, 0.1), validate_nonnegative=True)
¶
Build a scikit-learn GPR kernel using Tanimoto fingerprint similarity.
Source code in matgpr/kernels.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
build_additive_kernel(*kernels)
¶
Add two or more scikit-learn kernels.
Source code in matgpr/kernels.py
448 449 450 451 | |
build_product_kernel(*kernels)
¶
Multiply two or more scikit-learn kernels.
Source code in matgpr/kernels.py
454 455 456 457 | |