Merge branch 'develop' into feat/typehints

This commit is contained in:
Justus Kuhlmann 2025-11-03 11:54:01 +01:00 committed by GitHub
commit 54a8e022df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 2880 additions and 69 deletions

View file

@ -13,7 +13,7 @@ jobs:
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- uses: actions/checkout@v4
- name: Updated documentation
run: |

View file

@ -17,7 +17,7 @@ jobs:
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: flake8 Lint
uses: py-actions/flake8@v2
with:

View file

@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
include:
- os: macos-latest
python-version: "3.12"
@ -42,5 +42,10 @@ jobs:
uv pip install pytest pytest-cov pytest-benchmark hypothesis typing_extensions --system
uv pip freeze --system
- name: Run tests
- name: Run tests with -Werror
if: matrix.python-version != '3.14'
run: pytest --cov=pyerrors -vv -Werror
- name: Run tests without -Werror for python 3.14
if: matrix.python-version == '3.14'
run: pytest --cov=pyerrors -vv

View file

@ -2,6 +2,27 @@
All notable changes to this project will be documented in this file.
## [2.16.0] - 2025-10-30
### Added
- Support for custom configuration number extraction in the sfcf input module.
### Fixed
- Calculation of expected chisquare in connection with priors.
### Changed
- Support for python<3.10 was dropped.
## [2.15.1] - 2025-10-19
### Fixed
- Fixed handling of padding in Correlator prune method.
## [2.15.0] - 2025-10-10
### Added
- Option to explicitly specify the number of fit parameters added.
## [2.14.0] - 2025-03-09
### Added

View file

