GPy/GPy/models/gplvm.py

45 lines
1.3 KiB
Python
Raw Normal View History

2014-11-21 12:10:50 +00:00
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
2013-06-05 14:11:49 +01:00
# Licensed under the BSD 3-clause license (see LICENSE.txt)
import numpy as np
from .. import kern
2014-01-24 15:48:45 +00:00
from ..core import GP, Param
2013-06-05 14:11:49 +01:00
from ..likelihoods import Gaussian
class GPLVM(GP):
"""
Gaussian Process Latent Variable Model
"""
2014-11-05 14:58:37 +00:00
def __init__(self, Y, input_dim, init='PCA', X=None, kernel=None, name="gplvm"):
2014-01-24 15:56:27 +00:00
"""
:param Y: observed data
:type Y: np.ndarray
:param input_dim: latent dimensionality
:type input_dim: int
:param init: initialisation method for the latent space
:type init: 'PCA'|'random'
"""
2013-06-05 14:11:49 +01:00
if X is None:
2014-02-24 14:47:43 +00:00
from ..util.initialization import initialize_latent
2014-03-24 11:16:57 +00:00
X, fracs = initialize_latent(init, input_dim, Y)
else:
fracs = np.ones(input_dim)
2013-06-05 14:11:49 +01:00
if kernel is None:
2014-03-24 11:16:57 +00:00
kernel = kern.RBF(input_dim, lengthscale=fracs, ARD=input_dim > 1) + kern.Bias(input_dim, np.exp(-2))
2014-01-24 15:56:27 +00:00
likelihood = Gaussian()
super(GPLVM, self).__init__(X, Y, kernel, likelihood, name='GPLVM')
2014-02-24 14:47:43 +00:00
self.X = Param('latent_mean', X)
self.link_parameter(self.X, index=0)
2013-06-05 14:11:49 +01:00
2014-01-24 15:56:27 +00:00
def parameters_changed(self):
2014-02-24 14:47:43 +00:00
super(GPLVM, self).parameters_changed()
self.X.gradient = self.kern.gradients_X(self.grad_dict['dL_dK'], self.X, None)