Skip to content

Commit

Permalink
Added switch_dim parameter to ChangePoints kernel
Browse files Browse the repository at this point in the history
This parameter allows to define the ChangePoint on one particular dimension of
the input space. All other dimensions are still available to the kernels being
switched, and can be selected via active_dims.
  • Loading branch information
clwgg committed Jul 27, 2021
1 parent 3e4b9f1 commit 8f717ee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gpflow/kernels/changepoints.py
Expand Up @@ -54,13 +54,16 @@ def __init__(
kernels: List[Kernel],
locations: List[float],
steepness: Union[float, List[float]] = 1.0,
switch_dim: int = 0,
name: Optional[str] = None,
):
"""
:param kernels: list of kernels defining the different regimes
:param locations: list of change-point locations in the 1d input space
:param steepness: the steepness parameter(s) of the sigmoids, this can be
common between them or decoupled
:param switch_dim: the (one) dimension of the input space along which
the change-points are defined
"""
if len(kernels) != len(locations) + 1:
raise ValueError(
Expand All @@ -76,6 +79,7 @@ def __init__(

super().__init__(kernels, name=name)

self.switch_dim = switch_dim
self.locations = Parameter(locations)
self.steepness = Parameter(steepness, transform=positive())

Expand Down Expand Up @@ -119,4 +123,5 @@ def _sigmoids(self, X: tf.Tensor) -> tf.Tensor:
locations = tf.sort(self.locations) # ensure locations are ordered
locations = tf.reshape(locations, (1, 1, -1))
steepness = tf.reshape(self.steepness, (1, 1, -1))
return tf.sigmoid(steepness * (X[:, :, None] - locations))
Xslice = tf.reshape(X[:, self.switch_dim], (-1, 1, 1))
return tf.sigmoid(steepness * (Xslice - locations))

0 comments on commit 8f717ee

Please sign in to comment.