Skip to content

SmoothConvex

src.geostat.kernel.SmoothConvex

Bases: Kernel

SmoothConvex kernel class for Gaussian Processes (GPs).

The SmoothConvex class defines a kernel that produces a smooth and convex covariance structure. It allows for multiple sills and ranges, enabling a more complex representation of covariance that smoothly transitions across different scales.

Parameters:

  • range (list or Variable) –

    A list or TensorFlow variable representing the length scale parameters that control how quickly the covariance decreases with distance.

  • sill (list or Variable) –

    A list or TensorFlow variable representing the variance (sill) values for each smooth convex component.

  • 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 SmoothConvex kernel:

from geostat.kernel import SmoothConvex

# Create a SmoothConvex kernel with multiple sills and ranges
smooth_convex_kernel = SmoothConvex(range=[2.0, 3.0], sill=[1.0, 0.5])

locs1 = np.array([[0.0], [1.0], [2.0]])
locs2 = np.array([[0.0], [1.0], [2.0]])
covariance_matrix = smooth_convex_kernel({'locs1': locs1, 'locs2': locs2, 'sill': [1.0, 0.5], 'range': [2.0, 3.0]})

Notes:

  • The call method computes the covariance matrix using the smooth_convex function, which applies multiple convex functions based on the provided sill and range values for each component.
  • The vars method returns the parameter dictionary for both sill and range using the ppp_list function.
  • The SmoothConvex kernel is useful for modeling processes that require smooth transitions and convexity in their covariance structure across different scales.
Source code in src/geostat/kernel.py
class SmoothConvex(Kernel):
    """
    SmoothConvex kernel class for Gaussian Processes (GPs).

    The `SmoothConvex` class defines a kernel that produces a smooth and convex covariance structure. 
    It allows for multiple sills and ranges, enabling a more complex representation of covariance that 
    smoothly transitions across different scales.

    Parameters:
        range (list or tf.Variable):
            A list or TensorFlow variable representing the length scale parameters that control how 
            quickly the covariance decreases with distance.
        sill (list or tf.Variable):
            A list or TensorFlow variable representing the variance (sill) values for each smooth convex component.
        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 `SmoothConvex` kernel:

        ```python
        from geostat.kernel import SmoothConvex

        # Create a SmoothConvex kernel with multiple sills and ranges
        smooth_convex_kernel = SmoothConvex(range=[2.0, 3.0], sill=[1.0, 0.5])

        locs1 = np.array([[0.0], [1.0], [2.0]])
        locs2 = np.array([[0.0], [1.0], [2.0]])
        covariance_matrix = smooth_convex_kernel({'locs1': locs1, 'locs2': locs2, 'sill': [1.0, 0.5], 'range': [2.0, 3.0]})
        ```

    Examples: Notes:
        - The `call` method computes the covariance matrix using the `smooth_convex` function, which applies 
            multiple convex functions based on the provided `sill` and `range` values for each component.
        - The `vars` method returns the parameter dictionary for both `sill` and `range` using the `ppp_list` function.
        - The `SmoothConvex` kernel is useful for modeling processes that require smooth transitions and convexity 
            in their covariance structure across different scales.
    """

    def __init__(self, range, sill, scale=None, metric=None):
        fa = dict(sill=sill, range=range, scale=scale)
        autoinputs = scale_to_metric(scale, metric)
        super().__init__(fa, dict(d2=autoinputs))

    def vars(self):
        return ppp_list(self.fa['sill']) | ppp_list(self.fa['range'])

    def call(self, e):
        if isinstance(e['sill'], (tuple, list)):
            e['sill'] = tf.stack(e['sill'])
        if isinstance(e['range'], (tuple, list)):
            e['range'] = tf.stack(e['range'])

        return smooth_convex(tf.sqrt(e['d2']), e['sill'], e['range'])