mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
feat: backward derivative implemented, additional tests for deriv
This commit is contained in:
parent
8165479846
commit
a729def937
2 changed files with 25 additions and 1 deletions
|
@ -467,7 +467,7 @@ class Corr:
|
||||||
----------
|
----------
|
||||||
variant : str
|
variant : str
|
||||||
decides which definition of the finite differences derivative is used.
|
decides which definition of the finite differences derivative is used.
|
||||||
Available choice: symmetric, forward, improved, default: symmetric
|
Available choice: symmetric, forward, backward, improved, default: symmetric
|
||||||
"""
|
"""
|
||||||
if variant == "symmetric":
|
if variant == "symmetric":
|
||||||
newcontent = []
|
newcontent = []
|
||||||
|
@ -489,6 +489,16 @@ class Corr:
|
||||||
if(all([x is None for x in newcontent])):
|
if(all([x is None for x in newcontent])):
|
||||||
raise Exception("Derivative is undefined at all timeslices")
|
raise Exception("Derivative is undefined at all timeslices")
|
||||||
return Corr(newcontent, padding=[0, 1])
|
return Corr(newcontent, padding=[0, 1])
|
||||||
|
elif variant == "backward":
|
||||||
|
newcontent = []
|
||||||
|
for t in range(1, self.T):
|
||||||
|
if (self.content[t - 1] is None) or (self.content[t] is None):
|
||||||
|
newcontent.append(None)
|
||||||
|
else:
|
||||||
|
newcontent.append(self.content[t] - self.content[t - 1])
|
||||||
|
if(all([x is None for x in newcontent])):
|
||||||
|
raise Exception("Derivative is undefined at all timeslices")
|
||||||
|
return Corr(newcontent, padding=[1, 0])
|
||||||
elif variant == "improved":
|
elif variant == "improved":
|
||||||
newcontent = []
|
newcontent = []
|
||||||
for t in range(2, self.T - 2):
|
for t in range(2, self.T - 2):
|
||||||
|
|
|
@ -72,6 +72,20 @@ def test_modify_correlator():
|
||||||
func(corr, variant=variant)
|
func(corr, variant=variant)
|
||||||
|
|
||||||
|
|
||||||
|
def test_deriv():
|
||||||
|
corr_content = []
|
||||||
|
for t in range(24):
|
||||||
|
exponent = 1.2
|
||||||
|
corr_content.append(pe.pseudo_Obs(2 + t ** exponent, 0.2, 't'))
|
||||||
|
|
||||||
|
corr = pe.Corr(corr_content)
|
||||||
|
|
||||||
|
forward = corr.deriv(variant="forward")
|
||||||
|
backward = corr.deriv(variant="backward")
|
||||||
|
sym = corr.deriv(variant="symmetric")
|
||||||
|
assert np.all([o == 0 for o in (0.5 * (forward + backward) - sym)[1:-1]])
|
||||||
|
assert np.all([o == 0 for o in (corr.deriv('forward').deriv('backward') - corr.second_deriv())[1:-1]])
|
||||||
|
assert np.all([o == 0 for o in (corr.deriv('backward').deriv('forward') - corr.second_deriv())[1:-1]])
|
||||||
|
|
||||||
|
|
||||||
def test_m_eff():
|
def test_m_eff():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue