mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-08 19:42:39 +02:00
[magnification] mostly plotting and some model corrections for _predictive_variable
This commit is contained in:
parent
26bdcfa82e
commit
ca60ad3195
7 changed files with 54 additions and 33 deletions
|
|
@ -405,9 +405,10 @@ class GP(Model):
|
||||||
|
|
||||||
for each point N in Xnew
|
for each point N in Xnew
|
||||||
"""
|
"""
|
||||||
from ..util.linalg import jitchol
|
|
||||||
G = self.predict_wishard_embedding(Xnew, kern)
|
G = self.predict_wishard_embedding(Xnew, kern)
|
||||||
return np.array([2*np.sqrt(np.exp(np.sum(np.log(np.diag(jitchol(G[n, :, :])))))) for n in range(Xnew.shape[0])])
|
from ..util.linalg import jitchol
|
||||||
|
return np.array([np.sqrt(np.exp(2*np.sum(np.log(np.diag(jitchol(G[n, :, :])))))) for n in range(Xnew.shape[0])])
|
||||||
|
#return np.array([np.sqrt(np.linalg.det(G[n, :, :])) for n in range(Xnew.shape[0])])
|
||||||
|
|
||||||
def posterior_samples_f(self,X,size=10, full_cov=True):
|
def posterior_samples_f(self,X,size=10, full_cov=True):
|
||||||
"""
|
"""
|
||||||
|
|
@ -564,6 +565,22 @@ class GP(Model):
|
||||||
plot_raw=plot_raw, Y_metadata=Y_metadata,
|
plot_raw=plot_raw, Y_metadata=Y_metadata,
|
||||||
data_symbol=data_symbol, predict_kw=predict_kw, **kw)
|
data_symbol=data_symbol, predict_kw=predict_kw, **kw)
|
||||||
|
|
||||||
|
def plot_magnification(self, labels=None, which_indices=None,
|
||||||
|
resolution=50, ax=None, marker='o', s=40,
|
||||||
|
fignum=None, legend=True,
|
||||||
|
plot_limits=None,
|
||||||
|
aspect='auto', updates=False, **kwargs):
|
||||||
|
|
||||||
|
import sys
|
||||||
|
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
||||||
|
from ..plotting.matplot_dep import dim_reduction_plots
|
||||||
|
|
||||||
|
return dim_reduction_plots.plot_magnification(self, labels, which_indices,
|
||||||
|
resolution, ax, marker, s,
|
||||||
|
fignum, False, legend,
|
||||||
|
plot_limits, aspect, updates, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def input_sensitivity(self, summarize=True):
|
def input_sensitivity(self, summarize=True):
|
||||||
"""
|
"""
|
||||||
Returns the sensitivity for each dimension of this model
|
Returns the sensitivity for each dimension of this model
|
||||||
|
|
|
||||||
|
|
@ -181,3 +181,18 @@ class SparseGP(GP):
|
||||||
var[i] = np.diag(var_)+p0-t2
|
var[i] = np.diag(var_)+p0-t2
|
||||||
|
|
||||||
return mu, var
|
return mu, var
|
||||||
|
|
||||||
|
def plot_magnification(self, labels=None, which_indices=None,
|
||||||
|
resolution=50, ax=None, marker='o', s=40,
|
||||||
|
fignum=None, legend=True,
|
||||||
|
plot_limits=None,
|
||||||
|
aspect='auto', updates=False, plot_inducing=True, **kwargs):
|
||||||
|
|
||||||
|
import sys
|
||||||
|
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
||||||
|
from ..plotting.matplot_dep import dim_reduction_plots
|
||||||
|
|
||||||
|
return dim_reduction_plots.plot_magnification(self, labels, which_indices,
|
||||||
|
resolution, ax, marker, s,
|
||||||
|
fignum, plot_inducing, legend,
|
||||||
|
plot_limits, aspect, updates, **kwargs)
|
||||||
|
|
@ -24,7 +24,6 @@ class VerboseOptimization(object):
|
||||||
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.clear = clear_after_finish
|
||||||
self.deltat = .2
|
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
@ -80,6 +79,7 @@ class VerboseOptimization(object):
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.start = time.time()
|
self.start = time.time()
|
||||||
|
self._time = self.start
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def print_out(self, seconds):
|
def print_out(self, seconds):
|
||||||
|
|
@ -143,12 +143,12 @@ class VerboseOptimization(object):
|
||||||
def print_status(self, me, which=None):
|
def print_status(self, me, which=None):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
seconds = time.time()-self.start
|
t = time.time()
|
||||||
|
seconds = t-self.start
|
||||||
#sys.stdout.write(" "*len(self.message))
|
#sys.stdout.write(" "*len(self.message))
|
||||||
self.deltat += seconds
|
if t-self._time > .3 or seconds < .3:
|
||||||
if self.deltat > .3 or seconds < .3:
|
|
||||||
self.print_out(seconds)
|
self.print_out(seconds)
|
||||||
self.deltat = 0
|
self._time = t
|
||||||
|
|
||||||
self.iteration += 1
|
self.iteration += 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ class Kern(Parameterized):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
def gradients_XX(self, dL_dK, X, X2):
|
def gradients_XX(self, dL_dK, X, X2):
|
||||||
raise(NotImplementedError, "This is the second derivative of K wrt X and X2, and not implemented for this kernel")
|
raise(NotImplementedError, "This is the second derivative of K wrt X and X2, and not implemented for this kernel")
|
||||||
|
def gradients_XX_diag(self, dL_dK, X, X2):
|
||||||
|
raise(NotImplementedError, "This is the diagonal of the second derivative of K wrt X and X2, and not implemented for this kernel")
|
||||||
def gradients_X_diag(self, dL_dKdiag, X):
|
def gradients_X_diag(self, dL_dKdiag, X):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,18 +81,3 @@ class GPLVM(GP):
|
||||||
resolution, ax, marker, s,
|
resolution, ax, marker, s,
|
||||||
fignum, False, legend,
|
fignum, False, legend,
|
||||||
plot_limits, aspect, updates, **kwargs)
|
plot_limits, aspect, updates, **kwargs)
|
||||||
|
|
||||||
def plot_magnification(self, labels=None, which_indices=None,
|
|
||||||
resolution=50, ax=None, marker='o', s=40,
|
|
||||||
fignum=None, legend=True,
|
|
||||||
plot_limits=None,
|
|
||||||
aspect='auto', updates=False, **kwargs):
|
|
||||||
|
|
||||||
import sys
|
|
||||||
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
|
|
||||||
from ..plotting.matplot_dep import dim_reduction_plots
|
|
||||||
|
|
||||||
return dim_reduction_plots.plot_magnification(self, labels, which_indices,
|
|
||||||
resolution, ax, marker, s,
|
|
||||||
fignum, False, legend,
|
|
||||||
plot_limits, aspect, updates, **kwargs)
|
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ class SparseGPMiniBatch(SparseGP):
|
||||||
logger.info("Adding Z as parameter")
|
logger.info("Adding Z as parameter")
|
||||||
self.link_parameter(self.Z, index=0)
|
self.link_parameter(self.Z, index=0)
|
||||||
self.posterior = None
|
self.posterior = None
|
||||||
|
self._predictive_variable = self.Z
|
||||||
|
|
||||||
def has_uncertain_inputs(self):
|
def has_uncertain_inputs(self):
|
||||||
return isinstance(self.X, VariationalPosterior)
|
return isinstance(self.X, VariationalPosterior)
|
||||||
|
|
|
||||||
|
|
@ -322,11 +322,11 @@ def plot_magnification(model, labels=None, which_indices=None,
|
||||||
|
|
||||||
index = np.nonzero(labels == ul)[0]
|
index = np.nonzero(labels == ul)[0]
|
||||||
if model.input_dim == 1:
|
if model.input_dim == 1:
|
||||||
x = model.X[index, input_1]
|
x = X[index, input_1]
|
||||||
y = np.zeros(index.size)
|
y = np.zeros(index.size)
|
||||||
else:
|
else:
|
||||||
x = model.X[index, input_1]
|
x = X[index, input_1]
|
||||||
y = model.X[index, input_2]
|
y = X[index, input_2]
|
||||||
ax.scatter(x, y, marker=m, s=s, color=Tango.nextMedium(), label=this_label)
|
ax.scatter(x, y, marker=m, s=s, color=Tango.nextMedium(), label=this_label)
|
||||||
|
|
||||||
ax.set_xlabel('latent dimension %i' % input_1)
|
ax.set_xlabel('latent dimension %i' % input_1)
|
||||||
|
|
@ -335,13 +335,14 @@ def plot_magnification(model, labels=None, which_indices=None,
|
||||||
if not np.all(labels == 1.) and legend:
|
if not np.all(labels == 1.) and legend:
|
||||||
ax.legend(loc=0, numpoints=1)
|
ax.legend(loc=0, numpoints=1)
|
||||||
|
|
||||||
ax.set_xlim(xmin[0], xmax[0])
|
ax.set_xlim((xmin, xmax))
|
||||||
ax.set_ylim(xmin[1], xmax[1])
|
ax.set_ylim((ymin, ymax))
|
||||||
ax.grid(b=False) # remove the grid if present, it doesn't look good
|
ax.grid(b=False) # remove the grid if present, it doesn't look good
|
||||||
ax.set_aspect('auto') # set a nice aspect ratio
|
ax.set_aspect('auto') # set a nice aspect ratio
|
||||||
|
|
||||||
if plot_inducing:
|
if plot_inducing:
|
||||||
ax.plot(model.Z[:, input_1], model.Z[:, input_2], '^w')
|
Z = model.Z
|
||||||
|
ax.scatter(Z[:, input_1], Z[:, input_2], c='w', s=18, marker="^", edgecolor='k', linewidth=.3, alpha=.7)
|
||||||
|
|
||||||
if updates:
|
if updates:
|
||||||
fig.canvas.show()
|
fig.canvas.show()
|
||||||
|
|
@ -386,8 +387,8 @@ def plot_steepest_gradient_map(model, fignum=None, ax=None, which_indices=None,
|
||||||
this_label = 'class %i' % i
|
this_label = 'class %i' % i
|
||||||
m = marker.next()
|
m = marker.next()
|
||||||
index = np.nonzero(data_labels == ul)[0]
|
index = np.nonzero(data_labels == ul)[0]
|
||||||
x = model.X[index, input_1]
|
x = X[index, input_1]
|
||||||
y = model.X[index, input_2]
|
y = X[index, input_2]
|
||||||
ax.scatter(x, y, marker=m, s=data_s, color=Tango.nextMedium(), label=this_label)
|
ax.scatter(x, y, marker=m, s=data_s, color=Tango.nextMedium(), label=this_label)
|
||||||
|
|
||||||
ax.set_xlabel('latent dimension %i' % input_1)
|
ax.set_xlabel('latent dimension %i' % input_1)
|
||||||
|
|
@ -395,7 +396,7 @@ def plot_steepest_gradient_map(model, fignum=None, ax=None, which_indices=None,
|
||||||
|
|
||||||
controller = ImAnnotateController(ax,
|
controller = ImAnnotateController(ax,
|
||||||
plot_function,
|
plot_function,
|
||||||
tuple(model.X.min(0)[:, significant_dims]) + tuple(model.X.max(0)[:, significant_dims]),
|
tuple(X.min(0)[:, significant_dims]) + tuple(X.max(0)[:, significant_dims]),
|
||||||
resolution=resolution,
|
resolution=resolution,
|
||||||
aspect=aspect,
|
aspect=aspect,
|
||||||
cmap=get_cmap('jet'),
|
cmap=get_cmap('jet'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue