mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-27 05:46:24 +02:00
[kernel] plot_ard added (some other fixes as well)
This commit is contained in:
parent
e3617942d4
commit
d2d8a62d2d
14 changed files with 371 additions and 337 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# This is the local installation configuration file for GPy
|
||||
|
||||
[plotting]
|
||||
library = plotly
|
||||
#library = matplotlib
|
||||
#library = plotly
|
||||
library = matplotlib
|
||||
|
|
|
|||
|
|
@ -1,28 +1,47 @@
|
|||
# Copyright (c) 2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
try:
|
||||
#===========================================================================
|
||||
# Load in your plotting library here and
|
||||
# save it under the name plotting_library!
|
||||
# This is hooking the library in
|
||||
# for the usage in GPy:
|
||||
from ..util.config import config
|
||||
lib = config.get('plotting', 'library')
|
||||
if lib == 'matplotlib':
|
||||
import matplotlib
|
||||
from .matplot_dep import plot_definitions
|
||||
plotting_library = plot_definitions.MatplotlibPlots()
|
||||
if lib == 'plotly':
|
||||
import plotly
|
||||
from .plotly_dep import plot_definitions
|
||||
plotting_library = plot_definitions.PlotlyPlots()
|
||||
#===========================================================================
|
||||
except (ImportError, NameError):
|
||||
raise
|
||||
import warnings
|
||||
warnings.warn(ImportWarning("{} not available, install newest version of {} for plotting".format(lib, lib)))
|
||||
config.set('plotting', 'library', 'none')
|
||||
current_lib = [None]
|
||||
|
||||
def change_plotting_library(lib):
|
||||
try:
|
||||
#===========================================================================
|
||||
# Load in your plotting library here and
|
||||
# save it under the name plotting_library!
|
||||
# This is hooking the library in
|
||||
# for the usage in GPy:
|
||||
if lib == 'matplotlib':
|
||||
import matplotlib
|
||||
from .matplot_dep.plot_definitions import MatplotlibPlots
|
||||
current_lib[0] = MatplotlibPlots()
|
||||
if lib == 'plotly':
|
||||
import plotly
|
||||
from .plotly_dep.plot_definitions import PlotlyPlots
|
||||
current_lib[0] = PlotlyPlots()
|
||||
if lib == 'none':
|
||||
current_lib[0] = None
|
||||
#===========================================================================
|
||||
except (ImportError, NameError):
|
||||
import warnings
|
||||
warnings.warn(ImportWarning("{} not available, install newest version of {} for plotting".format(lib, lib)))
|
||||
config.set('plotting', 'library', 'none')
|
||||
|
||||
from ..util.config import config
|
||||
lib = config.get('plotting', 'library')
|
||||
change_plotting_library(lib)
|
||||
|
||||
def plotting_library():
|
||||
return current_lib[0]
|
||||
|
||||
def show(figure, **kwargs):
|
||||
"""
|
||||
Show the specific plotting library figure, returned by
|
||||
add_to_canvas().
|
||||
|
||||
kwargs are the plotting library specific options
|
||||
for showing/drawing a figure.
|
||||
"""
|
||||
return plotting_library().show_canvas(figure, **kwargs)
|
||||
|
||||
if config.get('plotting', 'library') is not 'none':
|
||||
# Inject the plots into classes here:
|
||||
|
|
@ -64,7 +83,7 @@ if config.get('plotting', 'library') is not 'none':
|
|||
|
||||
from ..kern import Kern
|
||||
Kern.plot_covariance = gpy_plot.kernel_plots.plot_covariance
|
||||
Kern.plot_covariance = gpy_plot.kernel_plots.plot_ARD
|
||||
Kern.plot_ARD = gpy_plot.kernel_plots.plot_ARD
|
||||
|
||||
from ..inference.optimization import Optimizer
|
||||
Optimizer.plot = gpy_plot.inference_plots.plot_optimizer
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
from .. import plotting_library
|
||||
pl = plotting_library
|
||||
from . import data_plots, gp_plots, latent_plots, kernel_plots, plot_util, inference_plots
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#===============================================================================
|
||||
import numpy as np
|
||||
from . import pl
|
||||
from . import plotting_library as pl
|
||||
#from .. import gpy_plot
|
||||
from .plot_util import get_x_y_var, get_free_dims, get_which_data_ycols,\
|
||||
get_which_data_rows, update_not_existing_kwargs, helper_predict_with_model
|
||||
|
||||
|
|
@ -54,9 +55,9 @@ def plot_data(self, which_data_rows='all',
|
|||
|
||||
:returns list: of plots created.
|
||||
"""
|
||||
canvas, plot_kwargs = pl.new_canvas(projection=projection, **plot_kwargs)
|
||||
canvas, plot_kwargs = pl().new_canvas(projection=projection, **plot_kwargs)
|
||||
plots = _plot_data(self, canvas, which_data_rows, which_data_ycols, visible_dims, projection, label, **plot_kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_data(self, canvas, which_data_rows='all',
|
||||
which_data_ycols='all', visible_dims=None,
|
||||
|
|
@ -73,19 +74,19 @@ def _plot_data(self, canvas, which_data_rows='all',
|
|||
#one dimensional plotting
|
||||
if len(free_dims) == 1:
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_1d) # @UndefinedVariable
|
||||
plots['dataplot'].append(pl.scatter(canvas, X[rows, free_dims], Y[rows, d], label=label, **plot_kwargs))
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.data_1d) # @UndefinedVariable
|
||||
plots['dataplot'].append(pl().scatter(canvas, X[rows, free_dims], Y[rows, d], label=label, **plot_kwargs))
|
||||
#2D plotting
|
||||
elif len(free_dims) == 2:
|
||||
if projection=='2d':
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_2d) # @UndefinedVariable
|
||||
plots['dataplot'].append(pl.scatter(canvas, X[rows, free_dims[0]], X[rows, free_dims[1]],
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.data_2d) # @UndefinedVariable
|
||||
plots['dataplot'].append(pl().scatter(canvas, X[rows, free_dims[0]], X[rows, free_dims[1]],
|
||||
color=Y[rows, d], label=label, **plot_kwargs))
|
||||
else:
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_2d) # @UndefinedVariable
|
||||
plots['dataplot'].append(pl.scatter(canvas, X[rows, free_dims[0]], X[rows, free_dims[1]],
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.data_2d) # @UndefinedVariable
|
||||
plots['dataplot'].append(pl().scatter(canvas, X[rows, free_dims[0]], X[rows, free_dims[1]],
|
||||
Z=Y[rows, d], color=Y[rows, d], label=label, **plot_kwargs))
|
||||
elif len(free_dims) == 0:
|
||||
pass #Nothing to plot!
|
||||
|
|
@ -117,9 +118,9 @@ def plot_data_error(self, which_data_rows='all',
|
|||
|
||||
:returns list: of plots created.
|
||||
"""
|
||||
canvas, error_kwargs = pl.new_canvas(projection=projection, **error_kwargs)
|
||||
canvas, error_kwargs = pl().new_canvas(projection=projection, **error_kwargs)
|
||||
plots = _plot_data_error(self, canvas, which_data_rows, which_data_ycols, visible_dims, projection, label, **error_kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_data_error(self, canvas, which_data_rows='all',
|
||||
which_data_ycols='all', visible_dims=None,
|
||||
|
|
@ -137,18 +138,18 @@ def _plot_data_error(self, canvas, which_data_rows='all',
|
|||
#one dimensional plotting
|
||||
if len(free_dims) == 1:
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(error_kwargs, pl.defaults.xerrorbar)
|
||||
plots['xerrorplot'].append(pl.xerrorbar(canvas, X[rows, free_dims].flatten(), Y[rows, d].flatten(),
|
||||
update_not_existing_kwargs(error_kwargs, pl().defaults.xerrorbar)
|
||||
plots['xerrorplot'].append(pl().xerrorbar(canvas, X[rows, free_dims].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
#2D plotting
|
||||
elif len(free_dims) == 2:
|
||||
update_not_existing_kwargs(error_kwargs, pl.defaults.xerrorbar) # @UndefinedVariable
|
||||
update_not_existing_kwargs(error_kwargs, pl().defaults.xerrorbar) # @UndefinedVariable
|
||||
for d in ycols:
|
||||
plots['xerrorplot'].append(pl.xerrorbar(canvas, X[rows, free_dims[0]].flatten(), Y[rows, d].flatten(),
|
||||
plots['xerrorplot'].append(pl().xerrorbar(canvas, X[rows, free_dims[0]].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims[0]].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
plots['yerrorplot'].append(pl.xerrorbar(canvas, X[rows, free_dims[1]].flatten(), Y[rows, d].flatten(),
|
||||
plots['yerrorplot'].append(pl().xerrorbar(canvas, X[rows, free_dims[1]].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims[1]].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
elif len(free_dims) == 0:
|
||||
|
|
@ -165,9 +166,9 @@ def plot_inducing(self, visible_dims=None, projection='2d', label=None, **plot_k
|
|||
:param array-like visible_dims: an array specifying the input dimensions to plot (maximum two)
|
||||
:param kwargs plot_kwargs: keyword arguments for the plotting library
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(projection=projection, **plot_kwargs)
|
||||
canvas, kwargs = pl().new_canvas(projection=projection, **plot_kwargs)
|
||||
plots = _plot_inducing(self, canvas, visible_dims, projection, label, **kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_inducing(self, canvas, visible_dims, projection, label, **plot_kwargs):
|
||||
if visible_dims is None:
|
||||
|
|
@ -180,15 +181,15 @@ def _plot_inducing(self, canvas, visible_dims, projection, label, **plot_kwargs)
|
|||
|
||||
#one dimensional plotting
|
||||
if len(free_dims) == 1:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.inducing_1d) # @UndefinedVariable
|
||||
plots['inducing'] = pl.plot_axis_lines(canvas, Z[:, free_dims], **plot_kwargs)
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.inducing_1d) # @UndefinedVariable
|
||||
plots['inducing'] = pl().plot_axis_lines(canvas, Z[:, free_dims], **plot_kwargs)
|
||||
#2D plotting
|
||||
elif len(free_dims) == 2 and projection == '3d':
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.inducing_3d) # @UndefinedVariable
|
||||
plots['inducing'] = pl.plot_axis_lines(canvas, Z[:, free_dims], **plot_kwargs)
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.inducing_3d) # @UndefinedVariable
|
||||
plots['inducing'] = pl().plot_axis_lines(canvas, Z[:, free_dims], **plot_kwargs)
|
||||
elif len(free_dims) == 2:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.inducing_2d) # @UndefinedVariable
|
||||
plots['inducing'] = pl.scatter(canvas, Z[:, free_dims[0]], Z[:, free_dims[1]],
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.inducing_2d) # @UndefinedVariable
|
||||
plots['inducing'] = pl().scatter(canvas, Z[:, free_dims[0]], Z[:, free_dims[1]],
|
||||
**plot_kwargs)
|
||||
elif len(free_dims) == 0:
|
||||
pass #Nothing to plot!
|
||||
|
|
@ -217,10 +218,10 @@ def plot_errorbars_trainset(self, which_data_rows='all',
|
|||
:param dict predict_kwargs: kwargs for the prediction used to predict the right quantiles.
|
||||
:param kwargs plot_kwargs: kwargs for the data plot for the plotting library you are using
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(projection=projection, **plot_kwargs)
|
||||
canvas, kwargs = pl().new_canvas(projection=projection, **plot_kwargs)
|
||||
plots = _plot_errorbars_trainset(self, canvas, which_data_rows, which_data_ycols,
|
||||
fixed_inputs, plot_raw, apply_link, label, projection, predict_kw, **kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_errorbars_trainset(self, canvas,
|
||||
which_data_rows='all', which_data_ycols='all',
|
||||
|
|
@ -244,7 +245,7 @@ def _plot_errorbars_trainset(self, canvas,
|
|||
plots = []
|
||||
|
||||
if len(free_dims)<=2:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.yerrorbar)
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.yerrorbar)
|
||||
if predict_kw is None:
|
||||
predict_kw = {}
|
||||
if 'Y_metadata' not in predict_kw:
|
||||
|
|
@ -254,18 +255,18 @@ def _plot_errorbars_trainset(self, canvas,
|
|||
ycols, predict_kw)
|
||||
if len(free_dims)==1:
|
||||
for d in ycols:
|
||||
plots.append(pl.yerrorbar(canvas, X[rows,free_dims[0]], mu[rows,d],
|
||||
plots.append(pl().yerrorbar(canvas, X[rows,free_dims[0]], mu[rows,d],
|
||||
np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
label=label,
|
||||
**plot_kwargs))
|
||||
elif len(free_dims) == 2:
|
||||
for d in ycols:
|
||||
plots.append(pl.yerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
plots.append(pl().yerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
color=Y[rows,d],
|
||||
label=label,
|
||||
**plot_kwargs))
|
||||
plots.append(pl.xerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
plots.append(pl().xerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
color=Y[rows,d],
|
||||
label=label,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
import numpy as np
|
||||
|
||||
from . import pl
|
||||
from . import plotting_library as pl
|
||||
from .plot_util import helper_for_plot_data, update_not_existing_kwargs, \
|
||||
helper_predict_with_model, get_which_data_ycols
|
||||
from .data_plots import _plot_data, _plot_inducing, _plot_data_error
|
||||
|
|
@ -62,7 +62,7 @@ def plot_mean(self, plot_limits=None, fixed_inputs=None,
|
|||
:param str label: the label for the plot.
|
||||
:param dict predict_kw: the keyword arguments for the prediction. If you want to plot a specific kernel give dict(kern=<specific kernel>) in here
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(projection=projection, **kwargs)
|
||||
canvas, kwargs = pl().new_canvas(projection=projection, **kwargs)
|
||||
helper_data = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
|
||||
helper_prediction = helper_predict_with_model(self, helper_data[5], plot_raw,
|
||||
apply_link, None,
|
||||
|
|
@ -70,7 +70,7 @@ def plot_mean(self, plot_limits=None, fixed_inputs=None,
|
|||
predict_kw)
|
||||
plots = _plot_mean(self, canvas, helper_data, helper_prediction,
|
||||
levels, projection, label, **kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_mean(self, canvas, helper_data, helper_prediction,
|
||||
levels=20, projection='2d', label=None,
|
||||
|
|
@ -81,17 +81,17 @@ def _plot_mean(self, canvas, helper_data, helper_prediction,
|
|||
mu, _, _ = helper_prediction
|
||||
if len(free_dims)==1:
|
||||
# 1D plotting:
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_1d) # @UndefinedVariable
|
||||
plots = dict(gpmean=[pl.plot(canvas, Xgrid[:, free_dims], mu, label=label, **kwargs)])
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_1d) # @UndefinedVariable
|
||||
plots = dict(gpmean=[pl().plot(canvas, Xgrid[:, free_dims], mu, label=label, **kwargs)])
|
||||
else:
|
||||
if projection == '2d':
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_2d) # @UndefinedVariable
|
||||
plots = dict(gpmean=[pl.contour(canvas, x[:,0], y[0,:],
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_2d) # @UndefinedVariable
|
||||
plots = dict(gpmean=[pl().contour(canvas, x[:,0], y[0,:],
|
||||
mu.reshape(resolution, resolution),
|
||||
levels=levels, label=label, **kwargs)])
|
||||
elif projection == '3d':
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_3d) # @UndefinedVariable
|
||||
plots = dict(gpmean=[pl.surface(canvas, x, y,
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_3d) # @UndefinedVariable
|
||||
plots = dict(gpmean=[pl().surface(canvas, x, y,
|
||||
mu.reshape(resolution, resolution),
|
||||
label=label,
|
||||
**kwargs)])
|
||||
|
|
@ -127,24 +127,24 @@ def plot_confidence(self, lower=2.5, upper=97.5, plot_limits=None, fixed_inputs=
|
|||
:param array-like which_data_ycols: which columns of the output y (!) to plot (array-like or list of ints)
|
||||
:param dict predict_kw: the keyword arguments for the prediction. If you want to plot a specific kernel give dict(kern=<specific kernel>) in here
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(**kwargs)
|
||||
canvas, kwargs = pl().new_canvas(**kwargs)
|
||||
ycols = get_which_data_ycols(self, which_data_ycols)
|
||||
helper_data = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
|
||||
helper_prediction = helper_predict_with_model(self, helper_data[5], plot_raw, apply_link,
|
||||
(lower, upper),
|
||||
ycols, predict_kw)
|
||||
plots = _plot_confidence(self, canvas, helper_data, helper_prediction, label, **kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_confidence(self, canvas, helper_data, helper_prediction, label, **kwargs):
|
||||
_, _, _, _, free_dims, Xgrid, _, _, _, _, _ = helper_data
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.confidence_interval) # @UndefinedVariable
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.confidence_interval) # @UndefinedVariable
|
||||
if len(free_dims)<=1:
|
||||
if len(free_dims)==1:
|
||||
percs = helper_prediction[1]
|
||||
fills = []
|
||||
for d in range(helper_prediction[0].shape[1]):
|
||||
fills.append(pl.fill_between(canvas, Xgrid[:,free_dims[0]], percs[0][:,d], percs[1][:,d], label=label, **kwargs))
|
||||
fills.append(pl().fill_between(canvas, Xgrid[:,free_dims[0]], percs[0][:,d], percs[1][:,d], label=label, **kwargs))
|
||||
return dict(gpconfidence=fills)
|
||||
else:
|
||||
pass #Nothing to plot!
|
||||
|
|
@ -177,7 +177,7 @@ def plot_samples(self, plot_limits=None, fixed_inputs=None,
|
|||
:param dict predict_kw: the keyword arguments for the prediction. If you want to plot a specific kernel give dict(kern=<specific kernel>) in here
|
||||
:param int levels: for 2D plotting, the number of contour levels to use is
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(projection=projection, **kwargs)
|
||||
canvas, kwargs = pl().new_canvas(projection=projection, **kwargs)
|
||||
ycols = get_which_data_ycols(self, which_data_ycols)
|
||||
helper_data = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
|
||||
helper_prediction = helper_predict_with_model(self, helper_data[5], plot_raw, apply_link,
|
||||
|
|
@ -185,7 +185,7 @@ def plot_samples(self, plot_limits=None, fixed_inputs=None,
|
|||
ycols, predict_kw, samples)
|
||||
plots = _plot_samples(self, canvas, helper_data, helper_prediction,
|
||||
projection, label, **kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_samples(self, canvas, helper_data, helper_prediction, projection,
|
||||
label, **kwargs):
|
||||
|
|
@ -195,12 +195,12 @@ def _plot_samples(self, canvas, helper_data, helper_prediction, projection,
|
|||
if len(free_dims)<=2:
|
||||
if len(free_dims)==1:
|
||||
# 1D plotting:
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.samples_1d) # @UndefinedVariable
|
||||
return dict(gpmean=[pl.plot(canvas, Xgrid[:, free_dims], samples, label=label, **kwargs)])
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.samples_1d) # @UndefinedVariable
|
||||
return dict(gpmean=[pl().plot(canvas, Xgrid[:, free_dims], samples, label=label, **kwargs)])
|
||||
elif len(free_dims)==2 and projection=='3d':
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.samples_3d) # @UndefinedVariable
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.samples_3d) # @UndefinedVariable
|
||||
for s in range(samples.shape[-1]):
|
||||
return dict(gpmean=[pl.surface(canvas, x,
|
||||
return dict(gpmean=[pl().surface(canvas, x,
|
||||
y, samples[:, s].reshape(resolution, resolution),
|
||||
**kwargs)])
|
||||
else:
|
||||
|
|
@ -235,27 +235,27 @@ def plot_density(self, plot_limits=None, fixed_inputs=None,
|
|||
:param int levels: the number of levels in the density (number bigger then 1, where 35 is smooth and 1 is the same as plot_confidence). You can go higher then 50 if the result is not smooth enough for you.
|
||||
:param dict predict_kw: the keyword arguments for the prediction. If you want to plot a specific kernel give dict(kern=<specific kernel>) in here
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(**kwargs)
|
||||
canvas, kwargs = pl().new_canvas(**kwargs)
|
||||
helper_data = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
|
||||
helper_prediction = helper_predict_with_model(self, helper_data[5], plot_raw,
|
||||
apply_link, np.linspace(2.5, 97.5, levels*2),
|
||||
get_which_data_ycols(self, which_data_ycols),
|
||||
predict_kw)
|
||||
plots = _plot_density(self, canvas, helper_data, helper_prediction, label, **kwargs)
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
def _plot_density(self, canvas, helper_data, helper_prediction, label, **kwargs):
|
||||
_, _, _, _, free_dims, Xgrid, _, _, _, _, _ = helper_data
|
||||
mu, percs, _ = helper_prediction
|
||||
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.density) # @UndefinedVariable
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.density) # @UndefinedVariable
|
||||
|
||||
if len(free_dims)<=1:
|
||||
if len(free_dims)==1:
|
||||
# 1D plotting:
|
||||
fills = []
|
||||
for d in range(mu.shape[1]):
|
||||
fills.append(pl.fill_gradient(canvas, Xgrid[:, free_dims[0]], [p[:,d] for p in percs], label=label, **kwargs))
|
||||
fills.append(pl().fill_gradient(canvas, Xgrid[:, free_dims[0]], [p[:,d] for p in percs], label=label, **kwargs))
|
||||
return dict(gpdensity=fills)
|
||||
else:
|
||||
pass # Nothing to plot!
|
||||
|
|
@ -299,7 +299,7 @@ def plot(self, plot_limits=None, fixed_inputs=None,
|
|||
:param bool plot_density: plot density instead of the confidence interval?
|
||||
:param dict predict_kw: the keyword arguments for the prediction. If you want to plot a specific kernel give dict(kern=<specific kernel>) in here
|
||||
"""
|
||||
canvas, _ = pl.new_canvas(projection=projection, **kwargs)
|
||||
canvas, _ = pl().new_canvas(projection=projection, **kwargs)
|
||||
helper_data = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
|
||||
helper_prediction = helper_predict_with_model(self, helper_data[5], plot_raw,
|
||||
apply_link, np.linspace(2.5, 97.5, levels*2) if plot_density else (lower,upper),
|
||||
|
|
@ -321,7 +321,7 @@ def plot(self, plot_limits=None, fixed_inputs=None,
|
|||
plots.update(_plot_samples(canvas, helper_data, helper_prediction, projection, "Lik Samples"))
|
||||
if hasattr(self, 'Z') and plot_inducing:
|
||||
plots.update(_plot_inducing(self, canvas, visible_dims, projection, 'Inducing'))
|
||||
return pl.add_to_canvas(canvas, plots, legend=legend)
|
||||
return pl().add_to_canvas(canvas, plots, legend=legend)
|
||||
|
||||
|
||||
def plot_f(self, plot_limits=None, fixed_inputs=None,
|
||||
|
|
|
|||
|
|
@ -5,24 +5,23 @@
|
|||
#import Tango
|
||||
#from base_plots import gpplot, x_frame1D, x_frame2D
|
||||
|
||||
from . import pl
|
||||
from . import plotting_library as pl
|
||||
|
||||
def plot_optimizer(optimizer, **kwargs):
|
||||
if optimizer.trace == None:
|
||||
print("No trace present so I can't plot it. Please check that the optimizer actually supplies a trace.")
|
||||
else:
|
||||
canvas, kwargs = pl.new_canvas(**kwargs)
|
||||
plots = dict(trace=pl.plot(range(len(optimizer.trace)), optimizer.trace))
|
||||
return pl.add_to_canvas(canvas, plots, xlabel='Iteration', ylabel='f(x)')
|
||||
canvas, kwargs = pl().new_canvas(**kwargs)
|
||||
plots = dict(trace=pl().plot(range(len(optimizer.trace)), optimizer.trace))
|
||||
return pl().add_to_canvas(canvas, plots, xlabel='Iteration', ylabel='f(x)')
|
||||
|
||||
def plot_sgd_traces(optimizer):
|
||||
figure = pl.figure(2,1)
|
||||
canvas, _ = pl.new_canvas(figure, 1, 1, title="Parameters")
|
||||
figure = pl().figure(2,1)
|
||||
canvas, _ = pl().new_canvas(figure, 1, 1, title="Parameters")
|
||||
plots = dict(lines=[])
|
||||
for k in optimizer.param_traces.keys():
|
||||
plots['lines'].append(pl.plot(canvas, range(len(optimizer.param_traces[k])), optimizer.param_traces[k], label=k))
|
||||
pl.add_to_canvas(canvas, legend=True)
|
||||
canvas, _ = pl.new_canvas(figure, 1, 2, title="Objective function")
|
||||
pl.plot(canvas, range(len(optimizer.fopt_trace)), optimizer.fopt_trace)
|
||||
return pl.add_to_canvas(canvas, plots, legend=True)
|
||||
|
||||
plots['lines'].append(pl().plot(canvas, range(len(optimizer.param_traces[k])), optimizer.param_traces[k], label=k))
|
||||
pl().add_to_canvas(canvas, legend=True)
|
||||
canvas, _ = pl().new_canvas(figure, 1, 2, title="Objective function")
|
||||
pl().plot(canvas, range(len(optimizer.fopt_trace)), optimizer.fopt_trace)
|
||||
return pl().add_to_canvas(canvas, plots, legend=True)
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@
|
|||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#===============================================================================
|
||||
import numpy as np
|
||||
from . import pl
|
||||
from . import plotting_library as pl
|
||||
from .. import Tango
|
||||
from .plot_util import get_x_y_var,\
|
||||
update_not_existing_kwargs, \
|
||||
helper_for_plot_data, scatter_label_generator, subsample_X,\
|
||||
find_best_layout_for_subplots
|
||||
|
||||
def plot_ARD(kernel, filtering=None, **kwargs):
|
||||
def plot_ARD(kernel, filtering=None, legend=False, **kwargs):
|
||||
"""
|
||||
If an ARD kernel is present, plot a bar representation using matplotlib
|
||||
|
||||
|
|
@ -45,11 +45,8 @@ def plot_ARD(kernel, filtering=None, **kwargs):
|
|||
will be used for plotting.
|
||||
:type filtering: list of names to use for ARD plot
|
||||
"""
|
||||
canvas, kwargs = pl.new_canvas(kwargs)
|
||||
|
||||
Tango.reset()
|
||||
|
||||
bars = []
|
||||
ard_params = np.atleast_2d(kernel.input_sensitivity(summarize=False))
|
||||
bottom = 0
|
||||
last_bottom = bottom
|
||||
|
|
@ -59,20 +56,24 @@ def plot_ARD(kernel, filtering=None, **kwargs):
|
|||
if filtering is None:
|
||||
filtering = kernel.parameter_names(recursive=False)
|
||||
|
||||
bars = []
|
||||
kwargs = update_not_existing_kwargs(kwargs, pl().defaults.ard)
|
||||
canvas, kwargs = pl().new_canvas(xlim=(-.5, kernel.input_dim-.5), **kwargs)
|
||||
for i in range(ard_params.shape[0]):
|
||||
if kernel.parameters[i].name in filtering:
|
||||
c = Tango.nextMedium()
|
||||
bars.append(pl.barplot(canvas, x, ard_params[i,:], color=c, label=kernel.parameters[i].name, bottom=bottom))
|
||||
bars.append(pl().barplot(canvas, x,
|
||||
ard_params[i,:], color=c,
|
||||
label=kernel.parameters[i].name,
|
||||
bottom=bottom, **kwargs))
|
||||
last_bottom = ard_params[i,:]
|
||||
bottom += last_bottom
|
||||
else:
|
||||
print("filtering out {}".format(kernel.parameters[i].name))
|
||||
|
||||
plt.add_to_canvas()
|
||||
ax.set_xlim(-.5, kernel.input_dim - .5)
|
||||
add_bar_labels(fig, ax, [bars[-1]], bottom=bottom-last_bottom)
|
||||
#add_bar_labels(fig, ax, [bars[-1]], bottom=bottom-last_bottom)
|
||||
|
||||
return dict(barplots=bars)
|
||||
return pl().add_to_canvas(canvas, bars, legend=legend)
|
||||
|
||||
def plot_covariance(kernel, x=None, label=None, plot_limits=None, visible_dims=None, resolution=None, projection=None, levels=20, **mpl_kwargs):
|
||||
"""
|
||||
|
|
@ -85,7 +86,7 @@ def plot_covariance(kernel, x=None, label=None, plot_limits=None, visible_dims=N
|
|||
:resolution: the resolution of the lines used in plotting
|
||||
:mpl_kwargs avalid keyword arguments to pass through to matplotlib (e.g. lw=7)
|
||||
"""
|
||||
canvas, error_kwargs = pl.new_canvas(projection=projection, **error_kwargs)
|
||||
canvas, error_kwargs = pl().new_canvas(projection=projection, **error_kwargs)
|
||||
_, _, _, _, free_dims, Xgrid, x, y, _, _, resolution = helper_for_plot_data(kernel, plot_limits, visible_dims, None, resolution)
|
||||
|
||||
if len(free_dims)<=2:
|
||||
|
|
@ -96,22 +97,22 @@ def plot_covariance(kernel, x=None, label=None, plot_limits=None, visible_dims=N
|
|||
assert x.size == 1, "The size of the fixed variable x is not 1"
|
||||
x = x.reshape((1, 1))
|
||||
# 1D plotting:
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_1d) # @UndefinedVariable
|
||||
plots = dict(covariance=[pl.plot(canvas, Xgrid[:, free_dims], mu, label=label, **kwargs)])
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_1d) # @UndefinedVariable
|
||||
plots = dict(covariance=[pl().plot(canvas, Xgrid[:, free_dims], mu, label=label, **kwargs)])
|
||||
else:
|
||||
if projection == '2d':
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_2d) # @UndefinedVariable
|
||||
plots = dict(covariance=[pl.contour(canvas, x, y,
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_2d) # @UndefinedVariable
|
||||
plots = dict(covariance=[pl().contour(canvas, x, y,
|
||||
mu.reshape(resolution, resolution).T,
|
||||
levels=levels, label=label, **kwargs)])
|
||||
elif projection == '3d':
|
||||
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_3d) # @UndefinedVariable
|
||||
plots = dict(covariance=[pl.surface(canvas, x, y,
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_3d) # @UndefinedVariable
|
||||
plots = dict(covariance=[pl().surface(canvas, x, y,
|
||||
mu.reshape(resolution, resolution).T,
|
||||
label=label,
|
||||
**kwargs)])
|
||||
|
||||
return pl.add_to_canvas(canvas, plots)
|
||||
return pl().add_to_canvas(canvas, plots)
|
||||
|
||||
if kernel.input_dim == 1:
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#===============================================================================
|
||||
import numpy as np
|
||||
from . import pl
|
||||
from . import plotting_library as pl
|
||||
from .plot_util import get_x_y_var,\
|
||||
update_not_existing_kwargs, \
|
||||
helper_for_plot_data, scatter_label_generator, subsample_X,\
|
||||
|
|
@ -58,12 +58,12 @@ def _plot_latent_scatter(canvas, X, visible_dims, labels, marker, num_samples, p
|
|||
scatters = []
|
||||
generate_colors = 'color' not in kwargs
|
||||
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)
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.latent_scatter)
|
||||
if generate_colors:
|
||||
kwargs['color'] = Tango.nextMedium()
|
||||
if projection == '3d':
|
||||
scatters.append(pl.scatter(canvas, x, y, Z=z, marker=m, label=this_label, **kwargs))
|
||||
else: scatters.append(pl.scatter(canvas, x, y, marker=m, label=this_label, **kwargs))
|
||||
scatters.append(pl().scatter(canvas, x, y, Z=z, marker=m, label=this_label, **kwargs))
|
||||
else: scatters.append(pl().scatter(canvas, x, y, marker=m, label=this_label, **kwargs))
|
||||
return scatters
|
||||
|
||||
def plot_latent_scatter(self, labels=None,
|
||||
|
|
@ -87,7 +87,7 @@ def plot_latent_scatter(self, labels=None,
|
|||
"""
|
||||
input_1, input_2, input_3 = sig_dims = self.get_most_significant_input_dimensions(which_indices)
|
||||
|
||||
canvas, kwargs = pl.new_canvas(projection=projection,
|
||||
canvas, kwargs = pl().new_canvas(projection=projection,
|
||||
xlabel='latent dimension %i' % input_1,
|
||||
ylabel='latent dimension %i' % input_2,
|
||||
zlabel='latent dimension %i' % input_3, **kwargs)
|
||||
|
|
@ -98,7 +98,7 @@ def plot_latent_scatter(self, labels=None,
|
|||
else:
|
||||
legend = find_best_layout_for_subplots(len(np.unique(labels)))[1]
|
||||
scatters = _plot_latent_scatter(canvas, X, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
|
||||
return pl.add_to_canvas(canvas, dict(scatter=scatters), legend=legend)
|
||||
return pl().add_to_canvas(canvas, dict(scatter=scatters), legend=legend)
|
||||
|
||||
|
||||
|
||||
|
|
@ -126,14 +126,14 @@ def plot_latent_inducing(self,
|
|||
|
||||
if 'color' not in kwargs:
|
||||
kwargs['color'] = 'white'
|
||||
canvas, kwargs = pl.new_canvas(projection=projection,
|
||||
canvas, kwargs = pl().new_canvas(projection=projection,
|
||||
xlabel='latent dimension %i' % input_1,
|
||||
ylabel='latent dimension %i' % input_2,
|
||||
zlabel='latent dimension %i' % input_3, **kwargs)
|
||||
Z = self.Z.values
|
||||
labels = np.array(['inducing'] * Z.shape[0])
|
||||
scatters = _plot_latent_scatter(canvas, Z, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
|
||||
return pl.add_to_canvas(canvas, dict(scatter=scatters), legend=legend)
|
||||
return pl().add_to_canvas(canvas, dict(scatter=scatters), legend=legend)
|
||||
|
||||
|
||||
|
||||
|
|
@ -150,13 +150,13 @@ def _plot_magnification(self, canvas, which_indices, Xgrid,
|
|||
Xtest_full[:, which_indices] = x
|
||||
mf = self.predict_magnification(Xtest_full, kern=kern, mean=mean, covariance=covariance)
|
||||
return mf.reshape(resolution, resolution).T
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl.defaults.magnification)
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl().defaults.magnification)
|
||||
try:
|
||||
if updates:
|
||||
return pl.imshow_interact(canvas, plot_function, (xmin[0], xmax[0], xmin[1], xmax[1]), resolution=resolution, **imshow_kwargs)
|
||||
return pl().imshow_interact(canvas, plot_function, (xmin[0], xmax[0], xmin[1], xmax[1]), resolution=resolution, **imshow_kwargs)
|
||||
else: raise NotImplementedError
|
||||
except NotImplementedError:
|
||||
return pl.imshow(canvas, plot_function(Xgrid[:, which_indices]), (xmin[0], xmax[0], xmin[1], xmax[1]), **imshow_kwargs)
|
||||
return pl().imshow(canvas, plot_function(Xgrid[:, which_indices]), (xmin[0], xmax[0], xmin[1], xmax[1]), **imshow_kwargs)
|
||||
|
||||
def plot_magnification(self, labels=None, which_indices=None,
|
||||
resolution=60, marker='<>^vsd', legend=True,
|
||||
|
|
@ -186,7 +186,7 @@ def plot_magnification(self, labels=None, which_indices=None,
|
|||
"""
|
||||
input_1, input_2 = which_indices = self.get_most_significant_input_dimensions(which_indices)[:2]
|
||||
X, _, _, _, _, Xgrid, _, _, xmin, xmax, resolution = helper_for_plot_data(self, plot_limits, which_indices, None, resolution)
|
||||
canvas, imshow_kwargs = pl.new_canvas(xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
canvas, imshow_kwargs = pl().new_canvas(xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **imshow_kwargs)
|
||||
if (labels is not None):
|
||||
legend = find_best_layout_for_subplots(len(np.unique(labels)))[1]
|
||||
|
|
@ -195,7 +195,7 @@ def plot_magnification(self, labels=None, which_indices=None,
|
|||
legend = False
|
||||
scatters = _plot_latent_scatter(canvas, X, which_indices, labels, marker, num_samples, projection='2d', **scatter_kwargs or {})
|
||||
view = _plot_magnification(self, canvas, which_indices[:2], Xgrid, xmin, xmax, resolution, updates, mean, covariance, kern, **imshow_kwargs)
|
||||
retval = pl.add_to_canvas(canvas, dict(scatter=scatters, imshow=view),
|
||||
retval = pl().add_to_canvas(canvas, dict(scatter=scatters, imshow=view),
|
||||
legend=legend,
|
||||
)
|
||||
_wait_for_updates(view, updates)
|
||||
|
|
@ -214,13 +214,13 @@ def _plot_latent(self, canvas, which_indices, Xgrid,
|
|||
mf = np.log(self.predict(Xtest_full, kern=kern)[1])
|
||||
return mf.reshape(resolution, resolution).T
|
||||
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl.defaults.latent)
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl().defaults.latent)
|
||||
try:
|
||||
if updates:
|
||||
return pl.imshow_interact(canvas, plot_function, (xmin[0], xmax[0], xmin[1], xmax[1]), resolution=resolution, **imshow_kwargs)
|
||||
return pl().imshow_interact(canvas, plot_function, (xmin[0], xmax[0], xmin[1], xmax[1]), resolution=resolution, **imshow_kwargs)
|
||||
else: raise NotImplementedError
|
||||
except NotImplementedError:
|
||||
return pl.imshow(canvas, plot_function(Xgrid[:, which_indices]), (xmin[0], xmax[0], xmin[1], xmax[1]), **imshow_kwargs)
|
||||
return pl().imshow(canvas, plot_function(Xgrid[:, which_indices]), (xmin[0], xmax[0], xmin[1], xmax[1]), **imshow_kwargs)
|
||||
|
||||
def plot_latent(self, labels=None, which_indices=None,
|
||||
resolution=60, legend=True,
|
||||
|
|
@ -249,7 +249,7 @@ def plot_latent(self, labels=None, which_indices=None,
|
|||
"""
|
||||
input_1, input_2 = which_indices = self.get_most_significant_input_dimensions(which_indices)[:2]
|
||||
X, _, _, _, _, Xgrid, _, _, xmin, xmax, resolution = helper_for_plot_data(self, plot_limits, which_indices, None, resolution)
|
||||
canvas, imshow_kwargs = pl.new_canvas(xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
canvas, imshow_kwargs = pl().new_canvas(xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **imshow_kwargs)
|
||||
if (labels is not None):
|
||||
legend = find_best_layout_for_subplots(len(np.unique(labels)))[1]
|
||||
|
|
@ -258,7 +258,7 @@ def plot_latent(self, labels=None, which_indices=None,
|
|||
legend = False
|
||||
scatters = _plot_latent_scatter(canvas, X, which_indices, labels, marker, num_samples, projection='2d', **scatter_kwargs or {})
|
||||
view = _plot_latent(self, canvas, which_indices, Xgrid, xmin, xmax, resolution, updates, kern, **imshow_kwargs)
|
||||
retval = pl.add_to_canvas(canvas, dict(scatter=scatters, imshow=view), legend=legend)
|
||||
retval = pl().add_to_canvas(canvas, dict(scatter=scatters, imshow=view), legend=legend)
|
||||
_wait_for_updates(view, updates)
|
||||
return retval
|
||||
|
||||
|
|
@ -274,15 +274,15 @@ def _plot_steepest_gradient_map(self, canvas, which_indices, Xgrid,
|
|||
#dmu_dX = self.predictive_gradients(Xgrid, kern=kern)[0].sum(1)
|
||||
argmax = np.argmax(dmu_dX, 1).astype(int)
|
||||
return dmu_dX.max(1).reshape(resolution, resolution).T, np.array(output_labels)[argmax].reshape(resolution, resolution).T
|
||||
annotation_kwargs = update_not_existing_kwargs(annotation_kwargs or {}, pl.defaults.annotation)
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs or {}, pl.defaults.gradient)
|
||||
annotation_kwargs = update_not_existing_kwargs(annotation_kwargs or {}, pl().defaults.annotation)
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs or {}, pl().defaults.gradient)
|
||||
try:
|
||||
if updates:
|
||||
return dict(annotation=pl.annotation_heatmap_interact(canvas, plot_function, (xmin[0], xmax[0], xmin[1], xmax[1]), resolution=resolution, imshow_kwargs=imshow_kwargs, **annotation_kwargs))
|
||||
return dict(annotation=pl().annotation_heatmap_interact(canvas, plot_function, (xmin[0], xmax[0], xmin[1], xmax[1]), resolution=resolution, imshow_kwargs=imshow_kwargs, **annotation_kwargs))
|
||||
else:
|
||||
raise NotImplementedError
|
||||
except NotImplementedError:
|
||||
imshow, annotation = pl.annotation_heatmap(canvas, *plot_function(Xgrid[:, which_indices]), extent=(xmin[0], xmax[0], xmin[1], xmax[1]), imshow_kwargs=imshow_kwargs, **annotation_kwargs)
|
||||
imshow, annotation = pl().annotation_heatmap(canvas, *plot_function(Xgrid[:, which_indices]), extent=(xmin[0], xmax[0], xmin[1], xmax[1]), imshow_kwargs=imshow_kwargs, **annotation_kwargs)
|
||||
return dict(heatmap=imshow, annotation=annotation)
|
||||
|
||||
def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which_indices=None,
|
||||
|
|
@ -314,7 +314,7 @@ def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which
|
|||
"""
|
||||
input_1, input_2 = which_indices = self.get_most_significant_input_dimensions(which_indices)[:2]
|
||||
X, _, _, _, _, Xgrid, _, _, xmin, xmax, resolution = helper_for_plot_data(self, plot_limits, which_indices, None, resolution)
|
||||
canvas, imshow_kwargs = pl.new_canvas(xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
canvas, imshow_kwargs = pl().new_canvas(xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **imshow_kwargs)
|
||||
if (data_labels is not None):
|
||||
legend = find_best_layout_for_subplots(len(np.unique(data_labels)))[1]
|
||||
|
|
@ -323,7 +323,7 @@ def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which
|
|||
legend = False
|
||||
plots = dict(scatter=_plot_latent_scatter(canvas, X, which_indices, data_labels, marker, num_samples, **scatter_kwargs or {}))
|
||||
plots.update(_plot_steepest_gradient_map(self, canvas, which_indices, Xgrid, xmin, xmax, resolution, output_labels, updates, kern, annotation_kwargs=annotation_kwargs, **imshow_kwargs))
|
||||
retval = pl.add_to_canvas(canvas, plots, legend=legend)
|
||||
retval = pl().add_to_canvas(canvas, plots, legend=legend)
|
||||
_wait_for_updates(plots['annotation'], updates)
|
||||
return retval
|
||||
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ import itertools
|
|||
|
||||
def in_ipynb():
|
||||
try:
|
||||
get_ipython()
|
||||
return True
|
||||
cfg = get_ipython().config
|
||||
return 'TerminalIPythonApp' not in cfg
|
||||
except NameError:
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ confidence_interval = dict(mode='lines', line_kwargs=dict(color=Tango.colorsHex[
|
|||
# data_y_1d_plot = dict(color='k', linewidth=1.5)
|
||||
#
|
||||
# # Kernel plots:
|
||||
# ard = dict(edgecolor='k', linewidth=1.2)
|
||||
ard = dict(linewidth=1.2, barmode='stack')
|
||||
#
|
||||
# # Input plots:
|
||||
latent = dict(colorscale='Greys', reversescale=True, zsmooth='best')
|
||||
|
|
|
|||
|
|
@ -64,7 +64,10 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
|||
figure = tools.make_subplots(rows, cols, specs=specs)
|
||||
return figure
|
||||
|
||||
def new_canvas(self, canvas=None, row=1, col=1, projection='2d', xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, **kwargs):
|
||||
def new_canvas(self, canvas=None, row=1, col=1, projection='2d',
|
||||
xlabel=None, ylabel=None, zlabel=None,
|
||||
title=None, xlim=None,
|
||||
ylim=None, zlim=None, **kwargs):
|
||||
#if 'filename' not in kwargs:
|
||||
# print('PlotlyWarning: filename was not given, this may clutter your plotly workspace')
|
||||
# filename = None
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ import GPy, os
|
|||
from nose import SkipTest
|
||||
|
||||
from ..util.config import config
|
||||
from ..plotting import change_plotting_library
|
||||
|
||||
change_plotting_library('matplotlib')
|
||||
if config.get('plotting', 'library') != 'matplotlib':
|
||||
raise SkipTest("Matplotlib not installed, not testing plots")
|
||||
|
||||
|
|
@ -90,6 +92,16 @@ def _image_comparison(baseline_images, extensions=['pdf','svg','ong'], tol=11):
|
|||
yield do_test
|
||||
plt.close('all')
|
||||
|
||||
def test_kernel():
|
||||
np.random.seed(1239847)
|
||||
k = GPy.kern.RBF(5, ARD=True) + GPy.kern.Linear(3, active_dims=[0,2,4], ARD=True) + GPy.kern.Bias(2)
|
||||
k.randomize()
|
||||
k.plot_ARD(legend=True)
|
||||
for do_test in _image_comparison(
|
||||
baseline_images=['kern_{}'.format(sub) for sub in ["ARD",]],
|
||||
extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
||||
def test_plot():
|
||||
np.random.seed(11111)
|
||||
X = np.random.uniform(-2, 2, (40, 1))
|
||||
|
|
|
|||
BIN
GPy/testing/plotting_tests/baseline/kern_ARD.png
Normal file
BIN
GPy/testing/plotting_tests/baseline/kern_ARD.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
Loading…
Add table
Add a link
Reference in a new issue