mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
Working on putting callback to update laplace in callback
This commit is contained in:
parent
6c4866662c
commit
9500b12b53
4 changed files with 26 additions and 2 deletions
|
|
@ -29,7 +29,7 @@ class Optimizer():
|
||||||
:rtype: optimizer object.
|
:rtype: optimizer object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, x_init, messages=False, model = None, max_f_eval=1e4, max_iters = 1e3, ftol=None, gtol=None, xtol=None):
|
def __init__(self, x_init, messages=False, model = None, max_f_eval=1e4, max_iters = 1e3, ftol=None, gtol=None, xtol=None, callback=None):
|
||||||
self.opt_name = None
|
self.opt_name = None
|
||||||
self.x_init = x_init
|
self.x_init = x_init
|
||||||
self.messages = messages
|
self.messages = messages
|
||||||
|
|
@ -45,6 +45,7 @@ class Optimizer():
|
||||||
self.gtol = gtol
|
self.gtol = gtol
|
||||||
self.ftol = ftol
|
self.ftol = ftol
|
||||||
self.model = model
|
self.model = model
|
||||||
|
self.callback = callback
|
||||||
|
|
||||||
def run(self, **kwargs):
|
def run(self, **kwargs):
|
||||||
start = dt.datetime.now()
|
start = dt.datetime.now()
|
||||||
|
|
@ -94,6 +95,8 @@ class opt_tnc(Optimizer):
|
||||||
opt_dict['ftol'] = self.ftol
|
opt_dict['ftol'] = self.ftol
|
||||||
if self.gtol is not None:
|
if self.gtol is not None:
|
||||||
opt_dict['pgtol'] = self.gtol
|
opt_dict['pgtol'] = self.gtol
|
||||||
|
if self.callback is not None:
|
||||||
|
opt_dict['callback'] = self.callback
|
||||||
|
|
||||||
opt_result = optimize.fmin_tnc(f_fp, self.x_init, messages = self.messages,
|
opt_result = optimize.fmin_tnc(f_fp, self.x_init, messages = self.messages,
|
||||||
maxfun = self.max_f_eval, **opt_dict)
|
maxfun = self.max_f_eval, **opt_dict)
|
||||||
|
|
@ -128,6 +131,8 @@ class opt_lbfgsb(Optimizer):
|
||||||
print "WARNING: l-bfgs-b doesn't have an ftol arg, so I'm going to ignore it"
|
print "WARNING: l-bfgs-b doesn't have an ftol arg, so I'm going to ignore it"
|
||||||
if self.gtol is not None:
|
if self.gtol is not None:
|
||||||
opt_dict['pgtol'] = self.gtol
|
opt_dict['pgtol'] = self.gtol
|
||||||
|
if self.callback is not None:
|
||||||
|
opt_dict['callback'] = self.callback
|
||||||
|
|
||||||
opt_result = optimize.fmin_l_bfgs_b(f_fp, self.x_init, iprint = iprint,
|
opt_result = optimize.fmin_l_bfgs_b(f_fp, self.x_init, iprint = iprint,
|
||||||
maxfun = self.max_f_eval, **opt_dict)
|
maxfun = self.max_f_eval, **opt_dict)
|
||||||
|
|
@ -155,6 +160,8 @@ class opt_simplex(Optimizer):
|
||||||
opt_dict['ftol'] = self.ftol
|
opt_dict['ftol'] = self.ftol
|
||||||
if self.gtol is not None:
|
if self.gtol is not None:
|
||||||
print "WARNING: simplex doesn't have an gtol arg, so I'm going to ignore it"
|
print "WARNING: simplex doesn't have an gtol arg, so I'm going to ignore it"
|
||||||
|
if self.callback is not None:
|
||||||
|
opt_dict['callback'] = self.callback
|
||||||
|
|
||||||
opt_result = optimize.fmin(f, self.x_init, (), disp = self.messages,
|
opt_result = optimize.fmin(f, self.x_init, (), disp = self.messages,
|
||||||
maxfun = self.max_f_eval, full_output=True, **opt_dict)
|
maxfun = self.max_f_eval, full_output=True, **opt_dict)
|
||||||
|
|
@ -187,6 +194,8 @@ class opt_rasm(Optimizer):
|
||||||
print "WARNING: minimize doesn't have an ftol arg, so I'm going to ignore it"
|
print "WARNING: minimize doesn't have an ftol arg, so I'm going to ignore it"
|
||||||
if self.gtol is not None:
|
if self.gtol is not None:
|
||||||
print "WARNING: minimize doesn't have an gtol arg, so I'm going to ignore it"
|
print "WARNING: minimize doesn't have an gtol arg, so I'm going to ignore it"
|
||||||
|
if self.callback is not None:
|
||||||
|
print "WARNING: minimize doesn't have a callback arg, so I'm going to ignore it"
|
||||||
|
|
||||||
opt_result = rasm.minimize(self.x_init, f_fp, (), messages = self.messages,
|
opt_result = rasm.minimize(self.x_init, f_fp, (), messages = self.messages,
|
||||||
maxnumfuneval = self.max_f_eval)
|
maxnumfuneval = self.max_f_eval)
|
||||||
|
|
@ -205,6 +214,8 @@ class opt_SCG(Optimizer):
|
||||||
def opt(self, f_fp = None, f = None, fp = None):
|
def opt(self, f_fp = None, f = None, fp = None):
|
||||||
assert not f is None
|
assert not f is None
|
||||||
assert not fp is None
|
assert not fp is None
|
||||||
|
if self.callback is not None:
|
||||||
|
print "WARNING: SCG doesn't have a callback arg, so I'm going to ignore it"
|
||||||
opt_result = SCG(f,fp,self.x_init, display=self.messages, maxiters=self.max_iters, max_f_eval=self.max_f_eval, xtol=self.xtol, ftol=self.ftol)
|
opt_result = SCG(f,fp,self.x_init, display=self.messages, maxiters=self.max_iters, max_f_eval=self.max_f_eval, xtol=self.xtol, ftol=self.ftol)
|
||||||
self.x_opt = opt_result[0]
|
self.x_opt = opt_result[0]
|
||||||
self.trace = opt_result[1]
|
self.trace = opt_result[1]
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ class Laplace(likelihood):
|
||||||
return self.likelihood_function._get_param_names()
|
return self.likelihood_function._get_param_names()
|
||||||
|
|
||||||
def _set_params(self, p):
|
def _set_params(self, p):
|
||||||
print "Setting noise sd: ", p
|
|
||||||
return self.likelihood_function._set_params(p)
|
return self.likelihood_function._set_params(p)
|
||||||
|
|
||||||
def both_gradients(self, dL_d_K_Sigma, dK_dthetaK):
|
def both_gradients(self, dL_d_K_Sigma, dK_dthetaK):
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,8 @@ class student_t(likelihood_function):
|
||||||
self.log_concave = False
|
self.log_concave = False
|
||||||
#super(student_t, self).__init__()
|
#super(student_t, self).__init__()
|
||||||
|
|
||||||
|
self._set_params(np.asarray(sigma))
|
||||||
|
|
||||||
def _get_params(self):
|
def _get_params(self):
|
||||||
return np.asarray(self.sigma)
|
return np.asarray(self.sigma)
|
||||||
|
|
||||||
|
|
@ -174,6 +176,8 @@ class student_t(likelihood_function):
|
||||||
|
|
||||||
def _set_params(self, x):
|
def _set_params(self, x):
|
||||||
self.sigma = float(x)
|
self.sigma = float(x)
|
||||||
|
print "Setting student t sigma: ", x
|
||||||
|
print x
|
||||||
#self.covariance_matrix = np.eye(self.N)*self._variance
|
#self.covariance_matrix = np.eye(self.N)*self._variance
|
||||||
#self.precision = 1./self._variance
|
#self.precision = 1./self._variance
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,16 @@ class GP(model):
|
||||||
def _get_param_names(self):
|
def _get_param_names(self):
|
||||||
return self.kern._get_param_names_transformed() + self.likelihood._get_param_names()
|
return self.kern._get_param_names_transformed() + self.likelihood._get_param_names()
|
||||||
|
|
||||||
|
def _update_params_callback(self, p):
|
||||||
|
#FIXME:Check the transforming
|
||||||
|
#Set the new parameters of the kernel and likelihood within the optimization
|
||||||
|
import ipdb; ipdb.set_trace() ### XXX BREAKPOINT
|
||||||
|
self.kern._set_params_transformed(p[:self.kern.Nparam_transformed()])
|
||||||
|
self.likelihood._set_params(p[self.kern.Nparam_transformed():])
|
||||||
|
#update the likelihood approximation within the optimisation with the current parameters
|
||||||
|
self.update_likelihood_approximation()
|
||||||
|
import ipdb; ipdb.set_trace() ### XXX BREAKPOINT
|
||||||
|
|
||||||
def update_likelihood_approximation(self):
|
def update_likelihood_approximation(self):
|
||||||
"""
|
"""
|
||||||
Approximates a non-gaussian likelihood using Expectation Propagation
|
Approximates a non-gaussian likelihood using Expectation Propagation
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue