generated from tillahoffmann/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from tillahoffmann/interface
Update docs and clean up interface.
- Loading branch information
Showing
36 changed files
with
377 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,3 +141,5 @@ workspace/ | |
*.o | ||
*.ipynb | ||
.cmdstanpy_cache | ||
*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.14.1 | ||
kernelspec: | ||
display_name: Python 3 (ipykernel) | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
```{code-cell} ipython3 | ||
import matplotlib as mpl | ||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
mpl.style.use("../jss.mplstyle") | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
fig, ax = plt.subplots() | ||
ax.set_aspect(1) | ||
offset = 2 | ||
xy = { | ||
(0, 0): ("how strong are\nthe data?", {"question": True}), | ||
(-1, -1): ("non-centered\nparameterization", {"rotate": True}), | ||
(0, -1): ("centered\nparameterization", {"rotate": True}), | ||
(1, -1): ("other method?", {"rotate": True}), | ||
(offset + 0.5, 0): ("is the GP on a\nregular grid?", {"question": True}), | ||
(offset, -1): ("Fourier\nmethods", {"rotate": True}), | ||
(offset + 1, -1): ("are the data\n\"dense\"?", {"question": True}), | ||
(offset + 0.5, -2): ("Fourier inducing\npoints", {"rotate": True}), | ||
(offset + 1.5, -2): ("structured\ndependencies", {"rotate": True}), | ||
} | ||
ax.scatter(*np.transpose(list(xy))) | ||
for (x, y), (text, kwargs) in xy.items(): | ||
kwargs = kwargs or {} | ||
rotate = kwargs.pop("rotate", False) | ||
question = kwargs.pop("question", False) | ||
kwargs = { | ||
"fontsize": "small", | ||
"ha": "center", | ||
"va": "top" if rotate else "center", | ||
"rotation": 90 if rotate else 0, | ||
"bbox": { | ||
"edgecolor": "none" if question else "k", | ||
"boxstyle": "round,pad=.5", | ||
"facecolor": "k" if question else "w", | ||
}, | ||
"color": "w" if question else "k", | ||
} | kwargs | ||
ax.text(x, y, text, **kwargs) | ||
def connect(xy1, xy2, frac=0.25, color="k", label=None): | ||
x1, y1 = xy1 | ||
x2, y2 = xy2 | ||
xy = [xy1, (x1, y1 - frac), (x2, y1 - frac), xy2] | ||
ax.plot(*np.transpose(xy), color=color, zorder=0, linewidth=1) | ||
if label: | ||
kwargs = { | ||
"fontsize": "small", | ||
"rotation": 90, | ||
"ha": "center", | ||
"va": "center", | ||
"bbox": { | ||
"edgecolor": "none", | ||
"facecolor": "w", | ||
} | ||
} | ||
ax.text(x2, (y1 - frac + y2) / 2, label, **kwargs) | ||
connect((0, 0), (-1, -1), label="weak") | ||
connect((0, 0), (0, -1), label="strong") | ||
connect((0, 0), (1, -1), label="very\nstrong") | ||
connect((offset + 0.5, 0), (offset, -1), label="yes") | ||
connect((offset + 0.5, 0), (offset + 1, -1), label="no") | ||
connect((offset + 1, -1), (offset + 0.5, -2), label="yes") | ||
connect((offset + 1, -1), (offset + 1.5, -2), label="no") | ||
ax.set_xlim(-1.25, 3.75) | ||
ax.set_ylim(-3, 0.25) | ||
ax.set_axis_off() | ||
ax.text(-1, 0, "(a)", ha="center", va="center") | ||
ax.text(1.8, 0, "(b)", ha="center", va="center") | ||
fig.tight_layout() | ||
fig.savefig("decision_tree.pdf", bbox_inches="tight") | ||
fig.savefig("decision_tree.png", bbox_inches="tight") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.14.1 | ||
kernelspec: | ||
display_name: Python 3 (ipykernel) | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
```{code-cell} ipython3 | ||
from gptools.util.kernels import ExpQuadKernel, MaternKernel | ||
from gptools.util.fft import transform_irfft, evaluate_rfft_scale | ||
import matplotlib as mpl | ||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
mpl.style.use("../jss.mplstyle") | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
np.random.seed(9) # Seed picked for good legend positioning. Works for any though. | ||
fig, axes = plt.subplots(2, 2) | ||
length_scale = 0.2 | ||
kernels = { | ||
"squared exp.": lambda period: ExpQuadKernel(1, length_scale, period), | ||
"Matern ³⁄₂": lambda period: MaternKernel(1.5, 1, length_scale, period), | ||
} | ||
x = np.linspace(0, 1, 101, endpoint=False) | ||
z = np.random.normal(0, 1, x.size) | ||
for ax, (key, kernel) in zip(axes[1], kernels.items()): | ||
value = kernel(None).evaluate(0, x[:, None]) | ||
line, = axes[0, 0].plot(x, value, ls="--") | ||
rfft = kernel(1).evaluate_rfft([x.size]) | ||
value = np.fft.irfft(rfft, x.size) | ||
axes[0, 1].plot(rfft, label=key) | ||
axes[0, 0].plot(x, value, color=line.get_color()) | ||
for maxf, ls in [(x.size // 2 + 1, "-"), (5, "--"), (3, ":")]: | ||
rfft_scale = evaluate_rfft_scale(rfft=rfft, size=x.size) | ||
rfft_scale[maxf:] = 0 | ||
f = transform_irfft(z, np.zeros_like(z), rfft_scale=rfft_scale) | ||
ax.plot(x, f, ls=ls, color=line.get_color(), label=fr"$\xi_\max={maxf}$") | ||
ax.set_xlabel("position $x$") | ||
ax.set_ylabel(f"{key} GP $f$") | ||
ax = axes[0, 0] | ||
ax.set_ylabel("kernel $k(0,x)$") | ||
ax.set_xlabel("position $x$") | ||
ax.legend([ | ||
mpl.lines.Line2D([], [], ls="--", color="gray"), | ||
mpl.lines.Line2D([], [], ls="-", color="gray"), | ||
], ["standard", "periodic"], fontsize="small") | ||
ax.text(0.05, 0.05, "(a)", transform=ax.transAxes) | ||
ax.yaxis.set_ticks([0, 0.5, 1]) | ||
ax = axes[0, 1] | ||
ax.set_yscale("log") | ||
ax.set_ylim(1e-5, x.size) | ||
ax.set_xlabel(r"frequency $\xi$") | ||
ax.set_ylabel(r"Fourier kernel $\tilde k=\phi\left(k\right)$") | ||
ax.legend(fontsize="small", loc="center right") | ||
ax.text(0.95, 0.95, "(b)", transform=ax.transAxes, ha="right", va="top") | ||
ax = axes[1, 0] | ||
ax.legend(fontsize="small", loc="lower center") | ||
ax.text(0.95, 0.95, "(c)", transform=ax.transAxes, ha="right", va="top") | ||
ax = axes[1, 1] | ||
ax.legend(fontsize="small", loc="lower center") | ||
ax.sharey(axes[1, 0]) | ||
ax.text(0.95, 0.95, "(d)", transform=ax.transAxes, ha="right", va="top") | ||
for ax in [axes[0, 0], *axes[1]]: | ||
ax.xaxis.set_ticks([0, 0.5, 1]) | ||
fig.tight_layout() | ||
fig.savefig("kernels.pdf", bbox_inches="tight") | ||
fig.savefig("kernels.png", bbox_inches="tight") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.