@ -1,4 +1,4 @@
[![](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![arXiv](https://img.shields.io/badge/arXiv-2209.14371-b31b1b.svg)](https://arxiv.org/abs/2209.14371) [![DOI](https://img.shields.io/badge/DOI-10.1016%2Fj.cpc.2023.108750-blue)](https://doi.org/10.1016/j.cpc.2023.108750)
[![](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![arXiv](https://img.shields.io/badge/arXiv-2209.14371-b31b1b.svg)](https://arxiv.org/abs/2209.14371) [![DOI](https://img.shields.io/badge/DOI-10.1016%2Fj.cpc.2023.108750-blue)](https://doi.org/10.1016/j.cpc.2023.108750)
# pyerrors
`pyerrors` is a python framework for error computation and propagation of Markov chain Monte Carlo data from lattice field theory and statistical mechanics simulations.

View file

@ -1399,13 +1399,15 @@ class Corr:
tmpmat = np.empty((Ntrunc, Ntrunc), dtype=object)
rmat = []
for t in range(basematrix.T):
if self.content[t] is None:
rmat.append(None)
else:
for i in range(Ntrunc):
for j in range(Ntrunc):
tmpmat[i][j] = evecs[i].T @ self[t] @ evecs[j]
rmat.append(np.copy(tmpmat))
newcontent = [None if (self.content[t] is None) else rmat[t] for t in range(self.T)]
return Corr(newcontent)
return Corr(rmat)
def _sort_vectors(vec_set_in: list[Optional[ndarray]], ts: int) -> list[Union[None, ndarray, list[ndarray]]]:

View file

@ -154,7 +154,7 @@ def least_squares(x: Any, y: Union[dict[str, ndarray], list[Obs], ndarray, dict[
Obs (e.g. results from a previous fit) or strings containing a value and an error formatted like
0.548(23), 500(40) or 0.5(0.4)
silent : bool, optional
If true all output to the console is omitted (default False).
If True all output to the console is omitted (default False).
initial_guess : list
can provide an initial guess for the input parameters. Relevant for
non-linear fits with many parameters. In case of correlated fits the guess is used to perform
@ -162,10 +162,10 @@ def least_squares(x: Any, y: Union[dict[str, ndarray], list[Obs], ndarray, dict[
method : str, optional
can be used to choose an alternative method for the minimization of chisquare.
The possible methods are the ones which can be used for scipy.optimize.minimize and
migrad of iminuit. If no method is specified, Levenberg-Marquard is used.
migrad of iminuit. If no method is specified, LevenbergMarquardt is used.
Reliable alternatives are migrad, Powell and Nelder-Mead.
tol: float, optional
can be used (only for combined fits and methods other than Levenberg-Marquard) to set the tolerance for convergence
can be used (only for combined fits and methods other than LevenbergMarquardt) to set the tolerance for convergence
to a different value to either speed up convergence at the cost of a larger error on the fitted parameters (and possibly
invalid estimates for parameter uncertainties) or smaller values to get more accurate parameter values
The stopping criterion depends on the method, e.g. migrad: edm_max = 0.002 * tol * errordef (EDM criterion: edm < edm_max)
@ -175,7 +175,7 @@ def least_squares(x: Any, y: Union[dict[str, ndarray], list[Obs], ndarray, dict[
In practice the correlation matrix is Cholesky decomposed and inverted (instead of the covariance matrix).
This procedure should be numerically more stable as the correlation matrix is typically better conditioned (Jacobi preconditioning).
inv_chol_cov_matrix [array,list], optional
array: shape = (no of y values) X (no of y values)
array: shape = (number of y values) X (number of y values)
list: for an uncombined fit: [""]
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
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.
@ -191,6 +191,9 @@ def least_squares(x: Any, y: Union[dict[str, ndarray], list[Obs], ndarray, dict[
If True, a quantile-quantile plot of the fit result is generated (default False).
num_grad : bool
Use numerical differentation instead of automatic differentiation to perform the error propagation (default False).
n_parms : int, optional
Number of fit parameters. Overrides automatic detection of parameter count.
Useful when autodetection fails. Must match the length of initial_guess or priors (if provided).
Returns
-------
@ -292,6 +295,18 @@ def least_squares(x: Any, y: Union[dict[str, ndarray], list[Obs], ndarray, dict[
raise Exception("No y errors available, run the gamma method first.")
# number of fit parameters
if 'n_parms' in kwargs:
n_parms = kwargs.get('n_parms')
if not isinstance(n_parms, int):
raise TypeError(
f"'n_parms' must be an integer, got {n_parms!r} "
f"of type {type(n_parms).__name__}."
)
if n_parms <= 0:
raise ValueError(
f"'n_parms' must be a positive integer, got {n_parms}."
)
else:
n_parms_ls = []
for key in key_ls:
if not callable(funcd[key]):
@ -479,7 +494,7 @@ def least_squares(x: Any, y: Union[dict[str, ndarray], list[Obs], ndarray, dict[
hat_vector = prepare_hat_matrix()
A = W @ hat_vector
P_phi = A @ np.linalg.pinv(A.T @ A) @ A.T
expected_chisquare = np.trace((np.identity(y_all.shape[-1]) - P_phi) @ W @ cov @ W)
expected_chisquare = np.trace((np.identity(y_all.shape[-1]) - P_phi) @ W @ cov @ W) + len(loc_priors)
output.chisquare_by_expected_chisquare = output.chisquare / expected_chisquare
if not silent:
print('chisquare/expected_chisquare:', output.chisquare_by_expected_chisquare)
@ -557,17 +572,20 @@ def total_least_squares(x: list[Obs], y: list[Obs], func: Callable, silent: bool
It is important that all numpy functions refer to autograd.numpy, otherwise the differentiation
will not work.
silent : bool, optional
If true all output to the console is omitted (default False).
If True all output to the console is omitted (default False).
initial_guess : list
can provide an initial guess for the input parameters. Relevant for non-linear
fits with many parameters.
expected_chisquare : bool
If true prints the expected chisquare which is
If True prints the expected chisquare which is
corrected by effects caused by correlated input data.
This can take a while as the full correlation matrix
has to be calculated (default False).
num_grad : bool
Use numerical differentation instead of automatic differentiation to perform the error propagation (default False).
Use numerical differentiation instead of automatic differentiation to perform the error propagation (default False).
n_parms : int, optional
Number of fit parameters. Overrides automatic detection of parameter count.
Useful when autodetection fails. Must match the length of initial_guess (if provided).
Notes
-----
@ -597,7 +615,19 @@ def total_least_squares(x: list[Obs], y: list[Obs], func: Callable, silent: bool
if not callable(func):
raise TypeError('func has to be a function.')
for i in range(42):
if 'n_parms' in kwargs:
n_parms = kwargs.get('n_parms')
if not isinstance(n_parms, int):
raise TypeError(
f"'n_parms' must be an integer, got {n_parms!r} "
f"of type {type(n_parms).__name__}."
)
if n_parms <= 0:
raise ValueError(
f"'n_parms' must be a positive integer, got {n_parms}."
)
else:
for i in range(100):
try:
func(np.arange(i), x.T[0])
except TypeError:
@ -610,6 +640,7 @@ def total_least_squares(x: list[Obs], y: list[Obs], func: Callable, silent: bool
raise RuntimeError("Fit function is not valid.")
n_parms = i
if not silent:
print('Fit with', n_parms, 'parameter' + 's' * (n_parms > 1))

View file

@ -8,12 +8,13 @@ from .utils import sort_names, check_idl
import itertools
from numpy import ndarray
from typing import Any, Union, Optional, Literal
from Collections.abc import Callable
sep = "/"
def read_sfcf(path: str, prefix: str, name: str, quarks: str='.*', corr_type: str="bi", noffset: int=0, wf: int=0, wf2: int=0, version: str="1.0c", cfg_separator: str="n", silent: bool=False, **kwargs) -> list[Obs]:
def read_sfcf(path: str, prefix: str, name: str, quarks: str='.*', corr_type: str="bi", noffset: int=0, wf: int=0, wf2: int=0, version: str="1.0c", cfg_separator: str="n", cfg_func: Callable | None = None, silent: bool=False, **kwargs) -> list[Obs]:
"""Read sfcf files from given folder structure.
Parameters
@ -74,11 +75,11 @@ def read_sfcf(path: str, prefix: str, name: str, quarks: str='.*', corr_type: st
"""
ret = read_sfcf_multi(path, prefix, [name], quarks_list=[quarks], corr_type_list=[corr_type],
noffset_list=[noffset], wf_list=[wf], wf2_list=[wf2], version=version,
cfg_separator=cfg_separator, silent=silent, **kwargs)
cfg_separator=cfg_separator, cfg_func=cfg_func, silent=silent, **kwargs)
return ret[name][quarks][str(noffset)][str(wf)][str(wf2)]
def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: list[str]=['.*'], corr_type_list: list[str]=['bi'], noffset_list: list[int]=[0], wf_list: list[int]=[0], wf2_list: list[int]=[0], version: str="1.0c", cfg_separator: str="n", silent: bool=False, keyed_out: bool=False, **kwargs) -> dict:
def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: list[str]=['.*'], corr_type_list: list[str]=['bi'], noffset_list: list[int]=[0], wf_list: list[int]=[0], wf2_list: list[int]=[0], version: str="1.0c", cfg_separator: str="n", cfg_func: Callable | None = None, silent: bool=False, keyed_out: bool=False, **kwargs) -> dict:
"""Read sfcf files from given folder structure.
Parameters
@ -246,7 +247,16 @@ def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: l
for key in needed_keys:
internal_ret_dict[key] = []
rep_idl: list = []
def _default_idl_func(cfg_string, cfg_sep):
return int(cfg_string.split(cfg_sep)[-1])
if cfg_func is None:
print("Default idl function in use.")
cfg_func = _default_idl_func
cfg_func_args = [cfg_separator]
else:
cfg_func_args = kwargs.get("cfg_func_args", [])
if not appended:
for i, item in enumerate(ls):
rep_path = path + '/' + item
@ -270,7 +280,7 @@ def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: l
for cfg in sub_ls:
try:
if compact:
rep_idl.append(int(cfg.split(cfg_separator)[-1]))
rep_idl.append(cfg_func(cfg, *cfg_func_args))
else:
rep_idl.append(int(cfg[3:]))
except Exception:
@ -353,7 +363,7 @@ def read_sfcf_multi(path: str, prefix: str, name_list: list[str], quarks_list: l
rep_idl = []
rep_data = []
filename = path + '/' + file
T, rep_idl, rep_data = _read_append_rep(filename, pattern, intern[name]['b2b'], cfg_separator, im, intern[name]['single'])
T, rep_idl, rep_data = _read_append_rep(filename, pattern, intern[name]['b2b'], im, intern[name]['single'], cfg_func, cfg_func_args)
if rep == 0:
intern[name]['T'] = T
for t in range(intern[name]['T']):
@ -586,12 +596,7 @@ def _read_compact_rep(path: str, rep: str, sub_ls: list[str], intern: dict[str,
return return_vals
def _read_chunk(chunk: list[str], gauge_line: int, cfg_sep: str, start_read: int, T: int, corr_line: int, b2b: bool, pattern: str, im: int, single: bool) -> tuple[int, list[float]]:
try:
idl = int(chunk[gauge_line].split(cfg_sep)[-1])
except Exception:
raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line)
def _read_chunk_data(chunk: list[str], start_read: int, T: int, corr_line: int, b2b: bool, pattern: str, im: int, single: bool) -> tuple[int, list[float]]:
found_pat = ""
data = []
for li in chunk[corr_line + 1:corr_line + 6 + b2b]:
@ -600,10 +605,10 @@ def _read_chunk(chunk: list[str], gauge_line: int, cfg_sep: str, start_read: int
for t, line in enumerate(chunk[start_read:start_read + T]):
floats = list(map(float, line.split()))
data.append(floats[im + 1 - single])
return idl, data
return data
def _read_append_rep(filename: str, pattern: str, b2b: bool, cfg_separator: str, im: int, single: bool) -> tuple[int, list[int], list[list[float]]]:
def _read_append_rep(filename: str, pattern: str, b2b: bool, im: int, single: bool, idl_func: Callable[str, list], cfg_func_args: list) -> tuple[int, list[int], list[list[float]]]:
with open(filename, 'r') as fp:
content = fp.readlines()
data_starts = []
@ -639,7 +644,11 @@ def _read_append_rep(filename: str, pattern: str, b2b: bool, cfg_separator: str,
start = data_starts[cnfg]
stop = start + data_starts[1]
chunk = content[start:stop]
idl, data = _read_chunk(chunk, gauge_line, cfg_separator, start_read, T, corr_line, b2b, pattern, im, single)
try:
idl = idl_func(chunk[gauge_line], *cfg_func_args)
except Exception:
raise Exception("Couldn't parse idl from file", filename, ", problem with chunk of lines", start + 1, "to", stop + 1)
data = _read_chunk_data(chunk, start_read, T, corr_line, b2b, pattern, im, single)
rep_idl.append(idl)
rep_data.append(data)

View file

@ -1 +1 @@
__version__ = "2.15.0-dev"
__version__ = "2.17.0-dev"

View file

@ -24,18 +24,18 @@ setup(name='pyerrors',
author_email='fabian.joswig@ed.ac.uk',
license="MIT",
packages=find_packages(),
python_requires='>=3.9.0',
python_requires='>=3.10.0',
install_requires=['numpy>=2.0', 'autograd>=1.7.0', 'numdifftools>=0.9.41', 'matplotlib>=3.9', 'scipy>=1.13', 'iminuit>=2.28', 'h5py>=3.11', 'lxml>=5.0', 'python-rapidjson>=1.20', 'pandas>=2.2'],
extras_require={'test': ['pytest', 'pytest-cov', 'pytest-benchmark', 'hypothesis', 'nbmake', 'flake8']},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',
'Topic :: Scientific/Engineering :: Physics'
],
)

View file

@ -783,3 +783,26 @@ def test_complex_add_and_mul():
cc += 2j
cc = cc * 4j
cc.real + cc.imag
def test_prune_with_Nones():
N = 3
T = 10
front_padding = 1
back_padding = T // 2
Ntrunc = N - 1
t0proj = 2
tproj = 3
corr_content = np.array([[[pe.pseudo_Obs((i+j+1)**(-t), .01, "None_prune_test") for i in range(N)] for j in range(N)] for t in range(T // 2 - front_padding)])
unpadded_corr = pe.Corr(corr_content)
padded_corr = pe.Corr(corr_content, padding=[front_padding, back_padding])
tmp_corr = unpadded_corr.prune(Ntrunc, t0proj=t0proj-front_padding, tproj=tproj-front_padding)
pruned_then_padded = pe.Corr(tmp_corr.content, padding=[front_padding, back_padding])
padded_then_pruned = padded_corr.prune(Ntrunc, t0proj=t0proj, tproj=tproj)
for t in range(T):
assert np.all(pruned_then_padded.content[t] == padded_then_pruned.content[t])

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,970 @@
[run]
version 2.1
date 2022-01-19 11:04:03 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n1.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_1
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 0
corr
+3.5119415254545021e+02 +6.7620978057264750e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 1
corr
+3.5120703575855339e+02 +6.5026340956203663e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 2
corr
+3.5120808902177868e+02 +6.5443496235264788e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 0
corr
+3.5120703575855515e+02 +6.9706500417651470e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 1
corr
+3.5122001235609065e+02 +6.9516150897757419e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 2
corr
+3.5122104108046199e+02 +6.9232860455434941e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 0
corr
+3.5120808902177447e+02 +1.0849949614595719e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 1
corr
+3.5122104108046182e+02 +1.0866063643253473e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 2
corr
+3.5122207631098047e+02 +1.0827277318679030e-14
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 0
corr
+3.5119415254545038e+02 +3.0143306723935508e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 1
corr
+3.5120703575855367e+02 +4.3340379505972648e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 2
corr
+3.5120808902177902e+02 +3.9652247575094006e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 0
corr
+3.5120703575855526e+02 -8.2540994138261318e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 1
corr
+3.5122001235609082e+02 -9.7121215247039609e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 2
corr
+3.5122104108046227e+02 -9.0872484903683497e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 0
corr
+3.5120808902177453e+02 +5.1331372776616026e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 1
corr
+3.5122104108046193e+02 +5.0816653044831932e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 2
corr
+3.5122207631098064e+02 +5.1165649253001659e-15
[run]
version 2.1
date 2022-01-19 11:04:05 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n2.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_1
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 0
corr
+3.5119415254545021e+02 +6.7620978057264750e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 1
corr
+3.5120703575855339e+02 +6.5026340956203663e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 2
corr
+3.5120808902177868e+02 +6.5443496235264788e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 0
corr
+3.5120703575855515e+02 +6.9706500417651470e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 1
corr
+3.5122001235609065e+02 +6.9516150897757419e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 2
corr
+3.5122104108046199e+02 +6.9232860455434941e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 0
corr
+3.5120808902177447e+02 +1.0849949614595719e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 1
corr
+3.5122104108046182e+02 +1.0866063643253473e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 2
corr
+3.5122207631098047e+02 +1.0827277318679030e-14
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 0
corr
+3.5119415254545038e+02 +3.0143306723935508e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 1
corr
+3.5120703575855367e+02 +4.3340379505972648e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 2
corr
+3.5120808902177902e+02 +3.9652247575094006e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 0
corr
+3.5120703575855526e+02 -8.2540994138261318e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 1
corr
+3.5122001235609082e+02 -9.7121215247039609e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 2
corr
+3.5122104108046227e+02 -9.0872484903683497e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 0
corr
+3.5120808902177453e+02 +5.1331372776616026e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 1
corr
+3.5122104108046193e+02 +5.0816653044831932e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 2
corr
+3.5122207631098064e+02 +5.1165649253001659e-15
[run]
version 2.1
date 2022-01-19 11:04:07 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n3.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_1
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 0
corr
+3.5119415254545021e+02 +6.7620978057264750e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 1
corr
+3.5120703575855339e+02 +6.5026340956203663e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 2
corr
+3.5120808902177868e+02 +6.5443496235264788e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 0
corr
+3.5120703575855515e+02 +6.9706500417651470e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 1
corr
+3.5122001235609065e+02 +6.9516150897757419e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 2
corr
+3.5122104108046199e+02 +6.9232860455434941e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 0
corr
+3.5120808902177447e+02 +1.0849949614595719e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 1
corr
+3.5122104108046182e+02 +1.0866063643253473e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 2
corr
+3.5122207631098047e+02 +1.0827277318679030e-14
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 0
corr
+3.5119415254545038e+02 +3.0143306723935508e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 1
corr
+3.5120703575855367e+02 +4.3340379505972648e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 2
corr
+3.5120808902177902e+02 +3.9652247575094006e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 0
corr
+3.5120703575855526e+02 -8.2540994138261318e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 1
corr
+3.5122001235609082e+02 -9.7121215247039609e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 2
corr
+3.5122104108046227e+02 -9.0872484903683497e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 0
corr
+3.5120808902177453e+02 +5.1331372776616026e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 1
corr
+3.5122104108046193e+02 +5.0816653044831932e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 2
corr
+3.5122207631098064e+02 +5.1165649253001659e-15
[run]
version 2.1
date 2022-01-19 11:04:09 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n4.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_1
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 0
corr
+3.5119415254545021e+02 +6.7620978057264750e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 1
corr
+3.5120703575855339e+02 +6.5026340956203663e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 2
corr
+3.5120808902177868e+02 +6.5443496235264788e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 0
corr
+3.5120703575855515e+02 +6.9706500417651470e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 1
corr
+3.5122001235609065e+02 +6.9516150897757419e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 2
corr
+3.5122104108046199e+02 +6.9232860455434941e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 0
corr
+3.5120808902177447e+02 +1.0849949614595719e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 1
corr
+3.5122104108046182e+02 +1.0866063643253473e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 2
corr
+3.5122207631098047e+02 +1.0827277318679030e-14
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 0
corr
+3.5119415254545038e+02 +3.0143306723935508e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 1
corr
+3.5120703575855367e+02 +4.3340379505972648e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 2
corr
+3.5120808902177902e+02 +3.9652247575094006e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 0
corr
+3.5120703575855526e+02 -8.2540994138261318e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 1
corr
+3.5122001235609082e+02 -9.7121215247039609e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 2
corr
+3.5122104108046227e+02 -9.0872484903683497e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 0
corr
+3.5120808902177453e+02 +5.1331372776616026e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 1
corr
+3.5122104108046193e+02 +5.0816653044831932e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 2
corr
+3.5122207631098064e+02 +5.1165649253001659e-15
[run]
version 2.1
date 2022-01-19 11:04:11 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n5.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_1
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 0
corr
+3.5119415254545021e+02 +6.7620978057264750e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 1
corr
+3.5120703575855339e+02 +6.5026340956203663e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 0
wf_2 2
corr
+3.5120808902177868e+02 +6.5443496235264788e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 0
corr
+3.5120703575855515e+02 +6.9706500417651470e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 1
corr
+3.5122001235609065e+02 +6.9516150897757419e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 1
wf_2 2
corr
+3.5122104108046199e+02 +6.9232860455434941e-15
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 0
corr
+3.5120808902177447e+02 +1.0849949614595719e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 1
corr
+3.5122104108046182e+02 +1.0866063643253473e-14
[correlator]
name f_1
quarks lquark lquark
offset 0
wf 2
wf_2 2
corr
+3.5122207631098047e+02 +1.0827277318679030e-14
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 0
corr
+3.5119415254545038e+02 +3.0143306723935508e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 1
corr
+3.5120703575855367e+02 +4.3340379505972648e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 0
wf_2 2
corr
+3.5120808902177902e+02 +3.9652247575094006e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 0
corr
+3.5120703575855526e+02 -8.2540994138261318e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 1
corr
+3.5122001235609082e+02 -9.7121215247039609e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 1
wf_2 2
corr
+3.5122104108046227e+02 -9.0872484903683497e-16
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 0
corr
+3.5120808902177453e+02 +5.1331372776616026e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 1
corr
+3.5122104108046193e+02 +5.0816653044831932e-15
[correlator]
name f_1
quarks lquark lquark
offset 1
wf 2
wf_2 2
corr
+3.5122207631098064e+02 +5.1165649253001659e-15

View file

@ -0,0 +1,400 @@
[run]
version 2.1
date 2022-01-19 11:04:03 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n1.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_A
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 0
corr_t
1 +6.5471188727972304e+01 -6.1214214711790100e-12
2 +1.0447210336915187e+00 +8.9219487930753188e-13
3 -4.1025094911185178e+01 -4.8315634170546161e-14
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 1
corr_t
1 +6.5551520722862705e+01 +2.0963356863957609e-13
2 +1.0542820240851569e+00 +2.3989756974599379e-15
3 -4.1024441815729936e+01 -5.7107484666182308e-15
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 2
corr_t
1 +6.5529951269442847e+01 -6.6512260271334321e-14
2 +1.0516822345055969e+00 -2.2935262162529075e-15
3 -4.1025142768037746e+01 +3.7566377680004518e-16
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 0
corr_t
1 +6.5471188727965909e+01 -1.6112786177915427e-11
2 +1.0447210337411881e+00 -7.0387528705692678e-13
3 -4.1025094911167137e+01 +4.6509152745618223e-13
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 1
corr_t
1 +6.5551520722842213e+01 -8.1976426690345305e-13
2 +1.0542820240843382e+00 +2.1626370477046812e-13
3 -4.1024441815730086e+01 -2.4147931196409923e-14
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 2
corr_t
1 +6.5529951269443117e+01 +7.9192560386479701e-14
2 +1.0516822345055870e+00 -1.2443038782429568e-14
3 -4.1025142768037739e+01 +5.9315333178954509e-17
[run]
version 2.1
date 2022-01-19 11:04:05 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n2.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_A
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 0
corr_t
1 +6.5471188727972304e+01 -6.1214214711790100e-12
2 +1.0447210336915187e+00 +8.9219487930753188e-13
3 -4.1025094911185178e+01 -4.8315634170546161e-14
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 1
corr_t
1 +6.5551520722862705e+01 +2.0963356863957609e-13
2 +1.0542820240851569e+00 +2.3989756974599379e-15
3 -4.1024441815729936e+01 -5.7107484666182308e-15
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 2
corr_t
1 +6.5529951269442847e+01 -6.6512260271334321e-14
2 +1.0516822345055969e+00 -2.2935262162529075e-15
3 -4.1025142768037746e+01 +3.7566377680004518e-16
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 0
corr_t
1 +6.5471188727965909e+01 -1.6112786177915427e-11
2 +1.0447210337411881e+00 -7.0387528705692678e-13
3 -4.1025094911167137e+01 +4.6509152745618223e-13
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 1
corr_t
1 +6.5551520722842213e+01 -8.1976426690345305e-13
2 +1.0542820240843382e+00 +2.1626370477046812e-13
3 -4.1024441815730086e+01 -2.4147931196409923e-14
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 2
corr_t
1 +6.5529951269443117e+01 +7.9192560386479701e-14
2 +1.0516822345055870e+00 -1.2443038782429568e-14
3 -4.1025142768037739e+01 +5.9315333178954509e-17
[run]
version 2.1
date 2022-01-19 11:04:07 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n3.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_A
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 0
corr_t
1 +6.5471188727972304e+01 -6.1214214711790100e-12
2 +1.0447210336915187e+00 +8.9219487930753188e-13
3 -4.1025094911185178e+01 -4.8315634170546161e-14
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 1
corr_t
1 +6.5551520722862705e+01 +2.0963356863957609e-13
2 +1.0542820240851569e+00 +2.3989756974599379e-15
3 -4.1024441815729936e+01 -5.7107484666182308e-15
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 2
corr_t
1 +6.5529951269442847e+01 -6.6512260271334321e-14
2 +1.0516822345055969e+00 -2.2935262162529075e-15
3 -4.1025142768037746e+01 +3.7566377680004518e-16
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 0
corr_t
1 +6.5471188727965909e+01 -1.6112786177915427e-11
2 +1.0447210337411881e+00 -7.0387528705692678e-13
3 -4.1025094911167137e+01 +4.6509152745618223e-13
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 1
corr_t
1 +6.5551520722842213e+01 -8.1976426690345305e-13
2 +1.0542820240843382e+00 +2.1626370477046812e-13
3 -4.1024441815730086e+01 -2.4147931196409923e-14
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 2
corr_t
1 +6.5529951269443117e+01 +7.9192560386479701e-14
2 +1.0516822345055870e+00 -1.2443038782429568e-14
3 -4.1025142768037739e+01 +5.9315333178954509e-17
[run]
version 2.1
date 2022-01-19 11:04:09 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n4.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_A
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 0
corr_t
1 +6.5471188727972304e+01 -6.1214214711790100e-12
2 +1.0447210336915187e+00 +8.9219487930753188e-13
3 -4.1025094911185178e+01 -4.8315634170546161e-14
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 1
corr_t
1 +6.5551520722862705e+01 +2.0963356863957609e-13
2 +1.0542820240851569e+00 +2.3989756974599379e-15
3 -4.1024441815729936e+01 -5.7107484666182308e-15
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 2
corr_t
1 +6.5529951269442847e+01 -6.6512260271334321e-14
2 +1.0516822345055969e+00 -2.2935262162529075e-15
3 -4.1025142768037746e+01 +3.7566377680004518e-16
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 0
corr_t
1 +6.5471188727965909e+01 -1.6112786177915427e-11
2 +1.0447210337411881e+00 -7.0387528705692678e-13
3 -4.1025094911167137e+01 +4.6509152745618223e-13
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 1
corr_t
1 +6.5551520722842213e+01 -8.1976426690345305e-13
2 +1.0542820240843382e+00 +2.1626370477046812e-13
3 -4.1024441815730086e+01 -2.4147931196409923e-14
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 2
corr_t
1 +6.5529951269443117e+01 +7.9192560386479701e-14
2 +1.0516822345055870e+00 -1.2443038782429568e-14
3 -4.1025142768037739e+01 +5.9315333178954509e-17
[run]
version 2.1
date 2022-01-19 11:04:11 +0100
host r04n07.palma.wwu
dir /scratch/tmp/j_kuhl19
user j_kuhl19
gauge_name /data_a_r0_n5.lex
gauge_md5 1ea28326e4090996111a320b8372811d
param_name sfcf_unity_test.in
param_md5 d881e90d41188a33b8b0f1bd0bc53ea5
param_hash 686af5e712ee2902180f5428af94c6e7
data_name ./output_10519905/data_af_A
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 0
corr_t
1 +6.5471188727972304e+01 -6.1214214711790100e-12
2 +1.0447210336915187e+00 +8.9219487930753188e-13
3 -4.1025094911185178e+01 -4.8315634170546161e-14
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 1
corr_t
1 +6.5551520722862705e+01 +2.0963356863957609e-13
2 +1.0542820240851569e+00 +2.3989756974599379e-15
3 -4.1024441815729936e+01 -5.7107484666182308e-15
[correlator]
name f_A
quarks lquark lquark
offset 0
wf 2
corr_t
1 +6.5529951269442847e+01 -6.6512260271334321e-14
2 +1.0516822345055969e+00 -2.2935262162529075e-15
3 -4.1025142768037746e+01 +3.7566377680004518e-16
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 0
corr_t
1 +6.5471188727965909e+01 -1.6112786177915427e-11
2 +1.0447210337411881e+00 -7.0387528705692678e-13
3 -4.1025094911167137e+01 +4.6509152745618223e-13
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 1
corr_t
1 +6.5551520722842213e+01 -8.1976426690345305e-13
2 +1.0542820240843382e+00 +2.1626370477046812e-13
3 -4.1024441815730086e+01 -2.4147931196409923e-14
[correlator]
name f_A
quarks lquark lquark
offset 1
wf 2
corr_t
1 +6.5529951269443117e+01 +7.9192560386479701e-14
2 +1.0516822345055870e+00 -1.2443038782429568e-14
3 -4.1025142768037739e+01 +5.9315333178954509e-17

View file

@ -1098,6 +1098,7 @@ def test_combined_fit_xerr():
}
xd = {k: np.transpose([[1 + .01 * np.random.uniform(), 2] for i in range(len(yd[k]))]) for k in fitd}
pe.fits.least_squares(xd, yd, fitd)
pe.fits.least_squares(xd, yd, fitd, n_parms=4)
def test_x_multidim_fit():
@ -1340,6 +1341,54 @@ def test_combined_fit_constant_shape():
funcs = {"a": lambda a, x: a[0] + a[1] * x,
"": lambda a, x: a[1] + x * 0}
pe.fits.least_squares(x, y, funcs, method='migrad')
pe.fits.least_squares(x, y, funcs, method='migrad', n_parms=2)
def test_fit_n_parms():
# Function that fails if the number of parameters is not specified:
def fcn(p, x):
# Assumes first half of terms are A second half are E
NTerms = int(len(p)/2)
A = anp.array(p[0:NTerms])[:, np.newaxis] # shape (n, 1)
E_P = anp.array(p[NTerms:])[:, np.newaxis] # shape (n, 1)
# This if statement handles the case where x is a single value rather than an array
if isinstance(x, anp.float64) or isinstance(x, anp.int64) or isinstance(x, float) or isinstance(x, int):
x = anp.array([x])[np.newaxis, :] # shape (1, m)
else:
x = anp.array(x)[np.newaxis, :] # shape (1, m)
exp_term = anp.exp(-E_P * x)
weighted_sum = A * exp_term # shape (n, m)
return anp.mean(weighted_sum, axis=0) # shape(m)
c = pe.Corr([pe.pseudo_Obs(2. * np.exp(-.2 * t) + .4 * np.exp(+.4 * t) + .4 * np.exp(-.6 * t), .1, 'corr') for t in range(12)])
c.fit(fcn, n_parms=2)
c.fit(fcn, n_parms=4)
xf = [pe.pseudo_Obs(t, .05, 'corr') for t in range(c.T)]
yf = [c[t] for t in range(c.T)]
pe.fits.total_least_squares(xf, yf, fcn, n_parms=2)
pe.fits.total_least_squares(xf, yf, fcn, n_parms=4)
# Is expected to fail, this is what is fixed with n_parms
with pytest.raises(RuntimeError):
c.fit(fcn, )
with pytest.raises(RuntimeError):
pe.fits.total_least_squares(xf, yf, fcn, )
# Test for positivity
with pytest.raises(ValueError):
c.fit(fcn, n_parms=-2)
with pytest.raises(ValueError):
pe.fits.total_least_squares(xf, yf, fcn, n_parms=-4)
# Have to pass an interger
with pytest.raises(TypeError):
c.fit(fcn, n_parms=2.)
with pytest.raises(TypeError):
pe.fits.total_least_squares(xf, yf, fcn, n_parms=1.2343)
# Improper number of parameters (function should fail)
with pytest.raises(ValueError):
c.fit(fcn, n_parms=7)
with pytest.raises(ValueError):
pe.fits.total_least_squares(xf, yf, fcn, n_parms=5)
def fit_general(x, y, func, silent=False, **kwargs):
@ -1562,3 +1611,81 @@ def old_prior_fit(x, y, func, priors, silent=False, **kwargs):
qqplot(x, y, func, result)
return output
def test_dof_prior_fit():
"""Performs an uncorrelated fit with a prior to uncorrelated data then
the expected chisquare and the usual dof need to agree"""
N = 5
def fitf(a, x):
return a[0] + 0 * x
x = [1. for i in range(N)]
y = [pe.cov_Obs(i, .1, '%d' % (i)) for i in range(N)]
[o.gm() for o in y]
res = pe.fits.least_squares(x, y, fitf, expected_chisquare=True, priors=[pe.cov_Obs(3, 1, 'p')])
assert res.chisquare_by_expected_chisquare == res.chisquare_by_dof
num_samples = 400
N = 10
x = norm.rvs(size=(N, num_samples)) # generate random numbers
r = np.zeros((N, N))
for i in range(N):
for j in range(N):
if(i==j):
r[i, j] = 1.0 # element in correlation matrix
errl = np.sqrt([3.4, 2.5, 3.6, 2.8, 4.2, 4.7, 4.9, 5.1, 3.2, 4.2]) # set y errors
for i in range(N):
for j in range(N):
if(i==j):
r[i, j] *= errl[i] * errl[j] # element in covariance matrix
c = cholesky(r, lower=True)
y = np.dot(c, x)
x = np.arange(N)
x_dict = {}
y_dict = {}
for i,item in enumerate(x):
x_dict[str(item)] = [x[i]]
for linear in [True, False]:
data = []
for i in range(N):
if linear:
data.append(pe.Obs([[i + 1 + o for o in y[i]]], ['ens'+str(i)]))
else:
data.append(pe.Obs([[np.exp(-(i + 1)) + np.exp(-(i + 1)) * o for o in y[i]]], ['ens'+str(i)]))
[o.gamma_method() for o in data]
data_dict = {}
for i,item in enumerate(x):
data_dict[str(item)] = [data[i]]
corr = pe.covariance(data, correlation=True)
chol = np.linalg.cholesky(corr)
covdiag = np.diag(1 / np.asarray([o.dvalue for o in data]))
chol_inv = scipy.linalg.solve_triangular(chol, covdiag, lower=True)
chol_inv_keys = [""]
chol_inv_keys_combined_fit = [str(item) for i,item in enumerate(x)]
if linear:
def fitf(p, x):
return p[1] + p[0] * x
fitf_dict = {}
for i,item in enumerate(x):
fitf_dict[str(item)] = fitf
else:
def fitf(p, x):
return p[1] * anp.exp(-p[0] * x)
fitf_dict = {}
for i,item in enumerate(x):
fitf_dict[str(item)] = fitf
fit_exp = pe.least_squares(x, data, fitf, expected_chisquare=True, priors = {0:pe.cov_Obs(1.0, 1, 'p')})
fit_cov = pe.least_squares(x, data, fitf, correlated_fit = True, inv_chol_cov_matrix = [chol_inv,chol_inv_keys], priors = {0:pe.cov_Obs(1.0, 1, 'p')})
assert np.isclose(fit_exp.chisquare_by_expected_chisquare,fit_exp.chisquare_by_dof,atol=1e-8)
assert np.isclose(fit_exp.chisquare_by_expected_chisquare,fit_cov.chisquare_by_dof,atol=1e-8)

View file

@ -152,7 +152,7 @@ def test_function_overloading():
np.arccos(1 / b)
np.arctan(1 / b)
np.arctanh(1 / b)
np.sinc(1 / b)
#np.sinc(1 / b) # Commented out for now
b ** b
0.5 ** b

View file

@ -24,10 +24,10 @@ def build_test_environment(path, env_type, cfgs, reps):
os.mkdir(path + "/data_c/data_c_r"+str(i))
for j in range(1, cfgs+1):
shutil.copy(path + "/data_c/data_c_r0/data_c_r0_n1", path + "/data_c/data_c_r"+str(i)+"/data_c_r"+str(i)+"_n"+str(j))
elif env_type == "a":
elif env_type in ["a", "apf"]:
for i in range(1, reps):
for corr in ["f_1", "f_A", "F_V0"]:
shutil.copy(path + "/data_a/data_a_r0." + corr, path + "/data_a/data_a_r" + str(i) + "." + corr)
shutil.copy(path + "/data_" + env_type + "/data_" + env_type + "_r0." + corr, path + "/data_" + env_type + "/data_" + env_type + "_r" + str(i) + "." + corr)
def test_o_bb(tmp_path):
@ -276,6 +276,28 @@ def test_a_bb(tmp_path):
assert f_1[0].value == 351.1941525454502
def test_a_bb_external_idl_func(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
def extract_idl(s: str) -> int:
return int(s.split("n")[-1])
f_1 = sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "f_1", quarks="lquark lquark", wf=0, wf2=0, version="2.0a", corr_type="bb", cfg_func=extract_idl)
print(f_1)
assert len(f_1) == 1
assert list(f_1[0].shape.keys()) == ["data_a_|r0", "data_a_|r1", "data_a_|r2"]
assert f_1[0].value == 351.1941525454502
def test_a_bb_external_idl_func_postfix(tmp_path):
build_test_environment(str(tmp_path), "apf", 5, 3)
def extract_idl(s: str) -> int:
return int(s.split("n")[-1][:-5])
f_1 = sfin.read_sfcf(str(tmp_path) + "/data_apf", "data_apf", "f_1", quarks="lquark lquark", wf=0, wf2=0, version="2.0a", corr_type="bb", cfg_func=extract_idl)
print(f_1)
assert len(f_1) == 1
assert list(f_1[0].shape.keys()) == ["data_apf_|r0", "data_apf_|r1", "data_apf_|r2"]
assert f_1[0].value == 351.1941525454502
def test_a_bi(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
f_A = sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "f_A", quarks="lquark lquark", wf=0, version="2.0a")
@ -287,6 +309,32 @@ def test_a_bi(tmp_path):
assert f_A[2].value == -41.025094911185185
def test_a_bi_external_idl_func(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
def extract_idl(s: str) -> int:
return int(s.split("n")[-1])
f_A = sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "f_A", quarks="lquark lquark", wf=0, version="2.0a", cfg_func=extract_idl)
print(f_A)
assert len(f_A) == 3
assert list(f_A[0].shape.keys()) == ["data_a_|r0", "data_a_|r1", "data_a_|r2"]
assert f_A[0].value == 65.4711887279723
assert f_A[1].value == 1.0447210336915187
assert f_A[2].value == -41.025094911185185
def test_a_bi_external_idl_func_postfix(tmp_path):
build_test_environment(str(tmp_path), "apf", 5, 3)
def extract_idl(s: str) -> int:
return int(s.split("n")[-1][:-5])
f_A = sfin.read_sfcf(str(tmp_path) + "/data_apf", "data_apf", "f_A", quarks="lquark lquark", wf=0, version="2.0a", cfg_func=extract_idl)
print(f_A)
assert len(f_A) == 3
assert list(f_A[0].shape.keys()) == ["data_apf_|r0", "data_apf_|r1", "data_apf_|r2"]
assert f_A[0].value == 65.4711887279723
assert f_A[1].value == 1.0447210336915187
assert f_A[2].value == -41.025094911185185
def test_a_bi_files(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
f_A = sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "f_A", quarks="lquark lquark", wf=0, version="2.0a", files=["data_a_r0.f_A", "data_a_r1.f_A", "data_a_r2.f_A"])
@ -316,6 +364,31 @@ def test_a_bib(tmp_path):
assert f_V0[2] == 683.6776090081005
def test_a_bib_external_idl_func(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
def extract_idl(s: str) -> int:
return int(s.split("n")[-1])
f_V0 = sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "F_V0", quarks="lquark lquark", wf=0, wf2=0, version="2.0a", corr_type="bib", cfg_func=extract_idl)
print(f_V0)
assert len(f_V0) == 3
assert list(f_V0[0].shape.keys()) == ["data_a_|r0", "data_a_|r1", "data_a_|r2"]
assert f_V0[0] == 683.6776090085115
assert f_V0[1] == 661.3188585582334
assert f_V0[2] == 683.6776090081005
def test_a_bib_external_idl_func_postfix(tmp_path):
build_test_environment(str(tmp_path), "apf", 5, 3)
def extract_idl(s: str) -> int:
return int(s.split("n")[-1][:-5])
f_V0 = sfin.read_sfcf(str(tmp_path) + "/data_apf", "data_apf", "F_V0", quarks="lquark lquark", wf=0, wf2=0, version="2.0a", corr_type="bib", cfg_func=extract_idl)
print(f_V0)
assert len(f_V0) == 3
assert list(f_V0[0].shape.keys()) == ["data_apf_|r0", "data_apf_|r1", "data_apf_|r2"]
assert f_V0[0] == 683.6776090085115
assert f_V0[1] == 661.3188585582334
assert f_V0[2] == 683.6776090081005
def test_simple_multi_a(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
corrs = sfin.read_sfcf_multi(str(tmp_path) + "/data_a", "data_a", ["F_V0"], quarks_list=["lquark lquark"], wf1_list=[0], wf2_list=[0], version="2.0a", corr_type_list=["bib"])