MCPcopy Index your code
hub / github.com/GPflow/GPflow / plot_kernel_prediction

Function plot_kernel_prediction

doc/sphinx/notebooks/getting_started/kernels.pct.py:111–140  ·  view source on GitHub ↗
(
    ax: Axes, kernel: gpflow.kernels.Kernel, *, optimise: bool = True
)

Source from the content-addressed store, hash-verified

109
110
111def plot_kernel_prediction(
112 ax: Axes, kernel: gpflow.kernels.Kernel, *, optimise: bool = True
113) -> None:
114 X = np.array([[-0.5], [0.0], [0.4], [0.5]])
115 Y = np.array([[1.0], [0.0], [0.6], [0.4]])
116 model = gpflow.models.GPR(
117 (X, Y), kernel=deepcopy(kernel), noise_variance=1e-3
118 )
119
120 if optimise:
121 gpflow.set_trainable(model.likelihood, False)
122 opt = gpflow.optimizers.Scipy()
123 opt.minimize(model.training_loss, model.trainable_variables)
124
125 Xplot = np.linspace(-0.6, 0.6, 100)[:, None]
126
127 f_mean, f_var = model.predict_f(Xplot, full_cov=False)
128 f_lower = f_mean - 1.96 * np.sqrt(f_var)
129 f_upper = f_mean + 1.96 * np.sqrt(f_var)
130
131 ax.scatter(X, Y, color="black")
132 (mean_line,) = ax.plot(Xplot, f_mean, "-", label=kernel.__class__.__name__)
133 color = mean_line.get_color()
134 ax.plot(Xplot, f_lower, lw=0.1, color=color)
135 ax.plot(Xplot, f_upper, lw=0.1, color=color)
136 ax.fill_between(
137 Xplot[:, 0], f_lower[:, 0], f_upper[:, 0], color=color, alpha=0.1
138 )
139 ax.set_ylim(bottom=-1.0, top=2.0)
140 ax.set_title("Example data fit")
141
142
143def plot_kernel(

Callers 2

plot_kernelFunction · 0.85
kernels.pct.pyFile · 0.85

Calls 4

minimizeMethod · 0.95
deepcopyFunction · 0.85
predict_fMethod · 0.45
plotMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…