mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-04 01:02:39 +02:00
[testing] BGPLVM
This commit is contained in:
parent
298893d65f
commit
116ad8762c
6 changed files with 62 additions and 32 deletions
|
|
@ -170,6 +170,9 @@ def plot_inducing(self, visible_dims=None, projection='2d', label=None, **plot_k
|
|||
return pl.show_canvas(canvas, plots)
|
||||
|
||||
def _plot_inducing(self, canvas, visible_dims, projection, label, **plot_kwargs):
|
||||
if visible_dims is None:
|
||||
sig_dims = self.get_most_significant_input_dimensions()
|
||||
visible_dims = [i for i in sig_dims if i is not None]
|
||||
free_dims = get_free_dims(self, visible_dims, None)
|
||||
|
||||
Z = self.Z[:, free_dims]
|
||||
|
|
|
|||
|
|
@ -116,16 +116,16 @@ def _plot_prediction_fit(self, canvas, plot_limits=None,
|
|||
raise NotImplementedError("Cannot plot in more then one dimension.")
|
||||
return plots
|
||||
|
||||
def _plot_latent_scatter(self, canvas, X, input_1, input_2, labels, marker, num_samples, **kwargs):
|
||||
def _plot_latent_scatter(self, canvas, X, visible_dims, labels, marker, num_samples, projection='2d', **kwargs):
|
||||
from .. import Tango
|
||||
Tango.reset()
|
||||
if labels is None:
|
||||
labels = np.ones(self.num_data)
|
||||
X, labels = subsample_X(X, labels, num_samples)
|
||||
scatters = []
|
||||
for x, y, this_label, _, m in scatter_label_generator(labels, X, input_1, input_2, marker):
|
||||
for x, y, z, this_label, _, m in scatter_label_generator(labels, X, visible_dims, marker):
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.latent_scatter)
|
||||
scatters.append(pl.scatter(canvas, x, y, marker=m, color=Tango.nextMedium(), label=this_label, **kwargs))
|
||||
scatters.append(pl.scatter(canvas, x, y, Z=z, marker=m, color=Tango.nextMedium(), label=this_label, **kwargs))
|
||||
return scatters
|
||||
|
||||
def plot_latent_scatter(self, labels=None,
|
||||
|
|
@ -134,6 +134,7 @@ def plot_latent_scatter(self, labels=None,
|
|||
plot_limits=None,
|
||||
marker='<>^vsd',
|
||||
num_samples=1000,
|
||||
projection='2d',
|
||||
**kwargs):
|
||||
"""
|
||||
Plot a scatter plot of the latent space.
|
||||
|
|
@ -146,13 +147,23 @@ def plot_latent_scatter(self, labels=None,
|
|||
:param str marker: markers to use - cycle if more labels then markers are given
|
||||
:param kwargs: the kwargs for the scatter plots
|
||||
"""
|
||||
input_1, input_2 = self.get_most_significant_input_dimensions(which_indices)
|
||||
canvas, kwargs = pl.get_new_canvas(xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **kwargs)
|
||||
sig_dims = self.get_most_significant_input_dimensions(which_indices)
|
||||
input_1, input_2, input_3 = [i for i in sig_dims if i is not None]
|
||||
|
||||
canvas, kwargs = pl.get_new_canvas(projection=projection, **kwargs)
|
||||
X, _, _ = get_x_y_var(self)
|
||||
scatters = _plot_latent_scatter(self, canvas, X, input_1, input_2, labels, marker, num_samples, **kwargs)
|
||||
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend and (labels is not None))
|
||||
|
||||
|
||||
scatters = _plot_latent_scatter(self, canvas, X, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
|
||||
if projection == '3d':
|
||||
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend and (labels is not None),
|
||||
xlabel='latent dimension %i' % input_1,
|
||||
ylabel='latent dimension %i' % input_2,
|
||||
zlabel='latent dimension %i' % input_3)
|
||||
else:
|
||||
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend and (labels is not None),
|
||||
xlabel='latent dimension %i' % input_1,
|
||||
ylabel='latent dimension %i' % input_2,
|
||||
#zlabel='latent dimension %i' % input_3
|
||||
)
|
||||
|
||||
|
||||
def _plot_magnification(self, canvas, input_1, input_2, Xgrid,
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ def helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resoluti
|
|||
Xgrid[:,i] = v
|
||||
return X, Xvar, Y, fixed_dims, free_dims, Xgrid, x, y, xmin, xmax, resolution
|
||||
|
||||
def scatter_label_generator(labels, X, input_1, input_2=None, marker=None):
|
||||
def scatter_label_generator(labels, X, visible_dims, marker=None):
|
||||
ulabels = []
|
||||
for lab in labels:
|
||||
if not lab in ulabels:
|
||||
|
|
@ -140,6 +140,8 @@ def scatter_label_generator(labels, X, input_1, input_2=None, marker=None):
|
|||
else:
|
||||
m = None
|
||||
|
||||
input_1, input_2, input_3 = visible_dims
|
||||
|
||||
for ul in ulabels:
|
||||
if type(ul) is np.string_:
|
||||
this_label = ul
|
||||
|
|
@ -160,10 +162,16 @@ def scatter_label_generator(labels, X, input_1, input_2=None, marker=None):
|
|||
if input_2 is None:
|
||||
x = X[index, input_1]
|
||||
y = np.zeros(index.size)
|
||||
else:
|
||||
z = None
|
||||
elif input_3 is None:
|
||||
x = X[index, input_1]
|
||||
y = X[index, input_2]
|
||||
yield x, y, this_label, index, m
|
||||
z = None
|
||||
else:
|
||||
x = X[index, input_1]
|
||||
y = X[index, input_2]
|
||||
z = X[index, input_3]
|
||||
yield x, y, z, this_label, index, m
|
||||
|
||||
def subsample_X(X, labels, num_samples=1000):
|
||||
"""
|
||||
|
|
@ -175,7 +183,7 @@ def subsample_X(X, labels, num_samples=1000):
|
|||
print("Warning: subsampling X, as it has more samples then 1000. X.shape={!s}".format(X.shape))
|
||||
if labels is not None:
|
||||
subsample = []
|
||||
for _, _, _, index, _ in scatter_label_generator(labels, X, 0):
|
||||
for _, _, _, _, index, _ in scatter_label_generator(labels, X, (0, None, None)):
|
||||
subsample.append(np.random.choice(index, size=max(2, int(index.size*(float(num_samples)/X.shape[0]))), replace=False))
|
||||
subsample = np.hstack(subsample)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue