Skip to content

Constant

src.geostat.kernel.Constant

Bases: Kernel

Constant kernel class for Gaussian Processes (GPs).

The Constant class defines a simple kernel that produces a constant covariance value across all pairs of input locations. This kernel is typically used to represent a baseline level of variance (sill) in the GP model.

Parameters:

  • sill (float or Variable) –

    The constant value representing the sill (baseline variance) of the kernel.

Examples:

Creating and using a Constant kernel:

from geostat import Parameters
from geostat.kernel import Constant
import numpy as np

# Create parameters.
p = Parameters(sill=2.0)

# Create a Constant kernel with a sill value of 2.0 and call it
locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
constant_kernel = Constant(sill=p.sill)
covariance_matrix = constant_kernel({'locs1': locs1, 'locs2': locs2, 'sill': 2.0})
print(covariance_matrix)
# tf.Tensor(
# [[2. 2. 2.]
#  [2. 2. 2.]
#  [2. 2. 2.]], shape=(3, 3), dtype=float32)

Notes:

  • The call method returns the constant value specified by sill for all pairs of input locations.
  • The vars method returns the parameter dictionary for sill using the ppp function.
  • The Constant kernel is useful when you want to add a fixed variance component to your GP model.
Source code in src/geostat/kernel.py
class Constant(Kernel):
    """
    Constant kernel class for Gaussian Processes (GPs).

    The `Constant` class defines a simple kernel that produces a constant covariance value across
    all pairs of input locations. This kernel is typically used to represent a baseline level of
    variance (sill) in the GP model.

    Parameters:
        sill (float or tf.Variable):
            The constant value representing the sill (baseline variance) of the kernel.

    Examples:
        Creating and using a `Constant` kernel:

        ```python
        from geostat import Parameters
        from geostat.kernel import Constant
        import numpy as np

        # Create parameters.
        p = Parameters(sill=2.0)

        # Create a Constant kernel with a sill value of 2.0 and call it
        locs1 = np.array([[0.0], [1.0], [2.0]])
        locs2 = np.array([[0.0], [1.0], [2.0]])
        constant_kernel = Constant(sill=p.sill)
        covariance_matrix = constant_kernel({'locs1': locs1, 'locs2': locs2, 'sill': 2.0})
        print(covariance_matrix)
        # tf.Tensor(
        # [[2. 2. 2.]
        #  [2. 2. 2.]
        #  [2. 2. 2.]], shape=(3, 3), dtype=float32)
        ```

    Examples: Notes:
        - The `call` method returns the constant value specified by `sill` for all pairs of input locations.
        - The `vars` method returns the parameter dictionary for `sill` using the `ppp` function.
        - The `Constant` kernel is useful when you want to add a fixed variance component to your GP model.
    """

    def __init__(self, sill):
        fa = dict(sill=sill)
        super().__init__(fa, dict())

    def vars(self):
        return ppp(self.fa['sill'])

    def call(self, e):
        return e['sill']