mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
minor changes, dimensionality reduction tests
This commit is contained in:
parent
a7692678c9
commit
26d68861ca
5 changed files with 29 additions and 16 deletions
|
|
@ -266,15 +266,19 @@ def bgplvm_simulation(optimize='scg',
|
|||
|
||||
if optimize:
|
||||
print "Optimizing model:"
|
||||
m.optimize('scg', max_iters=max_f_eval, max_f_eval=max_f_eval, messages=True)
|
||||
m.optimize('bfgs', max_iters=max_f_eval,
|
||||
max_f_eval=max_f_eval,
|
||||
messages=True, gtol=1e-2)
|
||||
if plot:
|
||||
import pylab
|
||||
m.plot_X_1d()
|
||||
pylab.figure(); pylab.axis(); m.kern.plot_ARD()
|
||||
pylab.figure('BGPLVM Simulation ARD Parameters');
|
||||
pylab.axis();
|
||||
m.kern.plot_ARD()
|
||||
return m
|
||||
|
||||
def mrd_simulation(optimize=True, plot_sim=False, **kw):
|
||||
D1, D2, D3, N, M, Q = 150, 250, 30, 200, 3, 7
|
||||
D1, D2, D3, N, M, Q = 15, 8, 8, 100, 3, 7
|
||||
slist, Slist, Ylist = _simulate_sincos(D1, D2, D3, N, M, Q, plot_sim)
|
||||
|
||||
from GPy.models import mrd
|
||||
|
|
@ -284,20 +288,20 @@ def mrd_simulation(optimize=True, plot_sim=False, **kw):
|
|||
reload(mrd); reload(kern)
|
||||
|
||||
k = kern.linear(Q, [0.01] * Q, True) + kern.bias(Q, np.exp(-2)) + kern.white(Q, np.exp(-2))
|
||||
m = mrd.MRD(*Ylist, Q=Q, M=M, kernel=k, initx="concat", initz='permute', **kw)
|
||||
m = mrd.MRD(Ylist, Q=Q, M=M, kernel=k, initx="concat", initz='permute', **kw)
|
||||
|
||||
for i, Y in enumerate(Ylist):
|
||||
m['{}_noise'.format(i + 1)] = Y.var() / 100.
|
||||
|
||||
# m.constrain('variance|noise', logexp_clipped())
|
||||
m.constrain('variance|noise', logexp_clipped())
|
||||
m.ensure_default_constraints()
|
||||
|
||||
# DEBUG
|
||||
np.seterr("raise")
|
||||
# np.seterr("raise")
|
||||
|
||||
if optimize:
|
||||
print "Optimizing Model:"
|
||||
m.optimize('scg', messages=1, max_iters=3e3)
|
||||
m.optimize('bfgs', messages=1, max_iters=3e3)
|
||||
|
||||
return m
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@
|
|||
import numpy as np
|
||||
import sys
|
||||
|
||||
|
||||
def print_out(len_maxiters, display, fnow, current_grad, beta, iteration):
|
||||
if display:
|
||||
print '\r',
|
||||
print '{0:>0{mi}g} {1:> 12e} {2:> 12e} {3:> 12e}'.format(iteration, float(fnow), float(beta), float(current_grad), mi=len_maxiters), # print 'Iteration:', iteration, ' Objective:', fnow, ' Scale:', beta, '\r',
|
||||
sys.stdout.flush()
|
||||
|
||||
def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=500, display=True, xtol=None, ftol=None, gtol=None):
|
||||
"""
|
||||
Optimisation through Scaled Conjugate Gradients (SCG)
|
||||
|
|
@ -65,7 +72,8 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=500, display=True, xto
|
|||
iteration = 0
|
||||
|
||||
if display:
|
||||
print ' {0:{mi}s} {1:11s} {2:11s} {3:11s}'.format("I", "F", "Scale", "|g|", mi=len(str(maxiters)))
|
||||
len_maxiters = len(str(maxiters))
|
||||
print ' {0:{mi}s} {1:11s} {2:11s} {3:11s}'.format("I", "F", "Scale", "|g|", mi=len_maxiters)
|
||||
|
||||
# Main optimization loop.
|
||||
while iteration < maxiters:
|
||||
|
|
@ -113,11 +121,7 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=500, display=True, xto
|
|||
flog.append(fnow) # Current function value
|
||||
|
||||
iteration += 1
|
||||
if display:
|
||||
print '\r',
|
||||
print '{0:>0{mi}g} {1:> 12e} {2:> 12e} {3:> 12e}'.format(iteration, float(fnow), float(beta), float(current_grad), mi=len(str(maxiters))),
|
||||
# print 'Iteration:', iteration, ' Objective:', fnow, ' Scale:', beta, '\r',
|
||||
sys.stdout.flush()
|
||||
print_out(len_maxiters, display, fnow, current_grad, beta, iteration)
|
||||
|
||||
if success:
|
||||
# Test for termination
|
||||
|
|
@ -158,5 +162,6 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=500, display=True, xto
|
|||
status = "maxiter exceeded"
|
||||
|
||||
if display:
|
||||
print_out(len_maxiters, display, fnow, current_grad, beta, iteration)
|
||||
print ""
|
||||
return x, flog, function_eval, status
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class Gaussian(likelihood):
|
|||
def _set_params(self, x):
|
||||
x = float(x)
|
||||
if self._variance != x:
|
||||
self.precision = 1. / max(x, 1e-6)
|
||||
self.precision = 1. / x
|
||||
self.covariance_matrix = np.eye(self.N) * x
|
||||
self.V = (self.precision) * self.Y
|
||||
self._variance = x
|
||||
|
|
|
|||
|
|
@ -93,8 +93,12 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
|||
x = np.hstack((self.X.flatten(), self.X_variance.flatten(), sparse_GP._get_params(self)))
|
||||
return x
|
||||
|
||||
def _clipped(self, x):
|
||||
return x # np.clip(x, -1e100, 1e100)
|
||||
|
||||
def _set_params(self, x, save_old=True, save_count=0):
|
||||
# try:
|
||||
x = self._clipped(x)
|
||||
N, Q = self.N, self.Q
|
||||
self.X = x[:self.X.size].reshape(N, Q).copy()
|
||||
self.X_variance = x[(N * Q):(2 * N * Q)].reshape(N, Q).copy()
|
||||
|
|
@ -176,7 +180,7 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
|||
# ========================
|
||||
self.dbound_dmuS = np.hstack((d_dmu, d_dS))
|
||||
self.dbound_dZtheta = sparse_GP._log_likelihood_gradients(self)
|
||||
return np.hstack((self.dbound_dmuS.flatten(), self.dbound_dZtheta))
|
||||
return self._clipped(np.hstack((self.dbound_dmuS.flatten(), self.dbound_dZtheta)))
|
||||
|
||||
def plot_latent(self, which_indices=None, *args, **kwargs):
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class GPLVM(GP):
|
|||
else:
|
||||
x = self.X[index,input_1]
|
||||
y = self.X[index,input_2]
|
||||
ax.scatter(x, y, marker=m, s=s, color=util.plot.Tango.nextMedium(), mew=1.3, label=this_label)
|
||||
ax.scatter(x, y, marker=m, s=s, color=util.plot.Tango.nextMedium(), label=this_label)
|
||||
|
||||
ax.set_xlabel('latent dimension %i'%input_1)
|
||||
ax.set_ylabel('latent dimension %i'%input_2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue