[plotting] restructuring more and more

This commit is contained in:
mzwiessele 2015-10-04 12:31:22 +01:00
parent c07f3dbe98
commit 831e032ade
18 changed files with 330 additions and 272 deletions

View file

@ -0,0 +1,109 @@
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.txt)
import sys
colorsHex = {\
"Aluminium6":"#2e3436",\
"Aluminium5":"#555753",\
"Aluminium4":"#888a85",\
"Aluminium3":"#babdb6",\
"Aluminium2":"#d3d7cf",\
"Aluminium1":"#eeeeec",\
"lightPurple":"#ad7fa8",\
"mediumPurple":"#75507b",\
"darkPurple":"#5c3566",\
"lightBlue":"#729fcf",\
"mediumBlue":"#3465a4",\
"darkBlue": "#204a87",\
"lightGreen":"#8ae234",\
"mediumGreen":"#73d216",\
"darkGreen":"#4e9a06",\
"lightChocolate":"#e9b96e",\
"mediumChocolate":"#c17d11",\
"darkChocolate":"#8f5902",\
"lightRed":"#ef2929",\
"mediumRed":"#cc0000",\
"darkRed":"#a40000",\
"lightOrange":"#fcaf3e",\
"mediumOrange":"#f57900",\
"darkOrange":"#ce5c00",\
"lightButter":"#fce94f",\
"mediumButter":"#edd400",\
"darkButter":"#c4a000"}
darkList = [colorsHex['darkBlue'],colorsHex['darkRed'],colorsHex['darkGreen'], colorsHex['darkOrange'], colorsHex['darkButter'], colorsHex['darkPurple'], colorsHex['darkChocolate'], colorsHex['Aluminium6']]
mediumList = [colorsHex['mediumBlue'], colorsHex['mediumRed'],colorsHex['mediumGreen'], colorsHex['mediumOrange'], colorsHex['mediumButter'], colorsHex['mediumPurple'], colorsHex['mediumChocolate'], colorsHex['Aluminium5']]
lightList = [colorsHex['lightBlue'], colorsHex['lightRed'],colorsHex['lightGreen'], colorsHex['lightOrange'], colorsHex['lightButter'], colorsHex['lightPurple'], colorsHex['lightChocolate'], colorsHex['Aluminium4']]
def currentDark():
return darkList[-1]
def currentMedium():
return mediumList[-1]
def currentLight():
return lightList[-1]
def nextDark():
darkList.append(darkList.pop(0))
return darkList[-1]
def nextMedium():
mediumList.append(mediumList.pop(0))
return mediumList[-1]
def nextLight():
lightList.append(lightList.pop(0))
return lightList[-1]
def reset():
while not darkList[0]==colorsHex['darkBlue']:
darkList.append(darkList.pop(0))
while not mediumList[0]==colorsHex['mediumBlue']:
mediumList.append(mediumList.pop(0))
while not lightList[0]==colorsHex['lightBlue']:
lightList.append(lightList.pop(0))
def hex2rgb(hexcolor):
hexcolor = [hexcolor[1+2*i:1+2*(i+1)] for i in range(3)]
r,g,b = [int(n,16) for n in hexcolor]
return (r,g,b)
colorsRGB = dict([(k,hex2rgb(i)) for k,i in colorsHex.items()])
cdict_RB = {'red' :((0.,colorsRGB['mediumRed'][0]/256.,colorsRGB['mediumRed'][0]/256.),
(.5,colorsRGB['mediumPurple'][0]/256.,colorsRGB['mediumPurple'][0]/256.),
(1.,colorsRGB['mediumBlue'][0]/256.,colorsRGB['mediumBlue'][0]/256.)),
'green':((0.,colorsRGB['mediumRed'][1]/256.,colorsRGB['mediumRed'][1]/256.),
(.5,colorsRGB['mediumPurple'][1]/256.,colorsRGB['mediumPurple'][1]/256.),
(1.,colorsRGB['mediumBlue'][1]/256.,colorsRGB['mediumBlue'][1]/256.)),
'blue':((0.,colorsRGB['mediumRed'][2]/256.,colorsRGB['mediumRed'][2]/256.),
(.5,colorsRGB['mediumPurple'][2]/256.,colorsRGB['mediumPurple'][2]/256.),
(1.,colorsRGB['mediumBlue'][2]/256.,colorsRGB['mediumBlue'][2]/256.))}
cdict_BGR = {'red' :((0.,colorsRGB['mediumBlue'][0]/256.,colorsRGB['mediumBlue'][0]/256.),
(.5,colorsRGB['mediumGreen'][0]/256.,colorsRGB['mediumGreen'][0]/256.),
(1.,colorsRGB['mediumRed'][0]/256.,colorsRGB['mediumRed'][0]/256.)),
'green':((0.,colorsRGB['mediumBlue'][1]/256.,colorsRGB['mediumBlue'][1]/256.),
(.5,colorsRGB['mediumGreen'][1]/256.,colorsRGB['mediumGreen'][1]/256.),
(1.,colorsRGB['mediumRed'][1]/256.,colorsRGB['mediumRed'][1]/256.)),
'blue':((0.,colorsRGB['mediumBlue'][2]/256.,colorsRGB['mediumBlue'][2]/256.),
(.5,colorsRGB['mediumGreen'][2]/256.,colorsRGB['mediumGreen'][2]/256.),
(1.,colorsRGB['mediumRed'][2]/256.,colorsRGB['mediumRed'][2]/256.))}
cdict_Alu = {'red' :((0./5,colorsRGB['Aluminium1'][0]/256.,colorsRGB['Aluminium1'][0]/256.),
(1./5,colorsRGB['Aluminium2'][0]/256.,colorsRGB['Aluminium2'][0]/256.),
(2./5,colorsRGB['Aluminium3'][0]/256.,colorsRGB['Aluminium3'][0]/256.),
(3./5,colorsRGB['Aluminium4'][0]/256.,colorsRGB['Aluminium4'][0]/256.),
(4./5,colorsRGB['Aluminium5'][0]/256.,colorsRGB['Aluminium5'][0]/256.),
(5./5,colorsRGB['Aluminium6'][0]/256.,colorsRGB['Aluminium6'][0]/256.)),
'green' :((0./5,colorsRGB['Aluminium1'][1]/256.,colorsRGB['Aluminium1'][1]/256.),
(1./5,colorsRGB['Aluminium2'][1]/256.,colorsRGB['Aluminium2'][1]/256.),
(2./5,colorsRGB['Aluminium3'][1]/256.,colorsRGB['Aluminium3'][1]/256.),
(3./5,colorsRGB['Aluminium4'][1]/256.,colorsRGB['Aluminium4'][1]/256.),
(4./5,colorsRGB['Aluminium5'][1]/256.,colorsRGB['Aluminium5'][1]/256.),
(5./5,colorsRGB['Aluminium6'][1]/256.,colorsRGB['Aluminium6'][1]/256.)),
'blue' :((0./5,colorsRGB['Aluminium1'][2]/256.,colorsRGB['Aluminium1'][2]/256.),
(1./5,colorsRGB['Aluminium2'][2]/256.,colorsRGB['Aluminium2'][2]/256.),
(2./5,colorsRGB['Aluminium3'][2]/256.,colorsRGB['Aluminium3'][2]/256.),
(3./5,colorsRGB['Aluminium4'][2]/256.,colorsRGB['Aluminium4'][2]/256.),
(4./5,colorsRGB['Aluminium5'][2]/256.,colorsRGB['Aluminium5'][2]/256.),
(5./5,colorsRGB['Aluminium6'][2]/256.,colorsRGB['Aluminium6'][2]/256.))}

View file

@ -1,3 +1,3 @@
from .. import plotting_library as pl
from . import data_plots, gp_plots
from . import data_plots, gp_plots, latent_plots

View file

@ -27,10 +27,8 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#===============================================================================
from . import pl
import numpy as np
from . import pl
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
@ -47,12 +45,14 @@ def _plot_data(self, canvas, which_data_rows='all',
plots = {}
plots['dataplot'] = []
plots['xerrorplot'] = []
if X_variance is not None: plots['xerrorplot'] = []
#one dimensional plotting
if len(free_dims) == 1:
for d in ycols:
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_1d)
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_1d) # @UndefinedVariable
plots['dataplot'].append(pl.scatter(canvas, X[rows, free_dims], Y[rows, d], **plot_kwargs))
if X_variance is not None:
update_not_existing_kwargs(error_kwargs, pl.defaults.xerrorbar)
@ -62,7 +62,7 @@ def _plot_data(self, canvas, which_data_rows='all',
#2D plotting
elif len(free_dims) == 2:
for d in ycols:
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_2d)
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]],
c=Y[rows, d], vmin=Y.min(), vmax=Y.max(), **plot_kwargs))
elif len(free_dims) == 0:
@ -84,7 +84,7 @@ def plot_data(self, which_data_rows='all',
:param which_data_rows: which of the training data to plot (default all)
:type which_data_rows: 'all' or a slice object to slice self.X, self.Y
:param which_data_ycols: when the data has several columns (independant outputs), only plot these
:type which_data_rows: 'all' or a list of integers
:type which_data_ycols: 'all' or a list of integers
:param visible_dims: an array specifying the input dimensions to plot (maximum two)
:type visible_dims: a numpy array
:param dict error_kwargs: kwargs for the error plot for the plotting library you are using
@ -94,7 +94,7 @@ def plot_data(self, which_data_rows='all',
"""
canvas, kwargs = pl.get_new_canvas(plot_kwargs)
plots = _plot_data(self, canvas, which_data_rows, which_data_ycols, visible_dims, error_kwargs, **kwargs)
return pl.show_canvas(canvas, plots)
return pl.show_canvas(canvas, plots, xlabel='x', ylabel='y', legend='dataplot')
def plot_inducing(self, visible_dims=None, **plot_kwargs):
@ -116,11 +116,11 @@ def _plot_inducing(self, canvas, visible_dims, **plot_kwargs):
#one dimensional plotting
if len(free_dims) == 1:
update_not_existing_kwargs(plot_kwargs, pl.defaults.inducing_1d)
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:
update_not_existing_kwargs(plot_kwargs, pl.defaults.inducing_2d)
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:
@ -184,15 +184,16 @@ def _plot_errorbars_trainset(self, canvas,
if 'Y_metadata' not in predict_kw:
predict_kw['Y_metadata'] = self.Y_metadata or {}
_, percs, _ = helper_predict_with_model(self, Xgrid, plot_raw,
apply_link, (0, 100),
apply_link, (2.5, 97.5),
ycols, predict_kw)
for d in ycols:
plots.append(pl.yerrorbar(canvas, X[rows,free_dims[0]], Y[rows,d],
np.vstack([Y[rows,d]-percs[0][rows,d], percs[1][rows,d]-Y[rows,d]]),
**plot_kwargs))
return dict(yerrorbars=plots)
else:
pass #Nothing to plot!
else:
raise NotImplementedError("Cannot plot in more then one dimension.")
return plots
return dict(yerrorbars=plots)

View file

@ -29,15 +29,15 @@
#===============================================================================
import numpy as np
from functools import wraps
from . import 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
def plot_mean(self, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols='all',
levels=20,
predict_kw=None,
@ -54,7 +54,6 @@ def plot_mean(self, plot_limits=None, fixed_inputs=None,
:type fixed_inputs: a list of tuples
:param int resolution: The resolution of the prediction [defaults are 1D:200, 2D:50]
:param bool plot_raw: plot the latent function (usually denoted f) only?
:param dict Y_metadata: the Y_metadata (for e.g. heteroscedastic GPs)
:param bool apply_link: whether to apply the link function of the GP to the raw prediction.
:param array-like which_data_ycols: which columns of 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
@ -63,17 +62,17 @@ def plot_mean(self, plot_limits=None, fixed_inputs=None,
canvas, kwargs = pl.get_new_canvas(kwargs)
plots = _plot_mean(self, canvas, plot_limits, fixed_inputs,
resolution, plot_raw,
apply_link, which_data_ycols, levels,
apply_link, visible_dims, which_data_ycols, levels,
predict_kw, **kwargs)
return pl.show_canvas(canvas, plots)
def _plot_mean(self, canvas, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols=None,
levels=20,
predict_kw=None, **kwargs):
_, _, _, _, free_dims, Xgrid, x, y, _, _, resolution = helper_for_plot_data(self, plot_limits, fixed_inputs, resolution)
_, _, _, _, free_dims, Xgrid, x, y, _, _, resolution = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
if len(free_dims)<=2:
mu, _, _ = helper_predict_with_model(self, Xgrid, plot_raw,
@ -82,10 +81,10 @@ def _plot_mean(self, canvas, plot_limits=None, fixed_inputs=None,
predict_kw)
if len(free_dims)==1:
# 1D plotting:
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_1d)
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_1d) # @UndefinedVariable
return dict(gpmean=[pl.plot(canvas, Xgrid[:, free_dims], mu, **kwargs)])
else:
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_2d)
update_not_existing_kwargs(kwargs, pl.defaults.meanplot_2d) # @UndefinedVariable
return dict(gpmean=[pl.contour(canvas, x, y,
mu.reshape(resolution, resolution),
levels=levels, **kwargs)])
@ -96,7 +95,7 @@ def _plot_mean(self, canvas, plot_limits=None, fixed_inputs=None,
def plot_confidence(self, lower=2.5, upper=97.5, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols='all',
predict_kw=None,
**kwargs):
@ -107,36 +106,37 @@ def plot_confidence(self, lower=2.5, upper=97.5, plot_limits=None, fixed_inputs=
Give the Y_metadata in the predict_kw if you need it.
:param float lower: the lower percentile to plot
:param float upper: the upper percentile to plot
:param plot_limits: The limits of the plot. If 1D [xmin,xmax], if 2D [[xmin,ymin],[xmax,ymax]]. Defaluts to data limits
:type plot_limits: np.array
:param fixed_inputs: a list of tuple [(i,v), (i,v)...], specifying that input dimension i should be set to value v.
:type fixed_inputs: a list of tuples
:param int resolution: The resolution of the prediction [default:200]
:param bool plot_raw: plot the latent function (usually denoted f) only?
:param dict Y_metadata: the Y_metadata (for e.g. heteroscedastic GPs)
:param bool apply_link: whether to apply the link function of the GP to the raw prediction.
:param array-like which_data_ycols: which columns of y to plot (array-like or list of ints)
:param array-like visible_dims: which columns of the input X (!) to plot (array-like or list of ints)
: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.get_new_canvas(kwargs)
plots = _plot_confidence(self, canvas, lower, upper, plot_limits,
fixed_inputs, resolution, plot_raw,
apply_link, which_data_ycols,
apply_link, visible_dims, which_data_ycols,
predict_kw, **kwargs)
return pl.show_canvas(canvas, plots)
def _plot_confidence(self, canvas, lower, upper, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols=None,
predict_kw=None,
**kwargs):
_, _, _, _, free_dims, Xgrid, _, _, _, _, _ = helper_for_plot_data(self, plot_limits, fixed_inputs, resolution)
_, _, _, _, free_dims, Xgrid, _, _, _, _, _ = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
ycols = get_which_data_ycols(self, which_data_ycols)
update_not_existing_kwargs(kwargs, pl.defaults.confidence_interval)
update_not_existing_kwargs(kwargs, pl.defaults.confidence_interval) # @UndefinedVariable
if len(free_dims)<=1:
if len(free_dims)==1:
@ -156,7 +156,7 @@ def _plot_confidence(self, canvas, lower, upper, plot_limits=None, fixed_inputs=
def plot_samples(self, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=True,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols='all',
samples=3, predict_kw=None,
**kwargs):
@ -173,6 +173,7 @@ def plot_samples(self, plot_limits=None, fixed_inputs=None,
:param int resolution: The resolution of the prediction [defaults are 1D:200, 2D:50]
:param bool plot_raw: plot the latent function (usually denoted f) only? This is usually what you want!
:param bool apply_link: whether to apply the link function of the GP to the raw prediction.
:param array-like visible_dims: which columns of the input X (!) to plot (array-like or list of ints)
:param array-like which_data_ycols: which columns of 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
:param int levels: for 2D plotting, the number of contour levels to use is
@ -180,17 +181,17 @@ def plot_samples(self, plot_limits=None, fixed_inputs=None,
canvas, kwargs = pl.get_new_canvas(kwargs)
plots = _plot_samples(self, canvas, plot_limits, fixed_inputs,
resolution, plot_raw,
apply_link, which_data_ycols, samples,
apply_link, visible_dims, which_data_ycols, samples,
predict_kw, **kwargs)
return pl.show_canvas(canvas, plots)
def _plot_samples(self, canvas, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols=None,
samples=3,
predict_kw=None, **kwargs):
_, _, _, _, free_dims, Xgrid, x, y, _, _, resolution = helper_for_plot_data(self, plot_limits, fixed_inputs, resolution)
_, _, _, _, free_dims, Xgrid, _, _, _, _, resolution = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
if len(free_dims)<2:
@ -198,7 +199,7 @@ def _plot_samples(self, canvas, plot_limits=None, fixed_inputs=None,
# 1D plotting:
_, _, samples = helper_predict_with_model(self, Xgrid, plot_raw, apply_link,
None, get_which_data_ycols(self, which_data_ycols), predict_kw, samples)
update_not_existing_kwargs(kwargs, pl.defaults.samples_1d)
update_not_existing_kwargs(kwargs, pl.defaults.samples_1d) # @UndefinedVariable
return dict(gpmean=[pl.plot(canvas, Xgrid[:, free_dims], samples, **kwargs)])
else:
pass # Nothing to plot!
@ -208,7 +209,7 @@ def _plot_samples(self, canvas, plot_limits=None, fixed_inputs=None,
def plot_density(self, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols='all',
levels=35,
predict_kw=None,
@ -226,8 +227,8 @@ def plot_density(self, plot_limits=None, fixed_inputs=None,
:type fixed_inputs: a list of tuples
:param int resolution: The resolution of the prediction [default:200]
:param bool plot_raw: plot the latent function (usually denoted f) only?
:param dict Y_metadata: the Y_metadata (for e.g. heteroscedastic GPs)
:param bool apply_link: whether to apply the link function of the GP to the raw prediction.
:param array-like visible_dims: which columns of the input X (!) to plot (array-like or list of ints)
:param array-like which_data_ycols: which columns of y to plot (array-like or list of ints)
: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
@ -235,22 +236,22 @@ def plot_density(self, plot_limits=None, fixed_inputs=None,
canvas, kwargs = pl.get_new_canvas(kwargs)
plots = _plot_density(self, canvas, plot_limits,
fixed_inputs, resolution, plot_raw,
apply_link, which_data_ycols,
apply_link, visible_dims, which_data_ycols,
levels,
predict_kw, **kwargs)
return pl.show_canvas(canvas, plots)
def _plot_density(self, canvas, plot_limits=None, fixed_inputs=None,
resolution=None, plot_raw=False,
apply_link=False,
apply_link=False, visible_dims=None,
which_data_ycols=None,
levels=35,
predict_kw=None, **kwargs):
_, _, _, _, free_dims, Xgrid, x, y, _, _, resolution = helper_for_plot_data(self, plot_limits, fixed_inputs, resolution)
_, _, _, _, free_dims, Xgrid, x, y, _, _, resolution = helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution)
ycols = get_which_data_ycols(self, which_data_ycols)
update_not_existing_kwargs(kwargs, pl.defaults.density)
update_not_existing_kwargs(kwargs, pl.defaults.density) # @UndefinedVariable
if len(free_dims)<=1:
if len(free_dims)==1:
@ -269,11 +270,126 @@ def _plot_density(self, canvas, plot_limits=None, fixed_inputs=None,
raise RuntimeError('Can only plot density in one input dimension')
def plot(self, plot_limits=None, fixed_inputs=None,
resolution=None, plot_inducing=True,
resolution=None,
plot_raw=False, apply_link=False,
which_data_ycols='all', which_data_rows='all',
levels=20, samples=0,
predict_kw=None,
visible_dims=None,
levels=20, samples=0, samples_likelihood=0, lower=2.5, upper=97.5,
plot_data=True, plot_inducing=True, plot_density=False,
predict_kw=None, error_kwargs=None,
**kwargs):
#maybe get the prediction to be only done once here
pass #for now
"""
Convinience function for plotting the fit of a GP.
Give the Y_metadata in the predict_kw if you need it.
:param plot_limits: The limits of the plot. If 1D [xmin,xmax], if 2D [[xmin,ymin],[xmax,ymax]]. Defaluts to data limits
:type plot_limits: np.array
:param fixed_inputs: a list of tuple [(i,v), (i,v)...], specifying that input dimension i should be set to value v.
:type fixed_inputs: a list of tuples
:param int resolution: The resolution of the prediction [default:200]
:param bool plot_raw: plot the latent function (usually denoted f) only?
:param bool apply_link: whether to apply the link function of the GP to the raw prediction.
:param which_data_ycols: when the data has several columns (independant outputs), only plot these
:type which_data_ycols: 'all' or a list of integers
:param which_data_rows: which of the training data to plot (default all)
:type which_data_rows: 'all' or a slice object to slice self.X, self.Y
:param array-like visible_dims: which columns of the input X (!) to plot (array-like or list of ints)
: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 int samples: the number of samples to draw from the GP and plot into the plot. This will allways be samples from the latent function.
:param int samples_likelihood: the number of samples to draw from the GP and apply the likelihood noise. This is usually not what you want!
:param float lower: the lower percentile to plot
:param float upper: the upper percentile to plot
:param bool plot_data: plot the data into the plot?
:param bool plot_inducing: plot inducing inputs?
: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
:param dict error_kwargs: kwargs for the error plot for the plotting library you are using
:param kwargs plot_kwargs: kwargs for the data plot for the plotting library you are using
"""
canvas, kwargs = pl.get_new_canvas(kwargs)
plots = _plot(self, canvas, plot_limits, fixed_inputs, resolution, plot_raw,
apply_link, which_data_ycols, which_data_rows, visible_dims,
levels, samples, samples_likelihood, lower, upper, plot_data,
plot_inducing, plot_density, predict_kw, error_kwargs)
return pl.show_canvas(canvas, plots)
def plot_f(self, plot_limits=None, fixed_inputs=None,
resolution=None,
apply_link=False,
which_data_ycols='all', which_data_rows='all',
visible_dims=None,
levels=20, samples=0, lower=2.5, upper=97.5,
plot_density=False,
plot_data=True, plot_inducing=True,
predict_kw=None, error_kwargs=None,
**kwargs):
"""
Convinience function for plotting the fit of a GP.
This is the same as plot, except it plots the latent function fit of the GP!
Give the Y_metadata in the predict_kw if you need it.
:param plot_limits: The limits of the plot. If 1D [xmin,xmax], if 2D [[xmin,ymin],[xmax,ymax]]. Defaluts to data limits
:type plot_limits: np.array
:param fixed_inputs: a list of tuple [(i,v), (i,v)...], specifying that input dimension i should be set to value v.
:type fixed_inputs: a list of tuples
:param int resolution: The resolution of the prediction [default:200]
:param bool apply_link: whether to apply the link function of the GP to the raw prediction.
:param which_data_ycols: when the data has several columns (independant outputs), only plot these
:type which_data_ycols: 'all' or a list of integers
:param which_data_rows: which of the training data to plot (default all)
:type which_data_rows: 'all' or a slice object to slice self.X, self.Y
:param array-like visible_dims: an array specifying the input dimensions to plot (maximum two)
: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 int samples: the number of samples to draw from the GP and plot into the plot. This will allways be samples from the latent function.
:param float lower: the lower percentile to plot
:param float upper: the upper percentile to plot
:param bool plot_data: plot the data into the plot?
:param bool plot_inducing: plot inducing inputs?
: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
:param dict error_kwargs: kwargs for the error plot for the plotting library you are using
:param kwargs plot_kwargs: kwargs for the data plot for the plotting library you are using
"""
canvas, kwargs = pl.get_new_canvas(kwargs)
plots = _plot(self, canvas, plot_limits, fixed_inputs, resolution,
True, apply_link, which_data_ycols, which_data_rows,
visible_dims, levels, samples, 0, lower, upper,
plot_data, plot_inducing, plot_density,
predict_kw, error_kwargs)
return pl.show_canvas(canvas, plots)
def _plot(self, canvas, plot_limits=None, fixed_inputs=None,
resolution=None,
plot_raw=False, apply_link=False,
which_data_ycols='all', which_data_rows='all',
visible_dims=None,
levels=20, samples=0, samples_likelihood=0, lower=2.5, upper=97.5,
plot_data=True, plot_inducing=True, plot_density=False,
predict_kw=None, error_kwargs=None,
**kwargs):
plots = {}
if plot_data:
plots.update(_plot_data(self, canvas, which_data_rows, which_data_ycols, visible_dims, error_kwargs))
plots.update(_plot_mean(self, canvas, plot_limits, fixed_inputs, resolution, plot_raw, apply_link, visible_dims, which_data_ycols, levels, predict_kw))
if not plot_density:
plots.update(_plot_confidence(self, canvas, lower, upper, plot_limits, fixed_inputs, resolution, plot_raw, apply_link, visible_dims, which_data_ycols, predict_kw))
else:
plots.update(_plot_density(self, canvas, plot_limits, fixed_inputs, resolution, plot_raw, apply_link, visible_dims, which_data_ycols, levels, predict_kw))
if samples > 0:
plots.update(_plot_samples(self, canvas, plot_limits, fixed_inputs, resolution, True, apply_link, visible_dims, which_data_ycols, samples, predict_kw))
if samples_likelihood > 0:
plots.update(_plot_samples(self, canvas, plot_limits, fixed_inputs, resolution, False, apply_link, visible_dims, which_data_ycols, samples, predict_kw))
if hasattr(self, 'Z') and plot_inducing:
plots.update(_plot_inducing(self, canvas, visible_dims))
return plots

View file

@ -84,7 +84,7 @@ def helper_predict_with_model(self, Xgrid, plot_raw, apply_link, percentiles, wh
fsamples[:, s] = self.likelihood.gp_link.transf(fsamples[:, s])
return retmu, percs, fsamples
def helper_for_plot_data(self, plot_limits, fixed_inputs, resolution):
def helper_for_plot_data(self, plot_limits, visible_dims, fixed_inputs, resolution):
"""
Figure out the data, free_dims and create an Xgrid for
the prediction.
@ -95,7 +95,7 @@ def helper_for_plot_data(self, plot_limits, fixed_inputs, resolution):
if fixed_inputs is None:
fixed_inputs = []
fixed_dims = get_fixed_dims(self, fixed_inputs)
free_dims = get_free_dims(self, None, fixed_dims)
free_dims = get_free_dims(self, visible_dims, fixed_dims)
if len(free_dims) == 1:
#define the frame on which to plot
@ -157,11 +157,10 @@ def get_free_dims(model, visible_dims, fixed_dims):
"""
if visible_dims is None:
visible_dims = np.arange(model.input_dim)
assert visible_dims.size <= 2, "Visible inputs cannot be larger than two"
if fixed_dims is None:
return visible_dims
else:
visible_dims = np.asanyarray(visible_dims)
if fixed_dims is not None:
return np.setdiff1d(visible_dims, fixed_dims)
return visible_dims
def get_fixed_dims(model, fixed_inputs):
"""