mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
feat!: merged the parameters padding_front and padding_back of Corr into
one parameter padding
This commit is contained in:
parent
56fe126593
commit
d778a3b238
6 changed files with 16 additions and 16 deletions
File diff suppressed because one or more lines are too long
|
@ -206,7 +206,7 @@ print(my_corr)
|
||||||
```
|
```
|
||||||
In case the correlation functions are not defined on the outermost timeslices, for example because of fixed boundary conditions, a padding can be introduced.
|
In case the correlation functions are not defined on the outermost timeslices, for example because of fixed boundary conditions, a padding can be introduced.
|
||||||
```python
|
```python
|
||||||
my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3], padding_front=1, padding_back=1)
|
my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3], padding=[1, 1])
|
||||||
print(my_corr)
|
print(my_corr)
|
||||||
> x0/a Corr(x0/a)
|
> x0/a Corr(x0/a)
|
||||||
> ------------------
|
> ------------------
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Corr:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, data_input, padding_front=0, padding_back=0, prange=None):
|
def __init__(self, data_input, padding=[0, 0], prange=None):
|
||||||
# All data_input should be a list of things at different timeslices. This needs to be verified
|
# All data_input should be a list of things at different timeslices. This needs to be verified
|
||||||
|
|
||||||
if not isinstance(data_input, list):
|
if not isinstance(data_input, list):
|
||||||
|
@ -53,7 +53,7 @@ class Corr:
|
||||||
|
|
||||||
# We now apply some padding to our list. In case that our list represents a correlator of length T but is not defined at every value.
|
# We now apply some padding to our list. In case that our list represents a correlator of length T but is not defined at every value.
|
||||||
# An undefined timeslice is represented by the None object
|
# An undefined timeslice is represented by the None object
|
||||||
self.content = [None] * padding_front + self.content + [None] * padding_back
|
self.content = [None] * padding[0] + self.content + [None] * padding[1]
|
||||||
self.T = len(self.content) # for convenience: will be used a lot
|
self.T = len(self.content) # for convenience: will be used a lot
|
||||||
|
|
||||||
# The attribute "range" [start,end] marks a range of two timeslices.
|
# The attribute "range" [start,end] marks a range of two timeslices.
|
||||||
|
@ -331,7 +331,7 @@ class Corr:
|
||||||
newcontent.append(self.content[t + 1] - self.content[t])
|
newcontent.append(self.content[t + 1] - self.content[t])
|
||||||
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_back=1)
|
return Corr(newcontent, padding=[0, 1])
|
||||||
if symmetric:
|
if symmetric:
|
||||||
newcontent = []
|
newcontent = []
|
||||||
for t in range(1, self.T - 1):
|
for t in range(1, self.T - 1):
|
||||||
|
@ -341,7 +341,7 @@ class Corr:
|
||||||
newcontent.append(0.5 * (self.content[t + 1] - self.content[t - 1]))
|
newcontent.append(0.5 * (self.content[t + 1] - self.content[t - 1]))
|
||||||
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_back=1, padding_front=1)
|
return Corr(newcontent, padding=[1, 1])
|
||||||
|
|
||||||
def second_deriv(self):
|
def second_deriv(self):
|
||||||
"""Return the second derivative of the correlator with respect to x0."""
|
"""Return the second derivative of the correlator with respect to x0."""
|
||||||
|
@ -353,7 +353,7 @@ class Corr:
|
||||||
newcontent.append((self.content[t + 1] - 2 * self.content[t] + self.content[t - 1]))
|
newcontent.append((self.content[t + 1] - 2 * self.content[t] + self.content[t - 1]))
|
||||||
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_back=1, padding_front=1)
|
return Corr(newcontent, padding=[1, 1])
|
||||||
|
|
||||||
def m_eff(self, variant='log', guess=1.0):
|
def m_eff(self, variant='log', guess=1.0):
|
||||||
"""Returns the effective mass of the correlator as correlator object
|
"""Returns the effective mass of the correlator as correlator object
|
||||||
|
@ -381,7 +381,7 @@ class Corr:
|
||||||
if(all([x is None for x in newcontent])):
|
if(all([x is None for x in newcontent])):
|
||||||
raise Exception('m_eff is undefined at all timeslices')
|
raise Exception('m_eff is undefined at all timeslices')
|
||||||
|
|
||||||
return np.log(Corr(newcontent, padding_back=1))
|
return np.log(Corr(newcontent, padding=[0, 1]))
|
||||||
|
|
||||||
elif variant in ['periodic', 'cosh', 'sinh']:
|
elif variant in ['periodic', 'cosh', 'sinh']:
|
||||||
if variant in ['periodic', 'cosh']:
|
if variant in ['periodic', 'cosh']:
|
||||||
|
@ -404,7 +404,7 @@ class Corr:
|
||||||
if(all([x is None for x in newcontent])):
|
if(all([x is None for x in newcontent])):
|
||||||
raise Exception('m_eff is undefined at all timeslices')
|
raise Exception('m_eff is undefined at all timeslices')
|
||||||
|
|
||||||
return Corr(newcontent, padding_back=1)
|
return Corr(newcontent, padding=[0, 1])
|
||||||
|
|
||||||
elif variant == 'arccosh':
|
elif variant == 'arccosh':
|
||||||
newcontent = []
|
newcontent = []
|
||||||
|
@ -415,7 +415,7 @@ class Corr:
|
||||||
newcontent.append((self.content[t + 1] + self.content[t - 1]) / (2 * self.content[t]))
|
newcontent.append((self.content[t + 1] + self.content[t - 1]) / (2 * self.content[t]))
|
||||||
if(all([x is None for x in newcontent])):
|
if(all([x is None for x in newcontent])):
|
||||||
raise Exception("m_eff is undefined at all timeslices")
|
raise Exception("m_eff is undefined at all timeslices")
|
||||||
return np.arccosh(Corr(newcontent, padding_back=1, padding_front=1))
|
return np.arccosh(Corr(newcontent, padding=[1, 1]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('Unknown variant.')
|
raise Exception('Unknown variant.')
|
||||||
|
|
|
@ -402,7 +402,7 @@ def import_json_string(json_string, verbose=True, full_output=False):
|
||||||
if len(tmp_o['tag']) == 0:
|
if len(tmp_o['tag']) == 0:
|
||||||
del tmp_o['tag']
|
del tmp_o['tag']
|
||||||
dat = get_Array_from_dict(tmp_o)
|
dat = get_Array_from_dict(tmp_o)
|
||||||
my_corr = Corr(list(dat), padding_front=padding_front, padding_back=padding_back)
|
my_corr = Corr(list(dat), padding=[padding_front, padding_back])
|
||||||
if corr_tag != 'None':
|
if corr_tag != 'None':
|
||||||
my_corr.tag = corr_tag
|
my_corr.tag = corr_tag
|
||||||
return my_corr
|
return my_corr
|
||||||
|
|
|
@ -115,7 +115,7 @@ def test_plateau():
|
||||||
|
|
||||||
def test_padded_correlator():
|
def test_padded_correlator():
|
||||||
my_list = [pe.Obs([np.random.normal(1.0, 0.1, 100)], ['ens1']) for o in range(8)]
|
my_list = [pe.Obs([np.random.normal(1.0, 0.1, 100)], ['ens1']) for o in range(8)]
|
||||||
my_corr = pe.Corr(my_list, padding_front=7, padding_back=3)
|
my_corr = pe.Corr(my_list, padding=[7, 3])
|
||||||
my_corr.reweighted
|
my_corr.reweighted
|
||||||
[o for o in my_corr]
|
[o for o in my_corr]
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ def test_json_corr_io():
|
||||||
for fp in [0, 2]:
|
for fp in [0, 2]:
|
||||||
for bp in [0, 7]:
|
for bp in [0, 7]:
|
||||||
for corr_tag in [None, 'my_Corr_tag']:
|
for corr_tag in [None, 'my_Corr_tag']:
|
||||||
my_corr = pe.Corr(obs_list, padding_front=fp, padding_back=bp)
|
my_corr = pe.Corr(obs_list, padding=[fp, bp])
|
||||||
my_corr.tag = corr_tag
|
my_corr.tag = corr_tag
|
||||||
pe.input.json.dump_to_json(my_corr, 'corr')
|
pe.input.json.dump_to_json(my_corr, 'corr')
|
||||||
recover = pe.input.json.load_json('corr')
|
recover = pe.input.json.load_json('corr')
|
||||||
|
@ -116,7 +116,7 @@ def test_json_corr_2d_io():
|
||||||
for tag in [None, "test"]:
|
for tag in [None, "test"]:
|
||||||
obs_list[3][0, 1].tag = tag
|
obs_list[3][0, 1].tag = tag
|
||||||
for padding in [0, 1]:
|
for padding in [0, 1]:
|
||||||
my_corr = pe.Corr(obs_list, padding_front=padding, padding_back=padding)
|
my_corr = pe.Corr(obs_list, padding=[padding, padding])
|
||||||
my_corr.tag = tag
|
my_corr.tag = tag
|
||||||
pe.input.json.dump_to_json(my_corr, 'corr')
|
pe.input.json.dump_to_json(my_corr, 'corr')
|
||||||
recover = pe.input.json.load_json('corr')
|
recover = pe.input.json.load_json('corr')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue