aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/laguerre/scripts
diff options
context:
space:
mode:
authorPatrik Müller <patrik.mueller@ost.ch>2022-07-15 16:24:48 +0200
committerPatrik Müller <patrik.mueller@ost.ch>2022-07-15 16:24:48 +0200
commit7a8795dcb555a551fd09a3c9b15002675e30891f (patch)
tree4913f47695788cc05778a4326ba5ca44b6eb0046 /buch/papers/laguerre/scripts
parentFirst version of section 'Gauss Quadratur', fix to gamma_approx.py when z=0 (diff)
downloadSeminarSpezielleFunktionen-7a8795dcb555a551fd09a3c9b15002675e30891f.tar.gz
SeminarSpezielleFunktionen-7a8795dcb555a551fd09a3c9b15002675e30891f.zip
Change image scripts to PDF format, update Makefile, add complex plane plot
Diffstat (limited to 'buch/papers/laguerre/scripts')
-rw-r--r--buch/papers/laguerre/scripts/estimates.py12
-rw-r--r--buch/papers/laguerre/scripts/integrand.py11
-rw-r--r--buch/papers/laguerre/scripts/integrand_exp.py12
-rw-r--r--buch/papers/laguerre/scripts/laguerre_poly.py16
-rw-r--r--buch/papers/laguerre/scripts/rel_error_complex.py43
-rw-r--r--buch/papers/laguerre/scripts/rel_error_mirror.py12
-rw-r--r--buch/papers/laguerre/scripts/rel_error_range.py25
-rw-r--r--buch/papers/laguerre/scripts/rel_error_shifted.py13
-rw-r--r--buch/papers/laguerre/scripts/rel_error_simple.py14
-rw-r--r--buch/papers/laguerre/scripts/targets.py26
10 files changed, 158 insertions, 26 deletions
diff --git a/buch/papers/laguerre/scripts/estimates.py b/buch/papers/laguerre/scripts/estimates.py
index 207bbd2..21551f3 100644
--- a/buch/papers/laguerre/scripts/estimates.py
+++ b/buch/papers/laguerre/scripts/estimates.py
@@ -1,10 +1,19 @@
if __name__ == "__main__":
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import gamma_approx as ga
import targets
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
+
N = 200
ns = np.arange(2, 13)
step = 1 / (N - 1)
@@ -32,7 +41,8 @@ if __name__ == "__main__":
for ax in axs:
ax.grid(1)
ax.legend()
- fig.savefig(f"{ga.img_path}/estimates.pgf")
+ # fig.savefig(f"{ga.img_path}/estimates.pgf")
+ fig.savefig(f"{ga.img_path}/estimates.pdf")
print(f"Intercept={intercept:.6g}, Bias={bias:.6g}")
predicts = np.ceil(intercept * ns[:, None] + bias - np.real(x))
diff --git a/buch/papers/laguerre/scripts/integrand.py b/buch/papers/laguerre/scripts/integrand.py
index f31f194..e970721 100644
--- a/buch/papers/laguerre/scripts/integrand.py
+++ b/buch/papers/laguerre/scripts/integrand.py
@@ -6,9 +6,18 @@ if __name__ == "__main__":
import os
from pathlib import Path
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
+
EPSILON = 1e-12
xlims = np.array([-3, 3])
@@ -30,4 +39,4 @@ if __name__ == "__main__":
ax.grid(1, "both")
labels = [f"$z={zi: 3.1f}$" for zi in np.squeeze(z)]
ax.legend(labels, ncol=2, loc="upper left", fontsize="small")
- fig.savefig(f"{img_path}/integrand.pgf")
+ fig.savefig(f"{img_path}/integrand.pdf")
diff --git a/buch/papers/laguerre/scripts/integrand_exp.py b/buch/papers/laguerre/scripts/integrand_exp.py
index 0e50f43..e649b26 100644
--- a/buch/papers/laguerre/scripts/integrand_exp.py
+++ b/buch/papers/laguerre/scripts/integrand_exp.py
@@ -6,8 +6,17 @@ if __name__ == "__main__":
import os
from pathlib import Path
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
+
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
EPSILON = 1e-12
xlims = np.array([-3, 3])
@@ -32,5 +41,6 @@ if __name__ == "__main__":
ax.grid(1, "both")
labels = [f"$z={zi: 3.1f}$" for zi in np.squeeze(z)]
ax.legend(labels, ncol=2, loc="upper left", fontsize="small")
- fig.savefig(f"{img_path}/integrand_exp.pgf")
+ # fig.savefig(f"{img_path}/integrand_exp.pgf")
+ fig.savefig(f"{img_path}/integrand_exp.pdf")
# plt.show()
diff --git a/buch/papers/laguerre/scripts/laguerre_poly.py b/buch/papers/laguerre/scripts/laguerre_poly.py
index 954a0b1..9700ab4 100644
--- a/buch/papers/laguerre/scripts/laguerre_poly.py
+++ b/buch/papers/laguerre/scripts/laguerre_poly.py
@@ -10,8 +10,17 @@ if __name__ == "__main__":
import os
from pathlib import Path
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import scipy.special as ss
+
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
N = 1000
step = 5
@@ -34,8 +43,8 @@ if __name__ == "__main__":
ax.set_xlabel(r"$x$", x=1.0, labelpad=-10, rotation=0, fontsize="large")
ylim = 13
- ax.set_yticks(np.arange(-ylim, ylim), minor=True)
- ax.set_yticks(np.arange(-step * (ylim // step), ylim, step))
+ ax.set_yticks(get_ticks(-ylim, ylim), minor=True)
+ ax.set_yticks(get_ticks(-step * (ylim // step), ylim, step))
ax.set_ylim(-ylim, ylim)
ax.set_ylabel(r"$y$", y=0.95, labelpad=-18, rotation=0, fontsize="large")
@@ -94,5 +103,6 @@ if __name__ == "__main__":
clip_on=False,
)
- fig.savefig(f"{img_path}/laguerre_poly.pgf")
+ # fig.savefig(f"{img_path}/laguerre_poly.pgf")
+ fig.savefig(f"{img_path}/laguerre_poly.pdf")
# plt.show()
diff --git a/buch/papers/laguerre/scripts/rel_error_complex.py b/buch/papers/laguerre/scripts/rel_error_complex.py
new file mode 100644
index 0000000..5be79be
--- /dev/null
+++ b/buch/papers/laguerre/scripts/rel_error_complex.py
@@ -0,0 +1,43 @@
+if __name__ == "__main__":
+ import matplotlib as mpl
+ import matplotlib.pyplot as plt
+ import numpy as np
+ import scipy.special
+
+ import gamma_approx as ga
+
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
+
+ xmax = 4
+ vals = np.linspace(-xmax + ga.EPSILON, xmax, 100)
+ x, y = np.meshgrid(vals, vals)
+ mesh = x + 1j * y
+ input = mesh.flatten()
+
+ lanczos = scipy.special.gamma(mesh)
+ lag = ga.eval_laguerre_gamma(input, n=8, func="optimal_shifted").reshape(mesh.shape)
+ rel_error = np.abs(ga.calc_rel_error(lanczos, lag))
+
+ fig, ax = plt.subplots(clear=True, constrained_layout=True, figsize=(4, 2.4))
+ _c = ax.pcolormesh(
+ x, y, rel_error, shading="gouraud", cmap="inferno", norm=mpl.colors.LogNorm()
+ )
+ cbr = fig.colorbar(_c, ax=ax)
+ cbr.minorticks_off()
+ # ax.set_title("Relative Error")
+ ax.set_xlabel("Re($z$)")
+ ax.set_ylabel("Im($z$)")
+ minor_ticks = np.arange(-xmax, xmax + ga.EPSILON)
+ ticks = np.arange(-xmax, xmax + ga.EPSILON, 2)
+ ax.set_xticks(ticks)
+ ax.set_xticks(minor_ticks, minor=True)
+ ax.set_yticks(ticks)
+ ax.set_yticks(minor_ticks, minor=True)
+ fig.savefig(f"{ga.img_path}/rel_error_complex.pdf")
+ # plt.show()
diff --git a/buch/papers/laguerre/scripts/rel_error_mirror.py b/buch/papers/laguerre/scripts/rel_error_mirror.py
index 05e68e4..7348d5e 100644
--- a/buch/papers/laguerre/scripts/rel_error_mirror.py
+++ b/buch/papers/laguerre/scripts/rel_error_mirror.py
@@ -1,9 +1,18 @@
if __name__ == "__main__":
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.special
import gamma_approx as ga
+
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
xmin = -15
xmax = 15
@@ -25,4 +34,5 @@ if __name__ == "__main__":
# ax.set_ylabel("Relativer Fehler")
ax.legend(ncol=1, loc="upper left", fontsize=ga.fontsize)
ax.grid(1, "both")
- fig.savefig(f"{ga.img_path}/rel_error_mirror.pgf")
+ # fig.savefig(f"{ga.img_path}/rel_error_mirror.pgf")
+ fig.savefig(f"{ga.img_path}/rel_error_mirror.pdf")
diff --git a/buch/papers/laguerre/scripts/rel_error_range.py b/buch/papers/laguerre/scripts/rel_error_range.py
index 7c74d76..43b5450 100644
--- a/buch/papers/laguerre/scripts/rel_error_range.py
+++ b/buch/papers/laguerre/scripts/rel_error_range.py
@@ -1,13 +1,21 @@
if __name__ == "__main__":
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.special
import gamma_approx as ga
-
- N = 1001
- xmin = -5
- xmax = 5
+
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
+ N = 1201
+ xmax = 6
+ xmin = -xmax
ns = np.arange(2, 12, 2)
ylim = np.array([-11, -1.2])
@@ -20,13 +28,14 @@ if __name__ == "__main__":
ax.semilogy(x, np.abs(rel_err), label=f"$n={n}$")
ax.set_xlim(x[0], x[-1])
ax.set_ylim(*(10.0 ** ylim))
- ax.set_xticks(np.arange(xmin + 1, xmax, 2))
- ax.set_xticks(np.arange(xmin, xmax), minor=True)
+ ax.set_xticks(np.arange(xmin, xmax + ga.EPSILON, 2))
+ ax.set_xticks(np.arange(xmin, xmax + ga.EPSILON), minor=True)
ax.set_yticks(10.0 ** np.arange(*ylim, 2))
- ax.set_yticks(10.0 ** np.arange(*ylim, 1), minor=True)
+ ax.set_yticks(10.0 ** np.arange(*ylim, 1), "", minor=True)
ax.set_xlabel(r"$z$")
# ax.set_ylabel("Relativer Fehler")
ax.legend(ncol=1, loc="upper left", fontsize=ga.fontsize)
ax.grid(1, "both")
- fig.savefig(f"{ga.img_path}/rel_error_range.pgf")
+ # fig.savefig(f"{ga.img_path}/rel_error_range.pgf")
+ fig.savefig(f"{ga.img_path}/rel_error_range.pdf")
# plt.show()
diff --git a/buch/papers/laguerre/scripts/rel_error_shifted.py b/buch/papers/laguerre/scripts/rel_error_shifted.py
index 1515c6e..dc9d177 100644
--- a/buch/papers/laguerre/scripts/rel_error_shifted.py
+++ b/buch/papers/laguerre/scripts/rel_error_shifted.py
@@ -1,10 +1,18 @@
if __name__ == "__main__":
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.special
import gamma_approx as ga
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
n = 8 # order of Laguerre polynomial
N = 200 # number of points in interval
@@ -19,7 +27,7 @@ if __name__ == "__main__":
ax.semilogy(x, rel_error, label=f"$m={target}$", linewidth=3)
gamma_lgo = ga.eval_laguerre_gamma(x, n=n, func="optimal_shifted")
rel_error = np.abs(ga.calc_rel_error(gamma, gamma_lgo))
- ax.semilogy(x, rel_error, "m", linestyle="dotted", label="$m^*$", linewidth=3)
+ ax.semilogy(x, rel_error, "m", linestyle=":", label="$m^*$", linewidth=3)
ax.set_xlim(x[0], x[-1])
ax.set_ylim(5e-9, 5e-8)
ax.set_xlabel(r"$z$")
@@ -27,5 +35,6 @@ if __name__ == "__main__":
ax.set_xticks(np.linspace(0, 1, 11), minor=True)
ax.grid(1, "both")
ax.legend(ncol=1, fontsize=ga.fontsize)
- fig.savefig(f"{ga.img_path}/rel_error_shifted.pgf")
+ # fig.savefig(f"{ga.img_path}/rel_error_shifted.pgf")
+ fig.savefig(f"{ga.img_path}/rel_error_shifted.pdf")
# plt.show()
diff --git a/buch/papers/laguerre/scripts/rel_error_simple.py b/buch/papers/laguerre/scripts/rel_error_simple.py
index 0929976..686500b 100644
--- a/buch/papers/laguerre/scripts/rel_error_simple.py
+++ b/buch/papers/laguerre/scripts/rel_error_simple.py
@@ -1,10 +1,21 @@
if __name__ == "__main__":
+ import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.special
import gamma_approx as ga
+ # mpl.rc("text", usetex=True)
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
+ # mpl.rcParams.update({"font.family": "serif", "font.serif": "TeX Gyre Termes"})
+
# Simple / naive
xmin = -5
xmax = 30
@@ -26,4 +37,5 @@ if __name__ == "__main__":
# ax.set_ylabel("Relativer Fehler")
ax.legend(ncol=3, fontsize=ga.fontsize)
ax.grid(1, "both")
- fig.savefig(f"{ga.img_path}/rel_error_simple.pgf")
+ # fig.savefig(f"{ga.img_path}/rel_error_simple.pgf")
+ fig.savefig(f"{ga.img_path}/rel_error_simple.pdf")
diff --git a/buch/papers/laguerre/scripts/targets.py b/buch/papers/laguerre/scripts/targets.py
index 73d6e03..206b3a1 100644
--- a/buch/papers/laguerre/scripts/targets.py
+++ b/buch/papers/laguerre/scripts/targets.py
@@ -10,24 +10,33 @@ def find_best_loc(N=200, a=1.375, b=0.5, ns=None):
bests = []
step = 1 / (N - 1)
x = np.linspace(step, 1 - step, N + 1)
- gamma = scipy.special.gamma(x)[:, None]
+ gamma = scipy.special.gamma(x)
for n in ns:
zeros, weights = np.polynomial.laguerre.laggauss(n)
est = np.ceil(b + a * n)
targets = np.arange(max(est - 2, 0), est + 3)
- glag = [
- ga.eval_laguerre_gamma(x, target=target, x=zeros, w=weights, func="shifted")
- for target in targets
- ]
- gamma_lag = np.stack(glag, -1)
- rel_error = np.abs(ga.calc_rel_error(gamma, gamma_lag))
+ rel_error = []
+ for target in targets:
+ gamma_lag = ga.eval_laguerre_gamma(x, target=target, x=zeros, w=weights, func="shifted")
+ rel_error.append(np.abs(ga.calc_rel_error(gamma, gamma_lag)))
+ rel_error = np.stack(rel_error, -1)
best = np.argmin(rel_error, -1) + targets[0]
bests.append(best)
return np.stack(bests, 0)
if __name__ == "__main__":
+ import matplotlib as mpl
import matplotlib.pyplot as plt
+
+ mpl.rcParams.update(
+ {
+ "mathtext.fontset": "stix",
+ "font.family": "serif",
+ "font.serif": "TeX Gyre Termes",
+ }
+ )
+
N = 200
ns = np.arange(2, 13)
@@ -45,4 +54,5 @@ if __name__ == "__main__":
ax.set_yticklabels(ns)
ax.set_xlabel(r"$z$")
ax.set_ylabel(r"$n$")
- fig.savefig(f"{ga.img_path}/targets.pgf")
+ # fig.savefig(f"{ga.img_path}/targets.pgf")
+ fig.savefig(f"{ga.img_path}/targets.pdf")