mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 03:53:41 +02:00
feat: Obs.details does not output zero error anymore in case the
gamma_method had not been applied. Obs.plot* function now correctly throw an exception in case the gamma_method had not been run. docs adjusted accordingly.
This commit is contained in:
parent
04a66439c2
commit
e62a957d3c
2 changed files with 27 additions and 12 deletions
|
@ -125,7 +125,7 @@ obs2 = pe.Obs([samples2], ['ensemble2'])
|
||||||
|
|
||||||
my_sum = obs1 + obs2
|
my_sum = obs1 + obs2
|
||||||
my_sum.details()
|
my_sum.details()
|
||||||
> Result 2.00697958e+00 +/- 0.00000000e+00 +/- 0.00000000e+00 (0.000%)
|
> Result 2.00697958e+00
|
||||||
> 1500 samples in 2 ensembles:
|
> 1500 samples in 2 ensembles:
|
||||||
> · Ensemble 'ensemble1' : 1000 configurations (from 1 to 1000)
|
> · Ensemble 'ensemble1' : 1000 configurations (from 1 to 1000)
|
||||||
> · Ensemble 'ensemble2' : 500 configurations (from 1 to 500)
|
> · Ensemble 'ensemble2' : 500 configurations (from 1 to 500)
|
||||||
|
@ -140,7 +140,7 @@ obs2 = pe.Obs([samples2], ['ensemble1|r02'])
|
||||||
|
|
||||||
> my_sum = obs1 + obs2
|
> my_sum = obs1 + obs2
|
||||||
> my_sum.details()
|
> my_sum.details()
|
||||||
> Result 2.00697958e+00 +/- 0.00000000e+00 +/- 0.00000000e+00 (0.000%)
|
> Result 2.00697958e+00
|
||||||
> 1500 samples in 1 ensemble:
|
> 1500 samples in 1 ensemble:
|
||||||
> · Ensemble 'ensemble1'
|
> · Ensemble 'ensemble1'
|
||||||
> · Replicum 'r01' : 1000 configurations (from 1 to 1000)
|
> · Replicum 'r01' : 1000 configurations (from 1 to 1000)
|
||||||
|
@ -170,12 +170,25 @@ Example:
|
||||||
```python
|
```python
|
||||||
# Observable defined on configurations 20 to 519
|
# Observable defined on configurations 20 to 519
|
||||||
obs1 = pe.Obs([samples1], ['ensemble1'], idl=[range(20, 520)])
|
obs1 = pe.Obs([samples1], ['ensemble1'], idl=[range(20, 520)])
|
||||||
|
obs1.details()
|
||||||
|
> Result 9.98319881e-01
|
||||||
|
> 500 samples in 1 ensemble:
|
||||||
|
> · Ensemble 'ensemble1' : 500 configurations (from 20 to 519)
|
||||||
|
|
||||||
# Observable defined on every second configuration between 5 and 1003
|
# Observable defined on every second configuration between 5 and 1003
|
||||||
obs2 = pe.Obs([samples2], ['ensemble1'], idl=[range(5, 1005, 2)])
|
obs2 = pe.Obs([samples2], ['ensemble1'], idl=[range(5, 1005, 2)])
|
||||||
|
obs2.details()
|
||||||
|
> Result 9.99100712e-01
|
||||||
|
> 500 samples in 1 ensemble:
|
||||||
|
> · Ensemble 'ensemble1' : 500 configurations (from 5 to 1003 in steps of 2)
|
||||||
|
|
||||||
# Observable defined on configurations 2, 9, 28, 29 and 501
|
# Observable defined on configurations 2, 9, 28, 29 and 501
|
||||||
obs3 = pe.Obs([samples3], ['ensemble1'], idl=[[2, 9, 28, 29, 501]])
|
obs3 = pe.Obs([samples3], ['ensemble1'], idl=[[2, 9, 28, 29, 501]])
|
||||||
|
obs3.details()
|
||||||
|
> Result 1.01718064e+00
|
||||||
|
> 5 samples in 1 ensemble:
|
||||||
|
> · Ensemble 'ensemble1' : 5 configurations (irregular range)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Warning:** Irregular Monte Carlo chains can result in odd patterns in the autocorrelation functions.
|
**Warning:** Irregular Monte Carlo chains can result in odd patterns in the autocorrelation functions.
|
||||||
|
|
|
@ -348,12 +348,14 @@ class Obs:
|
||||||
"""
|
"""
|
||||||
if self.tag is not None:
|
if self.tag is not None:
|
||||||
print("Description:", self.tag)
|
print("Description:", self.tag)
|
||||||
|
if not hasattr(self, 'e_dvalue'):
|
||||||
|
print('Result\t %3.8e' % (self.value))
|
||||||
|
else:
|
||||||
if self.value == 0.0:
|
if self.value == 0.0:
|
||||||
percentage = np.nan
|
percentage = np.nan
|
||||||
else:
|
else:
|
||||||
percentage = np.abs(self.dvalue / self.value) * 100
|
percentage = np.abs(self.dvalue / self.value) * 100
|
||||||
print('Result\t %3.8e +/- %3.8e +/- %3.8e (%3.3f%%)' % (self.value, self.dvalue, self.ddvalue, percentage))
|
print('Result\t %3.8e +/- %3.8e +/- %3.8e (%3.3f%%)' % (self.value, self.dvalue, self.ddvalue, percentage))
|
||||||
if hasattr(self, 'e_dvalue'):
|
|
||||||
if len(self.e_names) > 1:
|
if len(self.e_names) > 1:
|
||||||
print(' Ensemble errors:')
|
print(' Ensemble errors:')
|
||||||
for e_name in self.e_names:
|
for e_name in self.e_names:
|
||||||
|
@ -420,7 +422,7 @@ class Obs:
|
||||||
save : str
|
save : str
|
||||||
saves the figure to a file named 'save' if.
|
saves the figure to a file named 'save' if.
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, 'e_names'):
|
if not hasattr(self, 'e_dvalue'):
|
||||||
raise Exception('Run the gamma method first.')
|
raise Exception('Run the gamma method first.')
|
||||||
|
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
|
@ -453,7 +455,7 @@ class Obs:
|
||||||
|
|
||||||
def plot_rho(self):
|
def plot_rho(self):
|
||||||
"""Plot normalized autocorrelation function time for each ensemble."""
|
"""Plot normalized autocorrelation function time for each ensemble."""
|
||||||
if not hasattr(self, 'e_names'):
|
if not hasattr(self, 'e_dvalue'):
|
||||||
raise Exception('Run the gamma method first.')
|
raise Exception('Run the gamma method first.')
|
||||||
for e, e_name in enumerate(self.e_names):
|
for e, e_name in enumerate(self.e_names):
|
||||||
plt.xlabel('W')
|
plt.xlabel('W')
|
||||||
|
@ -475,7 +477,7 @@ class Obs:
|
||||||
|
|
||||||
def plot_rep_dist(self):
|
def plot_rep_dist(self):
|
||||||
"""Plot replica distribution for each ensemble with more than one replicum."""
|
"""Plot replica distribution for each ensemble with more than one replicum."""
|
||||||
if not hasattr(self, 'e_names'):
|
if not hasattr(self, 'e_dvalue'):
|
||||||
raise Exception('Run the gamma method first.')
|
raise Exception('Run the gamma method first.')
|
||||||
for e, e_name in enumerate(self.e_names):
|
for e, e_name in enumerate(self.e_names):
|
||||||
if len(self.e_content[e_name]) == 1:
|
if len(self.e_content[e_name]) == 1:
|
||||||
|
@ -503,7 +505,7 @@ class Obs:
|
||||||
expand : bool
|
expand : bool
|
||||||
show expanded history for irregular Monte Carlo chains (default: True).
|
show expanded history for irregular Monte Carlo chains (default: True).
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, 'e_names'):
|
if not hasattr(self, 'e_dvalue'):
|
||||||
raise Exception('Run the gamma method first.')
|
raise Exception('Run the gamma method first.')
|
||||||
|
|
||||||
for e, e_name in enumerate(self.e_names):
|
for e, e_name in enumerate(self.e_names):
|
||||||
|
@ -527,7 +529,7 @@ class Obs:
|
||||||
def plot_piechart(self):
|
def plot_piechart(self):
|
||||||
"""Plot piechart which shows the fractional contribution of each
|
"""Plot piechart which shows the fractional contribution of each
|
||||||
ensemble to the error and returns a dictionary containing the fractions."""
|
ensemble to the error and returns a dictionary containing the fractions."""
|
||||||
if not hasattr(self, 'e_names'):
|
if not hasattr(self, 'e_dvalue'):
|
||||||
raise Exception('Run the gamma method first.')
|
raise Exception('Run the gamma method first.')
|
||||||
if self.dvalue == 0.0:
|
if self.dvalue == 0.0:
|
||||||
raise Exception('Error is 0.0')
|
raise Exception('Error is 0.0')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue