changes tie_param to tie_params

This commit is contained in:
James Hensman 2013-03-11 16:46:47 +00:00
parent 4b9064bb0e
commit 5b86fce1b3
6 changed files with 27 additions and 8 deletions

View file

@ -56,7 +56,7 @@ class parameterised(object):
return copy.deepcopy(self)
def tie_param(self, which):
def tie_params(self, which):
matches = self.grep_param_names(which)
assert matches.size > 0, "need at least something to tie together"
if len(self.tied_indices):

View file

@ -62,7 +62,7 @@ def oil():
# Contrain all parameters to be positive
m.constrain_positive('')
m.tie_param('lengthscale')
m.tie_params('lengthscale')
m.update_likelihood_approximation()
# Optimize

View file

@ -138,7 +138,7 @@ def tuto_kernel_overview():
k.constrain_positive('var')
k.constrain_fixed(np.array([1]),1.75)
k.tie_param('len')
k.tie_params('len')
k.unconstrain('white')
k.constrain_bounded('white',lower=1e-5,upper=.5)
print k

View file

@ -237,7 +237,7 @@ class kern(parameterised):
for i in range(K1.Nparam + K2.Nparam):
index = np.where(index_param==i)[0]
if index.size > 1:
self.tie_param(index)
self.tie_params(index)
for i in prev_constr_pos:
self.constrain_positive(np.where(index_param==i)[0])
for i in prev_constr_neg:
@ -391,9 +391,13 @@ class kern(parameterised):
target += p2.variance*(p1._psi1[:,:,None]+p1._psi1[:,None,:])
#linear X bias
elif p1.name=='bias' and p2.name=='linear':
raise NotImplementedError
tmp = np.zeros((mu.shape[0],Z.shape[0]))
p2.psi1(Z,mu,S,tmp)
target += p1.variance*(tmp[:,:,None] + tmp[:,None,:])
elif p2.name=='bias' and p1.name=='linear':
raise NotImplementedError
tmp = np.zeros((mu.shape[0],Z.shape[0]))
p1.psi1(Z,mu,S,tmp)
target += p2.variance*(tmp[:,:,None] + tmp[:,None,:])
#rbf X linear
elif p1.name=='linear' and p2.name=='rbf':
raise NotImplementedError #TODO
@ -426,6 +430,11 @@ class kern(parameterised):
elif p2.name=='bias' and p1.name=='rbf':
p1.dpsi1_dtheta(dL_dpsi2.sum(1)*p2.variance*2.,Z,mu,S,target[ps1])
p2.dpsi1_dtheta(dL_dpsi2.sum(1)*p1._psi1*2.,Z,mu,S,target[ps2])
#linear X bias
elif p1.name=='bias' and p2.name=='linear':
p2.dpsi1_dtheta(dL_dpsi2.sum(1)*p1.variance*2., Z, mu, S, target[ps1])
elif p2.name=='bias' and p1.name=='linear':
p1.dpsi1_dtheta(dL_dpsi2.sum(1)*p2.variance*2., Z, mu, S, target[ps1])
#rbf X linear
elif p1.name=='linear' and p2.name=='rbf':
raise NotImplementedError #TODO
@ -451,6 +460,11 @@ class kern(parameterised):
p2.dpsi1_dX(dL_dpsi2.sum(1).T*p1.variance,Z,mu,S,target)
elif p2.name=='bias' and p1.name=='rbf':
p1.dpsi1_dZ(dL_dpsi2.sum(1).T*p2.variance,Z,mu,S,target)
#linear X bias
elif p1.name=='bias' and p2.name=='linear':
p2.dpsi1_dZ(dL_dpsi2.sum(1).T*p1.variance, Z, mu, S, target)
elif p2.name=='bias' and p1.name=='linear':
p1.dpsi1_dZ(dL_dpsi2.sum(1).T*p2.variance, Z, mu, S, target)
#rbf X linear
elif p1.name=='linear' and p2.name=='rbf':
raise NotImplementedError #TODO
@ -478,6 +492,11 @@ class kern(parameterised):
p2.dpsi1_dmuS(dL_dpsi2.sum(1).T*p1.variance*2.,Z,mu,S,target_mu,target_S)
elif p2.name=='bias' and p1.name=='rbf':
p1.dpsi1_dmuS(dL_dpsi2.sum(1).T*p2.variance*2.,Z,mu,S,target_mu,target_S)
#linear X bias
elif p1.name=='bias' and p2.name=='linear':
p2.dpsi1_dmuS(dL_dpsi2.sum(1).T*p1.variance*2., Z, mu, S, target_mu, target_S)
elif p2.name=='bias' and p1.name=='linear':
p1.dpsi1_dmuS(dL_dpsi2.sum(1).T*p2.variance*2., Z, mu, S, target_mu, target_S)
#rbf X linear
elif p1.name=='linear' and p2.name=='rbf':
raise NotImplementedError #TODO

View file

@ -58,7 +58,7 @@ class BGPLVMTests(unittest.TestCase):
m.randomize()
self.assertTrue(m.checkgrad())
@unittest.skip('psi2 cross terms are NotImplemented for this combination')
#@unittest.skip('psi2 cross terms are NotImplemented for this combination')
def test_linear_bias_kern(self):
N, M, Q, D = 10, 3, 2, 4
X = np.random.rand(N, Q)

View file

@ -8,7 +8,7 @@ import GPy
class KernelTests(unittest.TestCase):
def test_kerneltie(self):
K = GPy.kern.rbf(5, ARD=True)
K.tie_param('[01]')
K.tie_params('[01]')
K.constrain_fixed('2')
X = np.random.rand(5,5)
Y = np.ones((5,1))