swh:1:snp:c27a3710b2d4d750eacc54d8f3b9e57283e8e225
Tip revision: 2a30405fefb4de21a0951c885cb38a9d295d68d9 authored by Sergio Diaz on 10 September 2019, 16:00:22 UTC
Merge branch 'awav/gpflow-2.0' into sergio_pasc/gpflow-2.0/adapt-sgpmc-and-gpmc
Merge branch 'awav/gpflow-2.0' into sergio_pasc/gpflow-2.0/adapt-sgpmc-and-gpmc
Tip revision: 2a30405
intro_to_gpflow2_plotting.py
import io
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
def summary_matplotlib_image(figures, step, fmt="png"):
for name, fig in figures.items():
buf = io.BytesIO()
fig.savefig(buf, format=fmt, bbox_inches='tight')
buf.seek(0)
image = buf.getvalue()
image = tf.image.decode_image(buf.getvalue(), channels=4)
image = tf.expand_dims(image, 0)
tf.summary.image(name=name, data=image, step=step)
def plotting_regression(X, Y, xx, mean, var, samples):
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(111)
ax.plot(xx, mean, 'C0', lw=2)
ax.fill_between(xx[:,0],
mean[:,0] - 1.96 * np.sqrt(var[:,0]),
mean[:,0] + 1.96 * np.sqrt(var[:,0]),
color='C0', alpha=0.2)
ax.plot(X, Y, 'kx')
ax.plot(xx, samples[:, :, 0].numpy().T, 'C0', linewidth=.5)
ax.set_ylim(-2., +2.)
ax.set_xlim(0, 10)
plt.close()
return fig