mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-08 15:05:15 +02:00
[plotting] library is unfolding and should be working tonight
This commit is contained in:
parent
a6c0d82ef7
commit
c3afb4eaaf
13 changed files with 648 additions and 263 deletions
|
|
@ -27,16 +27,51 @@
|
|||
# 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
|
||||
from . import update_not_existing_kwargs
|
||||
from . import defaults
|
||||
|
||||
from functools import wraps
|
||||
from . import pl
|
||||
|
||||
import numpy as np
|
||||
from .plot_util import get_x_y_var, get_free_dims, get_which_data_ycols,\
|
||||
get_which_data_rows, update_not_existing_kwargs
|
||||
|
||||
def _plot_data(self, canvas, which_data_rows='all',
|
||||
which_data_ycols='all', visible_dims=None,
|
||||
error_kwargs=None, **plot_kwargs):
|
||||
if error_kwargs is None:
|
||||
error_kwargs = {}
|
||||
ycols = get_which_data_ycols(self, which_data_ycols)
|
||||
rows = get_which_data_rows(self, which_data_rows)
|
||||
|
||||
X, X_variance, Y = get_x_y_var(self)
|
||||
free_dims = get_free_dims(self, visible_dims, None)
|
||||
|
||||
plots = {}
|
||||
plots['dataplot'] = []
|
||||
plots['xerrorplot'] = []
|
||||
|
||||
#one dimensional plotting
|
||||
if len(free_dims) == 1:
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_1d)
|
||||
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)
|
||||
plots['xerrorplot'].append(pl.xerrorbar(canvas, X[rows, free_dims].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims].flatten()),
|
||||
**error_kwargs))
|
||||
#2D plotting
|
||||
elif len(free_dims) == 2:
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, pl.defaults.data_2d)
|
||||
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))
|
||||
else:
|
||||
raise NotImplementedError("Cannot plot in more then two dimensions")
|
||||
return plots
|
||||
|
||||
def plot_data(self, which_data_rows='all',
|
||||
which_data_ycols='all', visible_dims=None,
|
||||
error_kwargs=None, **plot_kwargs):
|
||||
"""
|
||||
Plot the training data
|
||||
- For higher dimensions than two, use fixed_inputs to plot the data points with some of the inputs fixed.
|
||||
|
|
@ -52,53 +87,9 @@ def _plot_data(self, canvas, which_data_rows='all',
|
|||
:type visible_dims: a numpy array
|
||||
: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
|
||||
"""
|
||||
#deal with optional arguments
|
||||
if which_data_rows == 'all':
|
||||
which_data_rows = slice(None)
|
||||
if which_data_ycols == 'all':
|
||||
which_data_ycols = np.arange(self.output_dim)
|
||||
if error_kwargs is None:
|
||||
error_kwargs = {}
|
||||
|
||||
if hasattr(self, 'has_uncertain_inputs') and self.has_uncertain_inputs():
|
||||
X = self.X.mean
|
||||
X_variance = self.X.variance
|
||||
else:
|
||||
X = self.X
|
||||
X_variance = None
|
||||
Y = self.Y
|
||||
|
||||
#work out what the inputs are for plotting (1D or 2D)
|
||||
if visible_dims is None:
|
||||
visible_dims = np.arange(self.input_dim)
|
||||
assert visible_dims.size <= 2, "Visible inputs cannot be larger than two"
|
||||
free_dims = visible_dims
|
||||
|
||||
#one dimensional plotting
|
||||
if len(free_dims) == 1:
|
||||
for d in which_data_ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, defaults.data_1d)
|
||||
canvas.append(pl.scatter(canvas, X[which_data_rows, free_dims], Y[which_data_rows, d], **plot_kwargs))
|
||||
if X_variance is not None:
|
||||
update_not_existing_kwargs(error_kwargs, defaults.xerrorbar)
|
||||
canvas.append(pl.xerrorbar(canvas, X[which_data_rows, free_dims].flatten(), Y[which_data_rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[which_data_rows, free_dims].flatten()),
|
||||
**error_kwargs))
|
||||
#2D plotting
|
||||
elif len(free_dims) == 2:
|
||||
for d in which_data_ycols:
|
||||
update_not_existing_kwargs(plot_kwargs, defaults.data_2d)
|
||||
canvas = pl.scatter(canvas, X[which_data_rows, free_dims[0]], X[which_data_rows, free_dims[1]],
|
||||
c=Y[which_data_rows, d], vmin=Y.min(), vmax=Y.max(), **plot_kwargs)
|
||||
else:
|
||||
raise NotImplementedError("Cannot plot in more then two dimensions")
|
||||
return canvas
|
||||
|
||||
@wraps(_plot_data)
|
||||
def plot_data(self, which_data_rows='all',
|
||||
which_data_ycols='all', visible_dims=None,
|
||||
error_kwargs=None, **plot_kwargs):
|
||||
:returns list: of plots created.
|
||||
"""
|
||||
canvas, kwargs = pl.get_new_canvas(plot_kwargs)
|
||||
_plot_data(self, canvas, which_data_rows, which_data_ycols, visible_dims, error_kwargs, **kwargs)
|
||||
return pl.show_canvas(canvas)
|
||||
plots = _plot_data(self, canvas, which_data_rows, which_data_ycols, visible_dims, error_kwargs, **kwargs)
|
||||
return pl.show_canvas(canvas, plots)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue