mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-05 14:55:15 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
cfdd72fc72
11 changed files with 1374 additions and 21 deletions
|
|
@ -256,8 +256,9 @@ class Model(Parameterized):
|
||||||
optimizer = optimization.get_optimizer(optimizer)
|
optimizer = optimization.get_optimizer(optimizer)
|
||||||
opt = optimizer(start, model=self, max_iters=max_iters, **kwargs)
|
opt = optimizer(start, model=self, max_iters=max_iters, **kwargs)
|
||||||
|
|
||||||
with VerboseOptimization(self, opt, maxiters=max_iters, verbose=messages, ipython_notebook=ipython_notebook):
|
with VerboseOptimization(self, opt, maxiters=max_iters, verbose=messages, ipython_notebook=ipython_notebook) as vo:
|
||||||
opt.run(f_fp=self._objective_grads, f=self._objective, fp=self._grads)
|
opt.run(f_fp=self._objective_grads, f=self._objective, fp=self._grads)
|
||||||
|
vo.finish(opt)
|
||||||
|
|
||||||
self.optimization_runs.append(opt)
|
self.optimization_runs.append(opt)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,10 @@ class Logexp(Transformation):
|
||||||
|
|
||||||
|
|
||||||
class NormalTheta(Transformation):
|
class NormalTheta(Transformation):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
_instances = []
|
_instances = []
|
||||||
def __new__(cls, mu_indices, var_indices):
|
def __new__(cls, mu_indices=None, var_indices=None):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
if cls._instances:
|
if cls._instances:
|
||||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||||
for instance in cls._instances:
|
for instance in cls._instances:
|
||||||
|
|
@ -143,9 +145,10 @@ class NormalTheta(Transformation):
|
||||||
self.var_indices = state[1]
|
self.var_indices = state[1]
|
||||||
|
|
||||||
class NormalNaturalAntti(NormalTheta):
|
class NormalNaturalAntti(NormalTheta):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
_instances = []
|
_instances = []
|
||||||
_logexp = Logexp()
|
def __new__(cls, mu_indices=None, var_indices=None):
|
||||||
def __new__(cls, mu_indices, var_indices):
|
"Do not use, not officially supported!"
|
||||||
if cls._instances:
|
if cls._instances:
|
||||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||||
for instance in cls._instances:
|
for instance in cls._instances:
|
||||||
|
|
@ -182,8 +185,10 @@ class NormalNaturalAntti(NormalTheta):
|
||||||
return "natantti"
|
return "natantti"
|
||||||
|
|
||||||
class NormalEta(Transformation):
|
class NormalEta(Transformation):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
_instances = []
|
_instances = []
|
||||||
def __new__(cls, mu_indices, var_indices):
|
def __new__(cls, mu_indices=None, var_indices=None):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
if cls._instances:
|
if cls._instances:
|
||||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||||
for instance in cls._instances:
|
for instance in cls._instances:
|
||||||
|
|
@ -223,8 +228,10 @@ class NormalEta(Transformation):
|
||||||
return "eta"
|
return "eta"
|
||||||
|
|
||||||
class NormalNaturalThroughTheta(NormalTheta):
|
class NormalNaturalThroughTheta(NormalTheta):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
_instances = []
|
_instances = []
|
||||||
def __new__(cls, mu_indices, var_indices):
|
def __new__(cls, mu_indices=None, var_indices=None):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
if cls._instances:
|
if cls._instances:
|
||||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||||
for instance in cls._instances:
|
for instance in cls._instances:
|
||||||
|
|
@ -272,8 +279,10 @@ class NormalNaturalThroughTheta(NormalTheta):
|
||||||
|
|
||||||
|
|
||||||
class NormalNaturalWhooot(NormalTheta):
|
class NormalNaturalWhooot(NormalTheta):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
_instances = []
|
_instances = []
|
||||||
def __new__(cls, mu_indices, var_indices):
|
def __new__(cls, mu_indices=None, var_indices=None):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
if cls._instances:
|
if cls._instances:
|
||||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||||
for instance in cls._instances:
|
for instance in cls._instances:
|
||||||
|
|
@ -307,8 +316,10 @@ class NormalNaturalWhooot(NormalTheta):
|
||||||
return "natgrad"
|
return "natgrad"
|
||||||
|
|
||||||
class NormalNaturalThroughEta(NormalEta):
|
class NormalNaturalThroughEta(NormalEta):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
_instances = []
|
_instances = []
|
||||||
def __new__(cls, mu_indices, var_indices):
|
def __new__(cls, mu_indices=None, var_indices=None):
|
||||||
|
"Do not use, not officially supported!"
|
||||||
if cls._instances:
|
if cls._instances:
|
||||||
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
cls._instances[:] = [instance for instance in cls._instances if instance()]
|
||||||
for instance in cls._instances:
|
for instance in cls._instances:
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class VerboseOptimization(object):
|
||||||
self.len_maxiters = len(str(maxiters))
|
self.len_maxiters = len(str(maxiters))
|
||||||
self.opt_name = opt.opt_name
|
self.opt_name = opt.opt_name
|
||||||
self.model.add_observer(self, self.print_status)
|
self.model.add_observer(self, self.print_status)
|
||||||
|
self.status = 'running'
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ class VerboseOptimization(object):
|
||||||
else:
|
else:
|
||||||
self.exps = exponents(self.fnow, self.current_gradient)
|
self.exps = exponents(self.fnow, self.current_gradient)
|
||||||
print 'Running {} Code:'.format(self.opt_name)
|
print 'Running {} Code:'.format(self.opt_name)
|
||||||
print ' {3:5s} {0:{mi}s} {1:11s} {2:11s}'.format("i", "f", "|g|", "secs", mi=self.len_maxiters)
|
print ' {3:7s} {0:{mi}s} {1:11s} {2:11s}'.format("i", "f", "|g|", "secs", mi=self.len_maxiters)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.start = time.time()
|
self.start = time.time()
|
||||||
|
|
@ -78,6 +79,7 @@ class VerboseOptimization(object):
|
||||||
['evaluation', "{:>0{l}}".format(self.iteration, l=self.len_maxiters)],
|
['evaluation', "{:>0{l}}".format(self.iteration, l=self.len_maxiters)],
|
||||||
['objective', "{: > 12.3E}".format(self.fnow)],
|
['objective', "{: > 12.3E}".format(self.fnow)],
|
||||||
['||gradient||', "{: >+12.3E}".format(float(self.current_gradient))],
|
['||gradient||', "{: >+12.3E}".format(float(self.current_gradient))],
|
||||||
|
['status', "{:s}".format(self.status)],
|
||||||
]
|
]
|
||||||
#message = "Lik:{:5.3E} Grad:{:5.3E} Lik:{:5.3E} Len:{!s}".format(float(m.log_likelihood()), np.einsum('i,i->', grads, grads), float(m.likelihood.variance), " ".join(["{:3.2E}".format(l) for l in m.kern.lengthscale.values]))
|
#message = "Lik:{:5.3E} Grad:{:5.3E} Lik:{:5.3E} Len:{!s}".format(float(m.log_likelihood()), np.einsum('i,i->', grads, grads), float(m.likelihood.variance), " ".join(["{:3.2E}".format(l) for l in m.kern.lengthscale.values]))
|
||||||
html_begin = """<style type="text/css">
|
html_begin = """<style type="text/css">
|
||||||
|
|
@ -109,7 +111,7 @@ class VerboseOptimization(object):
|
||||||
if b:
|
if b:
|
||||||
self.exps = n_exps
|
self.exps = n_exps
|
||||||
print '\r',
|
print '\r',
|
||||||
print '{3:> 6.2g} {0:>0{mi}g} {1:> 12e} {2:> 12e}'.format(self.iteration, float(self.fnow), float(self.current_gradient), time.time()-self.start, mi=self.len_maxiters), # print 'Iteration:', iteration, ' Objective:', fnow, ' Scale:', beta, '\r',
|
print '{3:> 7.2g} {0:>0{mi}g} {1:> 12e} {2:> 12e}'.format(self.iteration, float(self.fnow), float(self.current_gradient), time.time()-self.start, mi=self.len_maxiters), # print 'Iteration:', iteration, ' Objective:', fnow, ' Scale:', beta, '\r',
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def print_status(self, me, which=None):
|
def print_status(self, me, which=None):
|
||||||
|
|
@ -128,6 +130,9 @@ class VerboseOptimization(object):
|
||||||
else:
|
else:
|
||||||
self.current_gradient = np.nan
|
self.current_gradient = np.nan
|
||||||
|
|
||||||
|
def finish(self, opt):
|
||||||
|
self.status = opt.status
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.stop = time.time()
|
self.stop = time.time()
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
import latent_function_inference
|
import latent_function_inference
|
||||||
import optimization
|
import optimization
|
||||||
|
import mcmc
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# ## Copyright (c) 2014, Zhenwen Dai
|
# ## Copyright (c) 2014 Mu Niu, Zhenwen Dai and GPy Authors
|
||||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Optimizer():
|
||||||
self.x_opt = None
|
self.x_opt = None
|
||||||
self.funct_eval = None
|
self.funct_eval = None
|
||||||
self.status = None
|
self.status = None
|
||||||
self.max_f_eval = int(max_f_eval)
|
self.max_f_eval = int(max_iters)
|
||||||
self.max_iters = int(max_iters)
|
self.max_iters = int(max_iters)
|
||||||
self.bfgs_factor = bfgs_factor
|
self.bfgs_factor = bfgs_factor
|
||||||
self.trace = None
|
self.trace = None
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=np.inf, display=True,
|
||||||
function_eval = 1
|
function_eval = 1
|
||||||
fnow = fold
|
fnow = fold
|
||||||
gradnew = gradf(x, *optargs) # Initial gradient.
|
gradnew = gradf(x, *optargs) # Initial gradient.
|
||||||
|
function_eval += 1
|
||||||
#if any(np.isnan(gradnew)):
|
#if any(np.isnan(gradnew)):
|
||||||
# raise UnexpectedInfOrNan, "Gradient contribution resulted in a NaN value"
|
# raise UnexpectedInfOrNan, "Gradient contribution resulted in a NaN value"
|
||||||
current_grad = np.dot(gradnew, gradnew)
|
current_grad = np.dot(gradnew, gradnew)
|
||||||
|
|
@ -96,6 +97,7 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=np.inf, display=True,
|
||||||
sigma = sigma0 / np.sqrt(kappa)
|
sigma = sigma0 / np.sqrt(kappa)
|
||||||
xplus = x + sigma * d
|
xplus = x + sigma * d
|
||||||
gplus = gradf(xplus, *optargs)
|
gplus = gradf(xplus, *optargs)
|
||||||
|
function_eval += 1
|
||||||
theta = np.dot(d, (gplus - gradnew)) / sigma
|
theta = np.dot(d, (gplus - gradnew)) / sigma
|
||||||
|
|
||||||
# Increase effective curvature and evaluate step size alpha.
|
# Increase effective curvature and evaluate step size alpha.
|
||||||
|
|
@ -111,10 +113,10 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=np.inf, display=True,
|
||||||
fnew = f(xnew, *optargs)
|
fnew = f(xnew, *optargs)
|
||||||
function_eval += 1
|
function_eval += 1
|
||||||
|
|
||||||
# if function_eval >= max_f_eval:
|
if function_eval >= max_f_eval:
|
||||||
# status = "maximum number of function evaluations exceeded"
|
status = "maximum number of function evaluations exceeded"
|
||||||
# break
|
break
|
||||||
# return x, flog, function_eval, status
|
return x, flog, function_eval, status
|
||||||
|
|
||||||
Delta = 2.*(fnew - fold) / (alpha * mu)
|
Delta = 2.*(fnew - fold) / (alpha * mu)
|
||||||
if Delta >= 0.:
|
if Delta >= 0.:
|
||||||
|
|
@ -156,6 +158,7 @@ def SCG(f, gradf, x, optargs=(), maxiters=500, max_f_eval=np.inf, display=True,
|
||||||
# Update variables for new position
|
# Update variables for new position
|
||||||
gradold = gradnew
|
gradold = gradnew
|
||||||
gradnew = gradf(x, *optargs)
|
gradnew = gradf(x, *optargs)
|
||||||
|
function_eval += 1
|
||||||
current_grad = np.dot(gradnew, gradnew)
|
current_grad = np.dot(gradnew, gradnew)
|
||||||
fold = fnew
|
fold = fnew
|
||||||
# If the gradient is zero then we are done.
|
# If the gradient is zero then we are done.
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from _src.ODE_UYC import ODE_UYC
|
||||||
from _src.ODE_st import ODE_st
|
from _src.ODE_st import ODE_st
|
||||||
from _src.ODE_t import ODE_t
|
from _src.ODE_t import ODE_t
|
||||||
from _src.poly import Poly
|
from _src.poly import Poly
|
||||||
|
from _src.eq_ode2 import EQ_ODE2
|
||||||
|
|
||||||
from _src.trunclinear import TruncLinear,TruncLinear_inf
|
from _src.trunclinear import TruncLinear,TruncLinear_inf
|
||||||
from _src.splitKern import SplitKern,DiffGenomeKern
|
from _src.splitKern import SplitKern,DiffGenomeKern
|
||||||
|
|
|
||||||
1331
GPy/kern/_src/eq_ode2.py
Normal file
1331
GPy/kern/_src/eq_ode2.py
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -83,8 +83,8 @@ class BayesianGPLVMMiniBatch(SparseGPMiniBatch):
|
||||||
"""Get the gradients of the posterior distribution of X in its specific form."""
|
"""Get the gradients of the posterior distribution of X in its specific form."""
|
||||||
return X.mean.gradient, X.variance.gradient
|
return X.mean.gradient, X.variance.gradient
|
||||||
|
|
||||||
def _inner_parameters_changed(self, kern, X, Z, likelihood, Y, Y_metadata, Lm=None, dL_dKmm=None, subset_indices=None):
|
def _inner_parameters_changed(self, kern, X, Z, likelihood, Y, Y_metadata, Lm=None, dL_dKmm=None, subset_indices=None, **kw):
|
||||||
posterior, log_marginal_likelihood, grad_dict, current_values, value_indices = super(BayesianGPLVMMiniBatch, self)._inner_parameters_changed(kern, X, Z, likelihood, Y, Y_metadata, Lm=Lm, dL_dKmm=dL_dKmm, subset_indices=subset_indices)
|
posterior, log_marginal_likelihood, grad_dict, current_values, value_indices = super(BayesianGPLVMMiniBatch, self)._inner_parameters_changed(kern, X, Z, likelihood, Y, Y_metadata, Lm=Lm, dL_dKmm=dL_dKmm, subset_indices=subset_indices, **kw)
|
||||||
|
|
||||||
if self.has_uncertain_inputs():
|
if self.has_uncertain_inputs():
|
||||||
current_values['meangrad'], current_values['vargrad'] = self.kern.gradients_qX_expectations(
|
current_values['meangrad'], current_values['vargrad'] = self.kern.gradients_qX_expectations(
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ Created on 3 Nov 2014
|
||||||
def has_uncertain_inputs(self):
|
def has_uncertain_inputs(self):
|
||||||
return isinstance(self.X, VariationalPosterior)
|
return isinstance(self.X, VariationalPosterior)
|
||||||
|
|
||||||
def _inner_parameters_changed(self, kern, X, Z, likelihood, Y, Y_metadata, Lm=None, dL_dKmm=None, subset_indices=None):
|
def _inner_parameters_changed(self, kern, X, Z, likelihood, Y, Y_metadata, Lm=None, dL_dKmm=None, subset_indices=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
This is the standard part, which usually belongs in parameters_changed.
|
This is the standard part, which usually belongs in parameters_changed.
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ Created on 3 Nov 2014
|
||||||
algorithm.
|
algorithm.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
posterior, log_marginal_likelihood, grad_dict = self.inference_method.inference(kern, X, Z, likelihood, Y, Y_metadata, Lm=Lm, dL_dKmm=None)
|
posterior, log_marginal_likelihood, grad_dict = self.inference_method.inference(kern, X, Z, likelihood, Y, Y_metadata, Lm=Lm, dL_dKmm=None, **kwargs)
|
||||||
except:
|
except:
|
||||||
posterior, log_marginal_likelihood, grad_dict = self.inference_method.inference(kern, X, Z, likelihood, Y, Y_metadata)
|
posterior, log_marginal_likelihood, grad_dict = self.inference_method.inference(kern, X, Z, likelihood, Y, Y_metadata)
|
||||||
current_values = {}
|
current_values = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue