From 7aab7a428cc013f15a397411ceab72f4dcd91e9c Mon Sep 17 00:00:00 2001 From: T-Flet Date: Fri, 31 Jan 2020 17:37:29 +0000 Subject: [PATCH] Started reviewing change and sigmoidal kernels to improve CW --- GPy_ABCD/Kernels/changeOperators.py | 4 ++-- GPy_ABCD/Kernels/sigmoidalKernels.py | 8 ++++---- Tests/regressChangeOperators.py | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/GPy_ABCD/Kernels/changeOperators.py b/GPy_ABCD/Kernels/changeOperators.py index 19af3f1..79acd85 100644 --- a/GPy_ABCD/Kernels/changeOperators.py +++ b/GPy_ABCD/Kernels/changeOperators.py @@ -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): @@ -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) diff --git a/GPy_ABCD/Kernels/sigmoidalKernels.py b/GPy_ABCD/Kernels/sigmoidalKernels.py index 3551b99..c5eb2b5 100644 --- a/GPy_ABCD/Kernels/sigmoidalKernels.py +++ b/GPy_ABCD/Kernels/sigmoidalKernels.py @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/Tests/regressChangeOperators.py b/Tests/regressChangeOperators.py index 257c18d..2dcbb1e 100644 --- a/Tests/regressChangeOperators.py +++ b/Tests/regressChangeOperators.py @@ -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)