pyerrors 2.14.0__tar.gz → 2.15.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {pyerrors-2.14.0 → pyerrors-2.15.0}/PKG-INFO +3 -3
  2. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/fits.py +67 -36
  3. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/json.py +0 -5
  4. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/pandas.py +5 -6
  5. pyerrors-2.15.0/pyerrors/version.py +1 -0
  6. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors.egg-info/PKG-INFO +3 -3
  7. {pyerrors-2.14.0 → pyerrors-2.15.0}/setup.py +0 -1
  8. pyerrors-2.14.0/pyerrors/version.py +0 -1
  9. {pyerrors-2.14.0 → pyerrors-2.15.0}/LICENSE +0 -0
  10. {pyerrors-2.14.0 → pyerrors-2.15.0}/README.md +0 -0
  11. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/__init__.py +0 -0
  12. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/correlators.py +0 -0
  13. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/covobs.py +0 -0
  14. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/dirac.py +0 -0
  15. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/__init__.py +0 -0
  16. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/bdio.py +0 -0
  17. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/dobs.py +0 -0
  18. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/hadrons.py +0 -0
  19. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/misc.py +0 -0
  20. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/openQCD.py +0 -0
  21. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/sfcf.py +0 -0
  22. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/input/utils.py +0 -0
  23. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/integrate.py +0 -0
  24. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/linalg.py +0 -0
  25. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/misc.py +0 -0
  26. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/mpm.py +0 -0
  27. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/obs.py +0 -0
  28. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/roots.py +0 -0
  29. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors/special.py +0 -0
  30. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors.egg-info/SOURCES.txt +0 -0
  31. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors.egg-info/dependency_links.txt +0 -0
  32. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors.egg-info/requires.txt +0 -0
  33. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyerrors.egg-info/top_level.txt +0 -0
  34. {pyerrors-2.14.0 → pyerrors-2.15.0}/pyproject.toml +0 -0
  35. {pyerrors-2.14.0 → pyerrors-2.15.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pyerrors
3
- Version: 2.14.0
3
+ Version: 2.15.0
4
4
  Summary: Error propagation and statistical analysis for Monte Carlo simulations
5
5
  Home-page: https://github.com/fjosw/pyerrors
6
6
  Author: Fabian Joswig
@@ -11,7 +11,6 @@ Project-URL: Bug Tracker, https://github.com/fjosw/pyerrors/issues
11
11
  Project-URL: Changelog, https://github.com/fjosw/pyerrors/blob/master/CHANGELOG.md
12
12
  Classifier: Development Status :: 5 - Production/Stable
13
13
  Classifier: Intended Audience :: Science/Research
14
- Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Programming Language :: Python :: 3
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
@@ -46,6 +45,7 @@ Dynamic: description
46
45
  Dynamic: description-content-type
47
46
  Dynamic: home-page
48
47
  Dynamic: license
48
+ Dynamic: license-file
49
49
  Dynamic: project-url
50
50
  Dynamic: provides-extra
51
51
  Dynamic: requires-dist
@@ -131,7 +131,7 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
131
131
  Obs (e.g. results from a previous fit) or strings containing a value and an error formatted like
132
132
  0.548(23), 500(40) or 0.5(0.4)
133
133
  silent : bool, optional
134
- If true all output to the console is omitted (default False).
134
+ If True all output to the console is omitted (default False).
135
135
  initial_guess : list
136
136
  can provide an initial guess for the input parameters. Relevant for
137
137
  non-linear fits with many parameters. In case of correlated fits the guess is used to perform
@@ -139,10 +139,10 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
139
139
  method : str, optional
140
140
  can be used to choose an alternative method for the minimization of chisquare.
141
141
  The possible methods are the ones which can be used for scipy.optimize.minimize and
142
- migrad of iminuit. If no method is specified, Levenberg-Marquard is used.
142
+ migrad of iminuit. If no method is specified, Levenberg–Marquardt is used.
143
143
  Reliable alternatives are migrad, Powell and Nelder-Mead.
144
144
  tol: float, optional
145
- can be used (only for combined fits and methods other than Levenberg-Marquard) to set the tolerance for convergence
145
+ can be used (only for combined fits and methods other than Levenberg–Marquardt) to set the tolerance for convergence
146
146
  to a different value to either speed up convergence at the cost of a larger error on the fitted parameters (and possibly
147
147
  invalid estimates for parameter uncertainties) or smaller values to get more accurate parameter values
148
148
  The stopping criterion depends on the method, e.g. migrad: edm_max = 0.002 * tol * errordef (EDM criterion: edm < edm_max)
@@ -152,7 +152,7 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
152
152
  In practice the correlation matrix is Cholesky decomposed and inverted (instead of the covariance matrix).
153
153
  This procedure should be numerically more stable as the correlation matrix is typically better conditioned (Jacobi preconditioning).
154
154
  inv_chol_cov_matrix [array,list], optional
155
- array: shape = (no of y values) X (no of y values)
155
+ array: shape = (number of y values) X (number of y values)
156
156
  list: for an uncombined fit: [""]
157
157
  for a combined fit: list of keys belonging to the corr_matrix saved in the array, must be the same as the keys of the y dict in alphabetical order
158
158
  If correlated_fit=True is set as well, can provide an inverse covariance matrix (y errors, dy_f included!) of your own choosing for a correlated fit.
@@ -168,6 +168,9 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
168
168
  If True, a quantile-quantile plot of the fit result is generated (default False).
169
169
  num_grad : bool
170
170
  Use numerical differentation instead of automatic differentiation to perform the error propagation (default False).
171
+ n_parms : int, optional
172
+ Number of fit parameters. Overrides automatic detection of parameter count.
173
+ Useful when autodetection fails. Must match the length of initial_guess or priors (if provided).
171
174
 
172
175
  Returns
173
176
  -------
@@ -269,26 +272,38 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
269
272
  raise Exception("No y errors available, run the gamma method first.")
270
273
 
271
274
  # number of fit parameters
272
- n_parms_ls = []
273
- for key in key_ls:
274
- if not callable(funcd[key]):
275
- raise TypeError('func (key=' + key + ') is not a function.')
276
- if np.asarray(xd[key]).shape[-1] != len(yd[key]):
277
- raise ValueError('x and y input (key=' + key + ') do not have the same length')
278
- for n_loc in range(100):
279
- try:
280
- funcd[key](np.arange(n_loc), x_all.T[0])
281
- except TypeError:
282
- continue
283
- except IndexError:
284
- continue
275
+ if 'n_parms' in kwargs:
276
+ n_parms = kwargs.get('n_parms')
277
+ if not isinstance(n_parms, int):
278
+ raise TypeError(
279
+ f"'n_parms' must be an integer, got {n_parms!r} "
280
+ f"of type {type(n_parms).__name__}."
281
+ )
282
+ if n_parms <= 0:
283
+ raise ValueError(
284
+ f"'n_parms' must be a positive integer, got {n_parms}."
285
+ )
286
+ else:
287
+ n_parms_ls = []
288
+ for key in key_ls:
289
+ if not callable(funcd[key]):
290
+ raise TypeError('func (key=' + key + ') is not a function.')
291
+ if np.asarray(xd[key]).shape[-1] != len(yd[key]):
292
+ raise ValueError('x and y input (key=' + key + ') do not have the same length')
293
+ for n_loc in range(100):
294
+ try:
295
+ funcd[key](np.arange(n_loc), x_all.T[0])
296
+ except TypeError:
297
+ continue
298
+ except IndexError:
299
+ continue
300
+ else:
301
+ break
285
302
  else:
286
- break
287
- else:
288
- raise RuntimeError("Fit function (key=" + key + ") is not valid.")
289
- n_parms_ls.append(n_loc)
303
+ raise RuntimeError("Fit function (key=" + key + ") is not valid.")
304
+ n_parms_ls.append(n_loc)
290
305
 
291
- n_parms = max(n_parms_ls)
306
+ n_parms = max(n_parms_ls)
292
307
 
293
308
  if len(key_ls) > 1:
294
309
  for key in key_ls:
@@ -535,17 +550,20 @@ def total_least_squares(x, y, func, silent=False, **kwargs):
535
550
  It is important that all numpy functions refer to autograd.numpy, otherwise the differentiation
536
551
  will not work.
537
552
  silent : bool, optional
538
- If true all output to the console is omitted (default False).
553
+ If True all output to the console is omitted (default False).
539
554
  initial_guess : list
540
555
  can provide an initial guess for the input parameters. Relevant for non-linear
541
556
  fits with many parameters.
542
557
  expected_chisquare : bool
543
- If true prints the expected chisquare which is
558
+ If True prints the expected chisquare which is
544
559
  corrected by effects caused by correlated input data.
545
560
  This can take a while as the full correlation matrix
546
561
  has to be calculated (default False).
547
562
  num_grad : bool
548
- Use numerical differentation instead of automatic differentiation to perform the error propagation (default False).
563
+ Use numerical differentiation instead of automatic differentiation to perform the error propagation (default False).
564
+ n_parms : int, optional
565
+ Number of fit parameters. Overrides automatic detection of parameter count.
566
+ Useful when autodetection fails. Must match the length of initial_guess (if provided).
549
567
 
550
568
  Notes
551
569
  -----
@@ -575,19 +593,32 @@ def total_least_squares(x, y, func, silent=False, **kwargs):
575
593
  if not callable(func):
576
594
  raise TypeError('func has to be a function.')
577
595
 
578
- for i in range(42):
579
- try:
580
- func(np.arange(i), x.T[0])
581
- except TypeError:
582
- continue
583
- except IndexError:
584
- continue
585
- else:
586
- break
596
+ if 'n_parms' in kwargs:
597
+ n_parms = kwargs.get('n_parms')
598
+ if not isinstance(n_parms, int):
599
+ raise TypeError(
600
+ f"'n_parms' must be an integer, got {n_parms!r} "
601
+ f"of type {type(n_parms).__name__}."
602
+ )
603
+ if n_parms <= 0:
604
+ raise ValueError(
605
+ f"'n_parms' must be a positive integer, got {n_parms}."
606
+ )
587
607
  else:
588
- raise RuntimeError("Fit function is not valid.")
608
+ for i in range(100):
609
+ try:
610
+ func(np.arange(i), x.T[0])
611
+ except TypeError:
612
+ continue
613
+ except IndexError:
614
+ continue
615
+ else:
616
+ break
617
+ else:
618
+ raise RuntimeError("Fit function is not valid.")
619
+
620
+ n_parms = i
589
621
 
590
- n_parms = i
591
622
  if not silent:
592
623
  print('Fit with', n_parms, 'parameter' + 's' * (n_parms > 1))
593
624
 
@@ -571,7 +571,6 @@ def _ol_from_dict(ind, reps='DICTOBS'):
571
571
  counter = 0
572
572
 
573
573
  def dict_replace_obs(d):
574
- nonlocal ol
575
574
  nonlocal counter
576
575
  x = {}
577
576
  for k, v in d.items():
@@ -592,7 +591,6 @@ def _ol_from_dict(ind, reps='DICTOBS'):
592
591
  return x
593
592
 
594
593
  def list_replace_obs(li):
595
- nonlocal ol
596
594
  nonlocal counter
597
595
  x = []
598
596
  for e in li:
@@ -613,7 +611,6 @@ def _ol_from_dict(ind, reps='DICTOBS'):
613
611
  return x
614
612
 
615
613
  def obslist_replace_obs(li):
616
- nonlocal ol
617
614
  nonlocal counter
618
615
  il = []
619
616
  for e in li:
@@ -694,7 +691,6 @@ def _od_from_list_and_dict(ol, ind, reps='DICTOBS'):
694
691
 
695
692
  def dict_replace_string(d):
696
693
  nonlocal counter
697
- nonlocal ol
698
694
  x = {}
699
695
  for k, v in d.items():
700
696
  if isinstance(v, dict):
@@ -710,7 +706,6 @@ def _od_from_list_and_dict(ol, ind, reps='DICTOBS'):
710
706
 
711
707
  def list_replace_string(li):
712
708
  nonlocal counter
713
- nonlocal ol
714
709
  x = []
715
710
  for e in li:
716
711
  if isinstance(e, list):
@@ -1,6 +1,7 @@
1
1
  import warnings
2
2
  import gzip
3
3
  import sqlite3
4
+ from contextlib import closing
4
5
  import pandas as pd
5
6
  from ..obs import Obs
6
7
  from ..correlators import Corr
@@ -29,9 +30,8 @@ def to_sql(df, table_name, db, if_exists='fail', gz=True, **kwargs):
29
30
  None
30
31
  """
31
32
  se_df = _serialize_df(df, gz=gz)
32
- con = sqlite3.connect(db)
33
- se_df.to_sql(table_name, con, if_exists=if_exists, index=False, **kwargs)
34
- con.close()
33
+ with closing(sqlite3.connect(db)) as con:
34
+ se_df.to_sql(table_name, con=con, if_exists=if_exists, index=False, **kwargs)
35
35
 
36
36
 
37
37
  def read_sql(sql, db, auto_gamma=False, **kwargs):
@@ -52,9 +52,8 @@ def read_sql(sql, db, auto_gamma=False, **kwargs):
52
52
  data : pandas.DataFrame
53
53
  Dataframe with the content of the sqlite database.
54
54
  """
55
- con = sqlite3.connect(db)
56
- extract_df = pd.read_sql(sql, con, **kwargs)
57
- con.close()
55
+ with closing(sqlite3.connect(db)) as con:
56
+ extract_df = pd.read_sql(sql, con=con, **kwargs)
58
57
  return _deserialize_df(extract_df, auto_gamma=auto_gamma)
59
58
 
60
59
 
@@ -0,0 +1 @@
1
+ __version__ = "2.15.0"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pyerrors
3
- Version: 2.14.0
3
+ Version: 2.15.0
4
4
  Summary: Error propagation and statistical analysis for Monte Carlo simulations
5
5
  Home-page: https://github.com/fjosw/pyerrors
6
6
  Author: Fabian Joswig
@@ -11,7 +11,6 @@ Project-URL: Bug Tracker, https://github.com/fjosw/pyerrors/issues
11
11
  Project-URL: Changelog, https://github.com/fjosw/pyerrors/blob/master/CHANGELOG.md
12
12
  Classifier: Development Status :: 5 - Production/Stable
13
13
  Classifier: Intended Audience :: Science/Research
14
- Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Programming Language :: Python :: 3
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
@@ -46,6 +45,7 @@ Dynamic: description
46
45
  Dynamic: description-content-type
47
46
  Dynamic: home-page
48
47
  Dynamic: license
48
+ Dynamic: license-file
49
49
  Dynamic: project-url
50
50
  Dynamic: provides-extra
51
51
  Dynamic: requires-dist
@@ -30,7 +30,6 @@ setup(name='pyerrors',
30
30
  classifiers=[
31
31
  'Development Status :: 5 - Production/Stable',
32
32
  'Intended Audience :: Science/Research',
33
- 'License :: OSI Approved :: MIT License',
34
33
  'Programming Language :: Python :: 3',
35
34
  'Programming Language :: Python :: 3.9',
36
35
  'Programming Language :: Python :: 3.10',
@@ -1 +0,0 @@
1
- __version__ = "2.14.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes