mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-04 01:02:39 +02:00
some gplvm related fixes
This commit is contained in:
parent
a71bbc0d21
commit
563fbd257b
6 changed files with 19 additions and 26 deletions
|
|
@ -154,7 +154,7 @@ class Param(ObservableArray, Constrainable):
|
||||||
def _parameters_(self):
|
def _parameters_(self):
|
||||||
return []
|
return []
|
||||||
def _collect_gradient(self, target):
|
def _collect_gradient(self, target):
|
||||||
target[:] = self.gradient
|
target[:] = self.gradient.flat
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
# Fixing Parameters:
|
# Fixing Parameters:
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
|
|
|
||||||
|
|
@ -347,11 +347,11 @@ class kern(Parameterized):
|
||||||
|
|
||||||
def update_gradients_full(self, dL_dK, X):
|
def update_gradients_full(self, dL_dK, X):
|
||||||
[p.update_gradients_full(dL_dK, X) for p in self._parameters_]
|
[p.update_gradients_full(dL_dK, X) for p in self._parameters_]
|
||||||
pass
|
|
||||||
def update_gradients_sparse(self, dL_dKmm, dL_dKnm, dL_dKdiag, X, Z):
|
def update_gradients_sparse(self, dL_dKmm, dL_dKnm, dL_dKdiag, X, Z):
|
||||||
pass
|
raise NotImplementedError
|
||||||
def update_gradients_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, mu, S, Z):
|
def update_gradients_variational(self, dL_dKmm, dL_dpsi0, dL_dpsi1, dL_dpsi2, mu, S, Z):
|
||||||
pass
|
raise NotImplementedError
|
||||||
|
|
||||||
def dK_dtheta(self, dL_dK, X, X2=None):
|
def dK_dtheta(self, dL_dK, X, X2=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -375,7 +375,7 @@ class kern(Parameterized):
|
||||||
|
|
||||||
return self._transform_gradients(target)
|
return self._transform_gradients(target)
|
||||||
|
|
||||||
def dK_dX(self, dL_dK, X, X2=None):
|
def gradients_X(self, dL_dK, X, X2=None):
|
||||||
"""Compute the gradient of the objective function with respect to X.
|
"""Compute the gradient of the objective function with respect to X.
|
||||||
|
|
||||||
:param dL_dK: An array of gradients of the objective function with respect to the covariance function.
|
:param dL_dK: An array of gradients of the objective function with respect to the covariance function.
|
||||||
|
|
@ -387,9 +387,9 @@ class kern(Parameterized):
|
||||||
|
|
||||||
target = np.zeros_like(X)
|
target = np.zeros_like(X)
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
[p.dK_dX(dL_dK, X[:, i_s], None, target[:, i_s]) for p, i_s in zip(self._parameters_, self.input_slices)]
|
[p.gradients_X(dL_dK, X[:, i_s], None, target[:, i_s]) for p, i_s in zip(self._parameters_, self.input_slices)]
|
||||||
else:
|
else:
|
||||||
[p.dK_dX(dL_dK, X[:, i_s], X2[:, i_s], target[:, i_s]) for p, i_s in zip(self._parameters_, self.input_slices)]
|
[p.gradients_X(dL_dK, X[:, i_s], X2[:, i_s], target[:, i_s]) for p, i_s in zip(self._parameters_, self.input_slices)]
|
||||||
return target
|
return target
|
||||||
|
|
||||||
def Kdiag(self, X, which_parts='all'):
|
def Kdiag(self, X, which_parts='all'):
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,6 @@ class Bias(Kernpart):
|
||||||
super(Bias, self).__init__(input_dim, name)
|
super(Bias, self).__init__(input_dim, name)
|
||||||
self.variance = Param("variance", variance)
|
self.variance = Param("variance", variance)
|
||||||
self.add_parameter(self.variance)
|
self.add_parameter(self.variance)
|
||||||
#self._set_params(np.array([variance]).flatten())
|
|
||||||
|
|
||||||
# def _get_params(self):
|
|
||||||
# return self.variance
|
|
||||||
#
|
|
||||||
# def _set_params(self,x):
|
|
||||||
# assert x.shape==(1,)
|
|
||||||
# self.variance = x
|
|
||||||
#
|
|
||||||
# def _get_param_names(self):
|
|
||||||
# return ['variance']
|
|
||||||
|
|
||||||
def K(self,X,X2,target):
|
def K(self,X,X2,target):
|
||||||
target += self.variance
|
target += self.variance
|
||||||
|
|
@ -34,18 +23,21 @@ class Bias(Kernpart):
|
||||||
def Kdiag(self,X,target):
|
def Kdiag(self,X,target):
|
||||||
target += self.variance
|
target += self.variance
|
||||||
|
|
||||||
def dK_dtheta(self,dL_dKdiag,X,X2,target):
|
#def dK_dtheta(self,dL_dKdiag,X,X2,target):
|
||||||
target += dL_dKdiag.sum()
|
#target += dL_dKdiag.sum()
|
||||||
|
def update_gradients_full(self, dL_dK, X):
|
||||||
|
self.variance.gradient = dL_dK.sum()
|
||||||
|
|
||||||
def dKdiag_dtheta(self,dL_dKdiag,X,target):
|
def dKdiag_dtheta(self,dL_dKdiag,X,target):
|
||||||
target += dL_dKdiag.sum()
|
target += dL_dKdiag.sum()
|
||||||
|
|
||||||
def dK_dX(self, dL_dK,X, X2, target):
|
def gradients_X(self, dL_dK,X, X2, target):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def dKdiag_dX(self,dL_dKdiag,X,target):
|
def dKdiag_dX(self,dL_dKdiag,X,target):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------#
|
#---------------------------------------#
|
||||||
# PSI statistics #
|
# PSI statistics #
|
||||||
#---------------------------------------#
|
#---------------------------------------#
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ class RBF(Kernpart):
|
||||||
else:
|
else:
|
||||||
self.lengthscale.gradient += (self.variance / self.lengthscale) * np.sum(self._K_dvar * self._K_dist2 * dL_dK)
|
self.lengthscale.gradient += (self.variance / self.lengthscale) * np.sum(self._K_dvar * self._K_dist2 * dL_dK)
|
||||||
|
|
||||||
def _gradients_X(self, dL_dK, X, X2, target):
|
def gradients_X(self, dL_dK, X, X2, target):
|
||||||
#if self._X is None or X.base is not self._X.base or X2 is not None:
|
#if self._X is None or X.base is not self._X.base or X2 is not None:
|
||||||
self._K_computations(X, X2)
|
self._K_computations(X, X2)
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
|
|
@ -260,7 +260,7 @@ class RBF(Kernpart):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
num_data, num_inducing, input_dim = X.shape[0], X.shape[0], self.input_dim
|
num_data, num_inducing, input_dim = X.shape[0], X.shape[0], self.input_dim
|
||||||
X = param_to_array(X)
|
X, dvardLdK = param_to_array(X, dvardLdK)
|
||||||
weave.inline(code, arg_names=['num_data', 'num_inducing', 'input_dim', 'X', 'target', 'dvardLdK', 'var_len3'], type_converters=weave.converters.blitz, **self.weave_options)
|
weave.inline(code, arg_names=['num_data', 'num_inducing', 'input_dim', 'X', 'target', 'dvardLdK', 'var_len3'], type_converters=weave.converters.blitz, **self.weave_options)
|
||||||
else:
|
else:
|
||||||
code = """
|
code = """
|
||||||
|
|
@ -277,7 +277,7 @@ class RBF(Kernpart):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
num_data, num_inducing, input_dim = X.shape[0], X2.shape[0], self.input_dim
|
num_data, num_inducing, input_dim = X.shape[0], X2.shape[0], self.input_dim
|
||||||
X, X2 = param_to_array(X, X2)
|
X, X2, dvardLdK = param_to_array(X, X2, dvardLdK)
|
||||||
weave.inline(code, arg_names=['num_data', 'num_inducing', 'input_dim', 'X', 'X2', 'target', 'dvardLdK', 'var_len3'], type_converters=weave.converters.blitz, **self.weave_options)
|
weave.inline(code, arg_names=['num_data', 'num_inducing', 'input_dim', 'X', 'X2', 'target', 'dvardLdK', 'var_len3'], type_converters=weave.converters.blitz, **self.weave_options)
|
||||||
return target
|
return target
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class GPLVM(GP):
|
||||||
|
|
||||||
super(GPLVM, self).__init__(X, Y, kernel, likelihood, name='GPLVM')
|
super(GPLVM, self).__init__(X, Y, kernel, likelihood, name='GPLVM')
|
||||||
self.X = Param('X', X)
|
self.X = Param('X', X)
|
||||||
self.add_parameter(self.X, ndex=0)
|
self.add_parameter(self.X, index=0)
|
||||||
|
|
||||||
def initialise_latent(self, init, input_dim, Y):
|
def initialise_latent(self, init, input_dim, Y):
|
||||||
Xr = np.random.randn(Y.shape[0], input_dim)
|
Xr = np.random.randn(Y.shape[0], input_dim)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import pylab as pb
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .. import util
|
from .. import util
|
||||||
from GPy.util.latent_space_visualizations.controllers.imshow_controller import ImshowController
|
from GPy.util.latent_space_visualizations.controllers.imshow_controller import ImshowController
|
||||||
|
from misc import param_to_array
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
def most_significant_input_dimensions(model, which_indices):
|
def most_significant_input_dimensions(model, which_indices):
|
||||||
|
|
@ -74,7 +75,7 @@ def plot_latent(model, labels=None, which_indices=None,
|
||||||
|
|
||||||
index = np.nonzero(labels == ul)[0]
|
index = np.nonzero(labels == ul)[0]
|
||||||
if model.input_dim == 1:
|
if model.input_dim == 1:
|
||||||
x = model.X[index, input_1]
|
x = param_to_array(model.X)[index, input_1]
|
||||||
y = np.zeros(index.size)
|
y = np.zeros(index.size)
|
||||||
else:
|
else:
|
||||||
x = model.X[index, input_1]
|
x = model.X[index, input_1]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue