From 94b0322f0be2f7b3cc2a1f6a77075834660f7283 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann <82444481+jkuhl-uni@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:32:27 +0200 Subject: [PATCH] new variant of second derivative, bigger stencil (#197) * new variant of second derivative, bigger stencil * better docstring dor second_deriv * forgot to "r" in front of docstring * flake8 compliance --- pyerrors/correlators.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index 266ed428..8573cdbf 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -577,13 +577,21 @@ class Corr: raise Exception("Unknown variant.") def second_deriv(self, variant="symmetric"): - """Return the second derivative of the correlator with respect to x0. + r"""Return the second derivative of the correlator with respect to x0. Parameters ---------- variant : str decides which definition of the finite differences derivative is used. - Available choice: symmetric, improved, log, default: symmetric + Available choice: + - symmetric (default) + $$\tilde{\partial}^2_0 f(x_0) = f(x_0+1)-2f(x_0)+f(x_0-1)$$ + - big_symmetric + $$\partial^2_0 f(x_0) = \frac{f(x_0+2)-2f(x_0)+f(x_0-2)}{4}$$ + - improved + $$\partial^2_0 f(x_0) = \frac{-f(x_0+2) + 16 * f(x_0+1) - 30 * f(x_0) + 16 * f(x_0-1) - f(x_0-2)}{12}$$ + - log + $$f(x) = \tilde{\partial}^2_0 log(f(x_0))+(\tilde{\partial}_0 log(f(x_0)))^2$$ """ if self.N != 1: raise Exception("second_deriv only implemented for one-dimensional correlators.") @@ -597,6 +605,16 @@ class Corr: if (all([x is None for x in newcontent])): raise Exception("Derivative is undefined at all timeslices") return Corr(newcontent, padding=[1, 1]) + elif variant == "big_symmetric": + newcontent = [] + for t in range(2, self.T - 2): + if (self.content[t - 2] is None) or (self.content[t + 2] is None): + newcontent.append(None) + else: + newcontent.append((self.content[t + 2] - 2 * self.content[t] + self.content[t - 2]) / 4) + if (all([x is None for x in newcontent])): + raise Exception("Derivative is undefined at all timeslices") + return Corr(newcontent, padding=[2, 2]) elif variant == "improved": newcontent = [] for t in range(2, self.T - 2):