Skip to content

new variant of second derivative, bigger stencil #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions pyerrors/correlators.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,21 @@ def deriv(self, variant="symmetric"):
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.")
Expand All @@ -597,6 +605,16 @@ def second_deriv(self, variant="symmetric"):
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):
Expand Down