()
| 164 | |
| 165 | |
| 166 | def plot_gp(): |
| 167 | np.random.seed(12345) |
| 168 | sns.set_context("paper", font_scale=0.65) |
| 169 | |
| 170 | X_test = np.linspace(-10, 10, 100) |
| 171 | X_train = np.array([-3, 0, 7, 1, -9]) |
| 172 | y_train = np.sin(X_train) |
| 173 | |
| 174 | fig, axes = plt.subplots(2, 2) |
| 175 | alphas = [0, 1e-10, 1e-5, 1] |
| 176 | for ix, (ax, alpha) in enumerate(zip(axes.flatten(), alphas)): |
| 177 | G = GPRegression(kernel="RBFKernel", alpha=alpha) |
| 178 | G.fit(X_train, y_train) |
| 179 | y_pred, conf = G.predict(X_test) |
| 180 | |
| 181 | ax.plot(X_train, y_train, "rx", label="observed") |
| 182 | ax.plot(X_test, np.sin(X_test), label="true fn") |
| 183 | ax.plot(X_test, y_pred, "--", label="MAP (alpha={})".format(alpha)) |
| 184 | ax.fill_between(X_test, y_pred + conf, y_pred - conf, alpha=0.1) |
| 185 | ax.set_xticks([]) |
| 186 | ax.set_yticks([]) |
| 187 | sns.despine() |
| 188 | |
| 189 | ax.legend() |
| 190 | |
| 191 | plt.tight_layout() |
| 192 | plt.savefig("img/gp_alpha.png", dpi=300) |
| 193 | plt.close("all") |
| 194 | |
| 195 | |
| 196 | def plot_gp_dist(): |
nothing calls this directly
no test coverage detected