Bases: Kernel
SquaredExponential kernel class for Gaussian Processes (GPs).
The SquaredExponential class defines a widely used kernel that models smooth and continuous
covariance structures. It is parameterized by a sill (variance) and a range (length scale)
and can optionally use a metric for scaling.
Parameters:
-
sill
(float or Variable)
–
The variance (sill) of the kernel, representing the maximum covariance value.
-
range
(float or Variable)
–
The length scale parameter that controls how quickly the covariance decreases
with distance.
-
scale
(optional, default:
None
)
–
An optional scale parameter that can be used to modify the metric. Default is None.
-
metric
(optional, default:
None
)
–
An optional metric used for distance calculation. Default is None.
Examples:
Creating and using a SquaredExponential kernel:
from geostat.kernel import SquaredExponential
# Create a SquaredExponential kernel with a sill of 1.0 and a range of 2.0
sq_exp_kernel = SquaredExponential(sill=1.0, range=2.0)
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = sq_exp_kernel({'locs1': locs1, 'locs2': locs2, 'sill': 1.0, 'range': 2.0})
Notes:
- The
call method computes the covariance matrix using the squared exponential formula:
\( C(x, x') = \text{sill} \cdot \exp\left(-0.5 \frac{d^2}{\text{range}^2}\right) \),
where \(d^2\) is the squared distance between locs1 and locs2.
- The
vars method returns the parameter dictionary for both sill and range using the ppp function.
- This kernel is appropriate for modeling smooth, continuous processes with no abrupt changes.
Source code in src/geostat/kernel.py
| class SquaredExponential(Kernel):
"""
SquaredExponential kernel class for Gaussian Processes (GPs).
The `SquaredExponential` class defines a widely used kernel that models smooth and continuous
covariance structures. It is parameterized by a sill (variance) and a range (length scale)
and can optionally use a metric for scaling.
Parameters:
sill (float or tf.Variable):
The variance (sill) of the kernel, representing the maximum covariance value.
range (float or tf.Variable):
The length scale parameter that controls how quickly the covariance decreases
with distance.
scale (optional):
An optional scale parameter that can be used to modify the metric. Default is None.
metric (optional):
An optional metric used for distance calculation. Default is None.
Examples:
Creating and using a `SquaredExponential` kernel:
```python
from geostat.kernel import SquaredExponential
# Create a SquaredExponential kernel with a sill of 1.0 and a range of 2.0
sq_exp_kernel = SquaredExponential(sill=1.0, range=2.0)
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = sq_exp_kernel({'locs1': locs1, 'locs2': locs2, 'sill': 1.0, 'range': 2.0})
```
Examples: Notes:
- The `call` method computes the covariance matrix using the squared exponential formula:
\\( C(x, x') = \\text{sill} \cdot \exp\left(-0.5 \\frac{d^2}{\\text{range}^2}\\right) \\),
where \\(d^2\\) is the squared distance between `locs1` and `locs2`.
- The `vars` method returns the parameter dictionary for both `sill` and `range` using the `ppp` function.
- This kernel is appropriate for modeling smooth, continuous processes with no abrupt changes.
"""
def __init__(self, sill, range, scale=None, metric=None):
fa = dict(sill=sill, range=range)
autoinputs = scale_to_metric(scale, metric)
super().__init__(fa, dict(d2=autoinputs))
def vars(self):
return ppp(self.fa['sill']) | ppp(self.fa['range'])
def call(self, e):
return e['sill'] * tf.exp(-0.5 * e['d2'] / tf.square(e['range']))
|