Skip to content

Commit

Permalink
Started reviewing change and sigmoidal kernels to improve CW
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Flet committed Jan 31, 2020
1 parent de113f0 commit 7aab7a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions GPy_ABCD/Kernels/changeOperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from GPy.kern.src.kern import CombinationKernel
from GPy.core.parameterization import Param

from GPy_ABCD.Kernels.sigmoidalKernels import SigmoidalKernel, SigmoidalIndicatorKernel
from GPy_ABCD.Kernels.sigmoidalKernels import SigmoidalKernel, SigmoidalIndicatorKernel, SigmoidalIndicatorKernelWithWidth


class ChangeKernelBase(CombinationKernel):
Expand Down Expand Up @@ -100,7 +100,7 @@ def update_gradients_diag(self, dL_dK, X):
class ChangeWindowKernelWithWidth(ChangeKernelBase):
"""Composite kernel changing from left to right subkernels at a limited location"""
def __init__(self, left, right, location: float = 0., slope: float = 0.5, width: float = 1., name='change_window', fixed_slope = False):
super(ChangeWindowKernelWithWidth, self).__init__(left, right, SigmoidalIndicatorKernel, location, slope, name, fixed_slope)
super(ChangeWindowKernelWithWidth, self).__init__(left, right, SigmoidalIndicatorKernelWithWidth, location, slope, name, fixed_slope)
self.width = Param('width', width, Logexp())
self.link_parameter(self.width)

Expand Down
8 changes: 4 additions & 4 deletions GPy_ABCD/Kernels/sigmoidalKernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SigmoidalKernel(SigmoidalKernelBase):

def __init__(self, input_dim: int, reverse: bool = False, variance: float = 1., location: float = 0., slope: float = 0.5,
active_dims: int = None, name: str = 'sigmoidal', fixed_slope = False) -> None:
super(SigmoidalKernel, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name)
super(SigmoidalKernel, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name, fixed_slope)

def is_reversed(self):
return (self.slope < 0) ^ self.reverse
Expand Down Expand Up @@ -122,7 +122,7 @@ class SigmoidalIndicatorKernelOneLocation(SigmoidalKernelBase):

def __init__(self, input_dim: int, reverse: bool = False, variance: float = 1., location: float = 0., slope: float = 0.5,
active_dims: int = None, name: str = 'sigmoidal_indicator', fixed_slope = False) -> None:
super(SigmoidalIndicatorKernelOneLocation, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name)
super(SigmoidalIndicatorKernelOneLocation, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name, fixed_slope)

@staticmethod
def _tanhSigOneLocIndicatorHalfWidth(s, y = 0.01): # Distance from peak of 1-location indicator kernel to when y is reached
Expand Down Expand Up @@ -191,7 +191,7 @@ class SigmoidalIndicatorKernel(SigmoidalKernelBase):

def __init__(self, input_dim: int, reverse: bool = False, variance: float = 1., location: float = 0., stop_location: float = 1., slope: float = 0.5,
active_dims: int = None, name: str = 'sigmoidal_indicator', fixed_slope = False) -> None:
super(SigmoidalIndicatorKernel, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name)
super(SigmoidalIndicatorKernel, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name, fixed_slope)
self.stop_location = Param('stop_location', stop_location)
self.link_parameters(self.stop_location)

Expand Down Expand Up @@ -266,7 +266,7 @@ class SigmoidalIndicatorKernelWithWidth(SigmoidalKernelBase):

def __init__(self, input_dim: int, reverse: bool = False, variance: float = 1., location: float = 0., slope: float = 0.5, width: float = 1.,
active_dims: int = None, name: str = 'sigmoidal_indicator', fixed_slope = False) -> None:
super(SigmoidalIndicatorKernelWithWidth, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name)
super(SigmoidalIndicatorKernelWithWidth, self).__init__(input_dim, reverse, variance, location, slope, active_dims, name, fixed_slope)
self.width = Param('width', width, Logexp())
self.link_parameters(self.width)

Expand Down
10 changes: 5 additions & 5 deletions Tests/regressChangeOperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from GPy_ABCD.Util.dataAndPlottingUtil import *


X, Y = generate_changepoint_data(np.linspace(-20, 20, 201), lambda x: 0.1 * x, lambda x: 3 * np.sin(x), 0, 1, 0.3, True)
kernel = CP(LIN(), PER() + C())
# X, Y = generate_changepoint_data(np.linspace(-20, 20, 201), lambda x: 0.1 * x, lambda x: 3 * np.sin(x), -3, 1, 0.3, True)
# kernel = CP(LIN(), PER() + C())


# X, Y = generate_changewindow_data(np.linspace(-10, 30, 212), lambda x: 0.05 * x, lambda x: 0.05 * x * (x - 14), 0, 15, 1, 0.3, False)
# kernel = CW(LIN(), LIN() * LIN())
# # kernel = CW(LIN() * LIN(), LIN())
X, Y = generate_changewindow_data(np.linspace(-10, 30, 212), lambda x: 0.05 * x, lambda x: 0.05 * x * (x - 14), 0, 15, 1, 0.3, False)
kernel = CW(LIN(), LIN() * LIN())
# kernel = CW(LIN() * LIN(), LIN())


# X, Y = generate_changewindow_data(np.linspace(-10, 20, 212), lambda x: 2, lambda x: 2 + 3 * np.sin(x*2), 0, 15, 1, 0.3, False)
Expand Down

0 comments on commit 7aab7a4

Please sign in to comment.