Bases: Kernel
Delta kernel class for Gaussian Processes (GPs).
The Delta class defines a kernel that models a Dirac delta function effect, where covariance
is non-zero only when the inputs are identical. This kernel is useful for capturing exact matches
between input points, weighted by the specified sill parameter.
Parameters:
-
sill
(float or Variable)
–
The variance (sill) representing the weight of the delta function. This value is applied
when input locations match exactly.
-
axes
(list or None, default:
None
)
–
A list of axes over which to apply the delta function. If not specified, the delta function
is applied across all axes.
Examples:
Creating and using a Delta kernel:
from geostat.kernel import Delta
# Create a Delta kernel with a sill of 1.0, applied across all axes
delta_kernel = Delta(sill=1.0)
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = delta_kernel({'locs1': locs1, 'locs2': locs2, 'sill': 1.0})
Using the Delta kernel with specified axes:
delta_kernel_axes = Delta(sill=1.0, axes=[0])
Notes:
- The
call method computes a covariance matrix using a delta function, returning sill when the
squared distances are zero along the specified axes, and 0 otherwise.
- The
vars method returns the parameter dictionary for sill using the ppp function.
- The
Delta kernel is useful for modeling processes that exhibit exact matches or sharp changes
in covariance when inputs coincide, making it ideal for capturing discrete effects.
Source code in src/geostat/kernel.py
| class Delta(Kernel):
"""
Delta kernel class for Gaussian Processes (GPs).
The `Delta` class defines a kernel that models a Dirac delta function effect, where covariance
is non-zero only when the inputs are identical. This kernel is useful for capturing exact matches
between input points, weighted by the specified `sill` parameter.
Parameters:
sill (float or tf.Variable):
The variance (sill) representing the weight of the delta function. This value is applied
when input locations match exactly.
axes (list or None, optional):
A list of axes over which to apply the delta function. If not specified, the delta function
is applied across all axes.
Examples:
Creating and using a `Delta` kernel:
```python
from geostat.kernel import Delta
# Create a Delta kernel with a sill of 1.0, applied across all axes
delta_kernel = Delta(sill=1.0)
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = delta_kernel({'locs1': locs1, 'locs2': locs2, 'sill': 1.0})
```
Using the `Delta` kernel with specified axes:
```
delta_kernel_axes = Delta(sill=1.0, axes=[0])
```
Examples: Notes:
- The `call` method computes a covariance matrix using a delta function, returning `sill` when the
squared distances are zero along the specified axes, and 0 otherwise.
- The `vars` method returns the parameter dictionary for `sill` using the `ppp` function.
- The `Delta` kernel is useful for modeling processes that exhibit exact matches or sharp changes
in covariance when inputs coincide, making it ideal for capturing discrete effects.
"""
def __init__(self, sill, axes=None):
fa = dict(sill=sill)
self.axes = axes
super().__init__(fa, dict(pa_d2='per_axis_dist2'))
def vars(self):
return ppp(self.fa['sill'])
def call(self, e):
if self.axes is not None:
n = tf.shape(e['pa_d2'])[-1]
mask = tf.math.bincount(self.axes, minlength=n, maxlength=n, dtype=tf.float32)
d2 = tf.einsum('abc,c->ab', e['pa_d2'], mask)
else:
d2 = tf.reduce_sum(e['pa_d2'], axis=-1)
return e['sill'] * tf.cast(tf.equal(d2, 0.), tf.float32)
|