Bases: Kernel
Product kernel class for combining multiple Gaussian Process (GP) kernels multiplicatively.
The Product
class defines a kernel that combines multiple input kernels by multiplying them together.
This multiplicative combination allows for capturing interactions between the individual kernels, resulting
in a more complex and flexible covariance structure.
Parameters:
-
parts
(List[Kernel]
)
–
A list of kernel objects to be combined multiplicatively.
Examples:
Creating and using a Product
kernel:
from geostat.kernel import Product, SquaredExponential, Noise
# Create individual kernels
kernel1 = SquaredExponential(sill=1.0, range=2.0)
kernel2 = Noise(nugget=0.1)
# Combine kernels using the Product class
product_kernel = Product(parts=[kernel1, kernel2])
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = product_kernel({'locs1': locs1, 'locs2': locs2})
Multiplying another kernel with an existing Product
kernel:
kernel3 = SquaredExponential(sill=0.5, range=1.0)
combined_product = product_kernel * kernel3
Notes:
- The
call
method computes the product of all covariance matrices generated by the multiplied kernels.
- The
vars
method gathers parameters from all input kernels, making them accessible for optimization.
- The
Product
kernel is useful for building models where the covariance structure results from
multiplicative interactions between different kernels, allowing for more complex GP models.
Source code in src/geostat/kernel.py
| class Product(Kernel):
"""
Product kernel class for combining multiple Gaussian Process (GP) kernels multiplicatively.
The `Product` class defines a kernel that combines multiple input kernels by multiplying them together.
This multiplicative combination allows for capturing interactions between the individual kernels, resulting
in a more complex and flexible covariance structure.
Parameters:
parts (List[Kernel]):
A list of kernel objects to be combined multiplicatively.
Examples:
Creating and using a `Product` kernel:
```python
from geostat.kernel import Product, SquaredExponential, Noise
# Create individual kernels
kernel1 = SquaredExponential(sill=1.0, range=2.0)
kernel2 = Noise(nugget=0.1)
# Combine kernels using the Product class
product_kernel = Product(parts=[kernel1, kernel2])
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = product_kernel({'locs1': locs1, 'locs2': locs2})
```
Multiplying another kernel with an existing `Product` kernel:
```python
kernel3 = SquaredExponential(sill=0.5, range=1.0)
combined_product = product_kernel * kernel3
```
Examples: Notes:
- The `call` method computes the product of all covariance matrices generated by the multiplied kernels.
- The `vars` method gathers parameters from all input kernels, making them accessible for optimization.
- The `Product` kernel is useful for building models where the covariance structure results from
multiplicative interactions between different kernels, allowing for more complex GP models.
"""
def __init__(self, parts: List[Kernel]):
self.parts = parts
super().__init__({}, dict(locs1='locs1', locs2='locs2', parts=parts))
def vars(self):
return {k: p for part in self.parts for k, p in part.vars().items()}
def __mul__(self, other):
if isinstance(other, Kernel):
return Product(self.parts + [other])
def call(self, e):
return tf.reduce_prod(e['parts'], axis=0)
def report(self):
return ' '.join(part.report(p) for part in self.parts)
|