mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-08 03:22:38 +02:00
[optimize] added clear functionality for ipython notebook and kern input sensitivity error handling
This commit is contained in:
parent
c6cf0bc121
commit
77b4dc7d44
3 changed files with 31 additions and 24 deletions
|
|
@ -213,7 +213,7 @@ class Model(Parameterized):
|
||||||
self.obj_grads = np.clip(self._transform_gradients(self.objective_function_gradients()), -1e10, 1e10)
|
self.obj_grads = np.clip(self._transform_gradients(self.objective_function_gradients()), -1e10, 1e10)
|
||||||
return obj_f, self.obj_grads
|
return obj_f, self.obj_grads
|
||||||
|
|
||||||
def optimize(self, optimizer=None, start=None, messages=False, max_iters=1000, ipython_notebook=True, **kwargs):
|
def optimize(self, optimizer=None, start=None, messages=False, max_iters=1000, ipython_notebook=True, clear_after_finish=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
Optimize the model using self.log_likelihood and self.log_likelihood_gradient, as well as self.priors.
|
Optimize the model using self.log_likelihood and self.log_likelihood_gradient, as well as self.priors.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ def exponents(fnow, current_grad):
|
||||||
return np.sign(exps) * np.log10(exps).astype(int)
|
return np.sign(exps) * np.log10(exps).astype(int)
|
||||||
|
|
||||||
class VerboseOptimization(object):
|
class VerboseOptimization(object):
|
||||||
def __init__(self, model, opt, maxiters, verbose=False, current_iteration=0, ipython_notebook=True):
|
def __init__(self, model, opt, maxiters, verbose=False, current_iteration=0, ipython_notebook=True, clear_after_finish=False):
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
self.model = model
|
self.model = model
|
||||||
|
|
@ -22,6 +22,7 @@ class VerboseOptimization(object):
|
||||||
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.status = 'running'
|
||||||
|
self.clear = clear_after_finish
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
@ -37,30 +38,31 @@ class VerboseOptimization(object):
|
||||||
self.ipython_notebook = False
|
self.ipython_notebook = False
|
||||||
|
|
||||||
if self.ipython_notebook:
|
if self.ipython_notebook:
|
||||||
self.text.set_css('width', '100%')
|
|
||||||
#self.progress.set_css('width', '100%')
|
|
||||||
|
|
||||||
left_col = ContainerWidget(children = [self.progress, self.text])
|
left_col = ContainerWidget(children = [self.progress, self.text])
|
||||||
right_col = ContainerWidget(children = [self.model_show])
|
right_col = ContainerWidget(children = [self.model_show])
|
||||||
hor_align = ContainerWidget(children = [left_col, right_col])
|
self.hor_align = ContainerWidget(children = [left_col, right_col])
|
||||||
|
|
||||||
display(hor_align)
|
display(self.hor_align)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.text.set_css('width', '100%')
|
||||||
|
left_col.set_css({
|
||||||
|
'padding': '2px',
|
||||||
|
'width': "100%",
|
||||||
|
})
|
||||||
|
|
||||||
|
right_col.set_css({
|
||||||
|
'padding': '2px',
|
||||||
|
})
|
||||||
|
|
||||||
|
self.hor_align.set_css({
|
||||||
|
'width': "100%",
|
||||||
|
})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
left_col.set_css({
|
self.hor_align.remove_class('vbox')
|
||||||
'padding': '2px',
|
self.hor_align.add_class('hbox')
|
||||||
'width': "100%",
|
|
||||||
})
|
|
||||||
|
|
||||||
right_col.set_css({
|
|
||||||
'padding': '2px',
|
|
||||||
})
|
|
||||||
|
|
||||||
hor_align.set_css({
|
|
||||||
'width': "100%",
|
|
||||||
})
|
|
||||||
|
|
||||||
hor_align.remove_class('vbox')
|
|
||||||
hor_align.add_class('hbox')
|
|
||||||
|
|
||||||
left_col.add_class("box-flex1")
|
left_col.add_class("box-flex1")
|
||||||
right_col.add_class('box-flex0')
|
right_col.add_class('box-flex0')
|
||||||
|
|
@ -148,3 +150,5 @@ class VerboseOptimization(object):
|
||||||
print 'Optimization finished in {0:.5g} Seconds'.format(self.stop-self.start)
|
print 'Optimization finished in {0:.5g} Seconds'.format(self.stop-self.start)
|
||||||
print 'Optimization status: {0:.5g}'.format(self.status)
|
print 'Optimization status: {0:.5g}'.format(self.status)
|
||||||
print
|
print
|
||||||
|
elif self.clear:
|
||||||
|
self.hor_align.close()
|
||||||
|
|
|
||||||
|
|
@ -180,9 +180,12 @@ class Add(CombinationKernel):
|
||||||
|
|
||||||
def input_sensitivity(self, summarize=True):
|
def input_sensitivity(self, summarize=True):
|
||||||
if summarize:
|
if summarize:
|
||||||
return reduce(np.add, [k.input_sensitivity(summarize) for k in self.parts])
|
i_s = np.zeros((self.input_dim))
|
||||||
|
for k in self.parts:
|
||||||
|
i_s[k.active_dims] += k.input_sensitivity(summarize)
|
||||||
|
return i_s
|
||||||
else:
|
else:
|
||||||
i_s = np.zeros((len(self.parts), self.input_dim))
|
i_s = np.zeros((len(self.parts), self.input_dim))
|
||||||
from operator import setitem
|
from operator import setitem
|
||||||
[setitem(i_s, (i, Ellipsis), k.input_sensitivity(summarize)) for i, k in enumerate(self.parts)]
|
[setitem(i_s, (i, k.active_dims), k.input_sensitivity(summarize)) for i, k in enumerate(self.parts)]
|
||||||
return i_s
|
return i_s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue