pyerrors/docs/pyerrors.html

1354 lines
179 KiB
HTML
Raw Normal View History

2021-11-07 20:53:18 +00:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
2024-12-18 12:01:47 +00:00
<meta name="generator" content="pdoc 15.0.1"/>
2021-11-07 20:53:18 +00:00
<title>pyerrors API documentation</title>
2022-02-14 14:08:21 +00:00
<style>/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-fie
<style>/*! syntax-highlighting.css */pre{line-height:125%;}span.linenos{color:inherit; background-color:transparent; padding-left:5px; padding-right:20px;}.pdoc-code .hll{background-color:#ffffcc}.pdoc-code{background:#f8f8f8;}.pdoc-code .c{color:#3D7B7B; font-style:italic}.pdoc-code .err{border:1px solid #FF0000}.pdoc-code .k{color:#008000; font-weight:bold}.pdoc-code .o{color:#666666}.pdoc-code .ch{color:#3D7B7B; font-style:italic}.pdoc-code .cm{color:#3D7B7B; font-style:italic}.pdoc-code .cp{color:#9C6500}.pdoc-code .cpf{color:#3D7B7B; font-style:italic}.pdoc-code .c1{color:#3D7B7B; font-style:italic}.pdoc-code .cs{color:#3D7B7B; font-style:italic}.pdoc-code .gd{color:#A00000}.pdoc-code .ge{font-style:italic}.pdoc-code .gr{color:#E40000}.pdoc-code .gh{color:#000080; font-weight:bold}.pdoc-code .gi{color:#008400}.pdoc-code .go{color:#717171}.pdoc-code .gp{color:#000080; font-weight:bold}.pdoc-code .gs{font-weight:bold}.pdoc-code .gu{color:#800080; font-weight:bold}.pdoc-code .gt{color:#0044DD}.pdoc-code .kc{color:#008000; font-weight:bold}.pdoc-code .kd{color:#008000; font-weight:bold}.pdoc-code .kn{color:#008000; font-weight:bold}.pdoc-code .kp{color:#008000}.pdoc-code .kr{color:#008000; font-weight:bold}.pdoc-code .kt{color:#B00040}.pdoc-code .m{color:#666666}.pdoc-code .s{color:#BA2121}.pdoc-code .na{color:#687822}.pdoc-code .nb{color:#008000}.pdoc-code .nc{color:#0000FF; font-weight:bold}.pdoc-code .no{color:#880000}.pdoc-code .nd{color:#AA22FF}.pdoc-code .ni{color:#717171; font-weight:bold}.pdoc-code .ne{color:#CB3F38; font-weight:bold}.pdoc-code .nf{color:#0000FF}.pdoc-code .nl{color:#767600}.pdoc-code .nn{color:#0000FF; font-weight:bold}.pdoc-code .nt{color:#008000; font-weight:bold}.pdoc-code .nv{color:#19177C}.pdoc-code .ow{color:#AA22FF; font-weight:bold}.pdoc-code .w{color:#bbbbbb}.pdoc-code .mb{color:#666666}.pdoc-code .mf{color:#666666}.pdoc-code .mh{color:#666666}.pdoc-code .mi{color:#666666}.pdoc-code .mo{color:#666666}.pdoc-code .sa{color:#BA2121}.pdoc-code .sb{color:#BA2121}.pdoc-code .sc{color:#BA2121}.pdoc-code .dl{color:#BA2121}.pdoc-code .sd{color:#BA2121; font-style:italic}.pdoc-code .s2{color:#BA2121}.pdoc-code .se{color:#AA5D1F; font-weight:bold}.pdoc-code .sh{color:#BA2121}.pdoc-code .si{color:#A45A77; font-weight:bold}.pdoc-code .sx{color:#008000}.pdoc-code .sr{color:#A45A77}.pdoc-code .s1{color:#BA2121}.pdoc-code .ss{color:#19177C}.pdoc-code .bp{color:#008000}.pdoc-code .fm{color:#0000FF}.pdoc-code .vc{color:#19177C}.pdoc-code .vg{color:#19177C}.pdoc-code .vi{color:#19177C}.pdoc-code .vm{color:#19177C}.pdoc-code .il{color:#666666}</style>
<style>/*! theme.css */:root{--pdoc-background:#fff;}.pdoc{--text:#212529;--muted:#6c757d;--link:#3660a5;--link-hover:#1659c5;--code:#f8f8f8;--active:#fff598;--accent:#eee;--accent2:#c1c1c1;--nav-hover:rgba(255, 255, 255, 0.5);--name:#0066BB;--def:#008800;--annotation:#007020;}</style>
2023-09-15 07:03:59 +00:00
<style>/*! layout.css */html, body{width:100%;height:100%;}html, main{scroll-behavior:smooth;}body{background-color:var(--pdoc-background);}@media (max-width:769px){#navtoggle{cursor:pointer;position:absolute;width:50px;height:40px;top:1rem;right:1rem;border-color:var(--text);color:var(--text);display:flex;opacity:0.8;z-index:999;}#navtoggle:hover{opacity:1;}#togglestate + div{display:none;}#togglestate:checked + div{display:inherit;}main, header{padding:2rem 3vw;}header + main{margin-top:-3rem;}.git-button{display:none !important;}nav input[type="search"]{max-width:77%;}nav input[type="search"]:first-child{margin-top:-6px;}nav input[type="search"]:valid ~ *{display:none !important;}}@media (min-width:770px){:root{--sidebar-width:clamp(12.5rem, 28vw, 22rem);}nav{position:fixed;overflow:auto;height:100vh;width:var(--sidebar-width);}main, header{padding:3rem 2rem 3rem calc(var(--sidebar-width) + 3rem);width:calc(54rem + var(--sidebar-width));max-width:100%;}header + main{margin-top:-4rem;}#navtoggle{display:none;}}#togglestate{position:absolute;height:0;opacity:0;}nav.pdoc{--pad:clamp(0.5rem, 2vw, 1.75rem);--indent:1.5rem;background-color:var(--accent);border-right:1px solid var(--accent2);box-shadow:0 0 20px rgba(50, 50, 50, .2) inset;padding:0 0 0 var(--pad);overflow-wrap:anywhere;scrollbar-width:thin; scrollbar-color:var(--accent2) transparent; z-index:1}nav.pdoc::-webkit-scrollbar{width:.4rem; }nav.pdoc::-webkit-scrollbar-thumb{background-color:var(--accent2); }nav.pdoc > div{padding:var(--pad) 0;}nav.pdoc .module-list-button{display:inline-flex;align-items:center;color:var(--text);border-color:var(--muted);margin-bottom:1rem;}nav.pdoc .module-list-button:hover{border-color:var(--text);}nav.pdoc input[type=search]{display:block;outline-offset:0;width:calc(100% - var(--pad));}nav.pdoc .logo{max-width:calc(100% - var(--pad));max-height:35vh;display:block;margin:0 auto 1rem;transform:translate(calc(-.5 * var(--pad)), 0);}nav.pdoc ul{list-style:none;padding-left:0;}nav.pdoc > div > ul{margin-left:calc(0px - var(--pad));}nav.pdoc li a{padding:.2rem 0 .2rem calc(var(--pad) + var(--indent));}nav.pdoc > div > ul > li > a{padding-left:var(--pad);}nav.pdoc li{transition:all 100ms;}nav.pdoc li:hover{background-color:var(--nav-hover);}nav.pdoc a, nav.pdoc a:hover{color:var(--text);}nav.pdoc a{display:block;}nav.pdoc > h2:first-of-type{margin-top:1.5rem;}nav.pdoc .class:before{content:"class ";color:var(--muted);}nav.pdoc .function:after{content:"()";color:var(--muted);}nav.pdoc footer:before{content:"";display:block;width:calc(100% - var(--pad));border-top:solid var(--accent2) 1px;margin-top:1.5rem;padding-top:.5rem;}nav.pdoc footer{font-size:small;}</style>
2024-10-14 21:28:10 +00:00
<style>/*! content.css */.pdoc{color:var(--text);box-sizing:border-box;line-height:1.5;background:none;}.pdoc .pdoc-button{cursor:pointer;display:inline-block;border:solid black 1px;border-radius:2px;font-size:.75rem;padding:calc(0.5em - 1px) 1em;transition:100ms all;}.pdoc .alert{padding:1rem 1rem 1rem calc(1.5rem + 24px);border:1px solid transparent;border-radius:.25rem;background-repeat:no-repeat;background-position:.75rem center;margin-bottom:1rem;}.pdoc .alert > em{display:none;}.pdoc .alert > *:last-child{margin-bottom:0;}.pdoc .alert.note {color:#084298;background-color:#cfe2ff;border-color:#b6d4fe;background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23084298%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M8%2016A8%208%200%201%200%208%200a8%208%200%200%200%200%2016zm.93-9.412-1%204.705c-.07.34.029.533.304.533.194%200%20.487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703%200-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381%202.29-.287zM8%205.5a1%201%200%201%201%200-2%201%201%200%200%201%200%202z%22/%3E%3C/svg%3E");}.pdoc .alert.warning{color:#664d03;background-color:#fff3cd;border-color:#ffecb5;background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23664d03%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M8.982%201.566a1.13%201.13%200%200%200-1.96%200L.165%2013.233c-.457.778.091%201.767.98%201.767h13.713c.889%200%201.438-.99.98-1.767L8.982%201.566zM8%205c.535%200%20.954.462.9.995l-.35%203.507a.552.552%200%200%201-1.1%200L7.1%205.995A.905.905%200%200%201%208%205zm.002%206a1%201%200%201%201%200%202%201%201%200%200%201%200-2z%22/%3E%3C/svg%3E");}.pdoc .alert.danger{color:#842029;background-color:#f8d7da;border-color:#f5c2c7;background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23842029%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M5.52.359A.5.5%200%200%201%206%200h4a.5.5%200%200%201%20.474.658L8.694%206H12.5a.5.5%200%200%201%20.395.807l-7%209a.5.5%200%200%201-.873-.454L6.823%209.5H3.5a.5.5%200%200%201-.48-.641l2.5-8.5z%22/%3E%3C/svg%3E");}.pdoc .visually-hidden{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;margin:-1px !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;white-space:nowrap !important;border:0 !important;}.pdoc h1, .pdoc h2, .pdoc h3{font-weight:300;margin:.3em 0;padding:.2em 0;}.pdoc > section:not(.module-info) h1{font-size:1.5rem;font-weight:500;}.pdoc > section:not(.module-info) h2{font-size:1.4rem;font-weight:500;}.pdoc > section:not(.module-info) h3{font-size:1.3rem;font-weight:500;}.pdoc > section:not(.module-info) h4{font-size:1.2rem;}.pdoc > section:not(.module-info) h5{font-size:1.1rem;}.pdoc a{text-decoration:none;color:var(--link);}.pdoc a:hover{color:var(--link-hover);}.pdoc blockquote{margin-left:2rem;}.pdoc pre{border-top:1px solid var(--accent2);border-bottom:1px solid var(--accent2);margin-top:0;margin-bottom:1em;padding:.5rem 0 .5rem .5rem;overflow-x:auto;background-color:var(--code);}.pdoc code{color:var(--text);padding:.2em .4em;margin:0;font-size:85%;background-color:var(--accent);border-radius:6px;}.pdoc a > code{color:inherit;}.pdoc pre > code{display:inline-block;font-size:inherit;background:none;border:none;padding:0;}.pdoc > section:not(.module-info){margin-bottom:1.5rem;}.pdoc .modulename{margin-top:0;font-weight:bold;}.pdoc .modulename a{color:var(--link);transition:100ms all;}.pdoc .git-button{float:right;border:solid var(--link) 1px;}.pdoc .git-button:hover{background-color:var(--link);color:var(--pdoc-background);}.view-source-toggle-state,.view-source-toggle-state ~ .pdoc-code{display:none;}.view-source-toggle-state:checked ~ .pdoc-code{display:block;}.view-source-button{display:inline-block;float:right;font-size:.75rem;line-height:1.5rem;color:var(--muted);padding:0 .
2022-02-15 12:25:34 +00:00
<style>/*! custom.css */</style><script>
2021-11-07 20:53:18 +00:00
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script>
/* Re-invoke MathJax when DOM content changes, for example during search. */
document.addEventListener("DOMContentLoaded", () => {
new MutationObserver(() => MathJax.typeset()).observe(
document.querySelector("main.pdoc").parentNode,
{childList: true}
);
})
2022-11-13 20:04:54 +00:00
</script>
<style>
mjx-container {
overflow-x: auto;
2024-06-19 10:56:18 +00:00
overflow-y: hidden;
2022-11-13 20:04:54 +00:00
}
</style></head>
2022-02-14 14:08:21 +00:00
<body>
<nav class="pdoc">
<label id="navtoggle" for="togglestate" class="pdoc-button"><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke-linecap='round' stroke="currentColor" stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg></label>
<input id="togglestate" type="checkbox" aria-hidden="true" tabindex="-1">
<div>
<input type="search" placeholder="Search..." role="searchbox" aria-label="search"
pattern=".+" required>
2023-03-24 10:11:43 +00:00
<h2>Contents</h2>
<ul>
2021-11-07 20:53:18 +00:00
<li><a href="#what-is-pyerrors">What is pyerrors?</a>
<ul>
2023-03-13 13:29:24 +00:00
<li><a href="#installation">Installation</a></li>
2021-11-16 11:46:28 +00:00
<li><a href="#basic-example">Basic example</a></li>
2021-11-07 20:53:18 +00:00
</ul></li>
<li><a href="#the-obs-class">The <code>Obs</code> class</a>
<ul>
2021-11-09 11:51:27 +00:00
<li><a href="#error-propagation">Error propagation</a></li>
2022-01-16 15:44:50 +00:00
<li><a href="#error-estimation">Error estimation</a></li>
<li><a href="#multiple-ensemblesreplica">Multiple ensembles/replica</a></li>
2021-11-07 20:53:18 +00:00
<li><a href="#irregular-monte-carlo-chains">Irregular Monte Carlo chains</a></li>
</ul></li>
2021-11-07 21:09:48 +00:00
<li><a href="#correlators">Correlators</a></li>
2022-02-14 14:08:21 +00:00
<li><a href="#complex-valued-observables">Complex valued observables</a></li>
2022-02-22 09:51:41 +00:00
<li><a href="#the-covobs-class">The <code>Covobs</code> class</a></li>
2022-02-14 14:08:21 +00:00
<li><a href="#error-propagation-in-iterative-algorithms">Error propagation in iterative algorithms</a>
<ul>
<li><a href="#least-squares-fits">Least squares fits</a></li>
<li><a href="#total-least-squares-fits">Total least squares fits</a></li>
</ul></li>
2021-11-07 20:53:18 +00:00
<li><a href="#matrix-operations">Matrix operations</a></li>
2022-02-22 10:11:24 +00:00
<li><a href="#export-data">Export data</a>
<ul>
<li><a href="#jsongz-format-specification">json.gz format specification</a></li>
</ul></li>
2021-11-07 20:53:18 +00:00
</ul>
2023-03-24 10:11:43 +00:00
<h2>Submodules</h2>
<ul>
<li><a href="pyerrors/correlators.html">correlators</a></li>
<li><a href="pyerrors/covobs.html">covobs</a></li>
<li><a href="pyerrors/dirac.html">dirac</a></li>
<li><a href="pyerrors/fits.html">fits</a></li>
<li><a href="pyerrors/input.html">input</a></li>
2023-07-14 13:23:17 +00:00
<li><a href="pyerrors/integrate.html">integrate</a></li>
2023-03-24 10:11:43 +00:00
<li><a href="pyerrors/linalg.html">linalg</a></li>
<li><a href="pyerrors/misc.html">misc</a></li>
<li><a href="pyerrors/mpm.html">mpm</a></li>
<li><a href="pyerrors/obs.html">obs</a></li>
<li><a href="pyerrors/roots.html">roots</a></li>
2024-01-07 16:22:53 +00:00
<li><a href="pyerrors/special.html">special</a></li>
2023-03-24 10:11:43 +00:00
<li><a href="pyerrors/version.html">version</a></li>
</ul>
2022-02-14 14:08:21 +00:00
2022-04-29 09:14:53 +00:00
<a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev" target="_blank">
2022-02-14 14:08:21 +00:00
built with <span class="visually-hidden">pdoc</span><img
alt="pdoc logo"
src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20role%3D%22img%22%20aria-label%3D%22pdoc%20logo%22%20width%3D%22300%22%20height%3D%22150%22%20viewBox%3D%22-1%200%2060%2030%22%3E%3Ctitle%3Epdoc%3C/title%3E%3Cpath%20d%3D%22M29.621%2021.293c-.011-.273-.214-.475-.511-.481a.5.5%200%200%200-.489.503l-.044%201.393c-.097.551-.695%201.215-1.566%201.704-.577.428-1.306.486-2.193.182-1.426-.617-2.467-1.654-3.304-2.487l-.173-.172a3.43%203.43%200%200%200-.365-.306.49.49%200%200%200-.286-.196c-1.718-1.06-4.931-1.47-7.353.191l-.219.15c-1.707%201.187-3.413%202.131-4.328%201.03-.02-.027-.49-.685-.141-1.763.233-.721.546-2.408.772-4.076.042-.09.067-.187.046-.288.166-1.347.277-2.625.241-3.351%201.378-1.008%202.271-2.586%202.271-4.362%200-.976-.272-1.935-.788-2.774-.057-.094-.122-.18-.184-.268.033-.167.052-.339.052-.516%200-1.477-1.202-2.679-2.679-2.679-.791%200-1.496.352-1.987.9a6.3%206.3%200%200%200-1.001.029c-.492-.564-1.207-.929-2.012-.929-1.477%200-2.679%201.202-2.679%202.679A2.65%202.65%200%200%200%20.97%206.554c-.383.747-.595%201.572-.595%202.41%200%202.311%201.507%204.29%203.635%205.107-.037.699-.147%202.27-.423%203.294l-.137.461c-.622%202.042-2.515%208.257%201.727%2010.643%201.614.908%203.06%201.248%204.317%201.248%202.665%200%204.492-1.524%205.322-2.401%201.476-1.559%202.886-1.854%206.491.82%201.877%201.393%203.514%201.753%204.861%201.068%202.223-1.713%202.811-3.867%203.399-6.374.077-.846.056-1.469.054-1.537zm-4.835%204.313c-.054.305-.156.586-.242.629-.034-.007-.131-.022-.307-.157-.145-.111-.314-.478-.456-.908.221.121.432.25.675.355.115.039.219.051.33.081zm-2.251-1.238c-.05.33-.158.648-.252.694-.022.001-.125-.018-.307-.157-.217-.166-.488-.906-.639-1.573.358.344.754.693%201.198%201.036zm-3.887-2.337c-.006-.116-.018-.231-.041-.342.635.145%201.189.368%201.599.625.097.231.166.481.174.642-.03.049-.055.101-.067.158-.046.013-.128.026-.298.004-.278-.037-.901-.57-1.367-1.087zm-1.127-.497c.116.306.176.625.12.71-.019.014-.117.045-.345.016-.206-.027-.604-.332-.986-.695.41-.051.816-.056%201.211-.031zm-4.535%201.535c.209.22.379.47.358.598-.006.041-.088.138-.351.234-.144.055-.539-.063-.979-.259a11.66%2011.66%200%200%200%20.972-.573zm.983-.664c.359-.237.738-.418%201.126-.554.25.237.479.548.457.694-.006.042-.087.138-.351.235-.174.064-.694-.105-1.232-.375zm-3.381%201.794c-.022.145-.061.29-.149.401-.133.166-.358.248-.69.251h-.002c-.133%200-.306-.26-.45-.621.417.091.854.07%201.291-.031zm-2.066-8.077a4.78%204.78%200%200%201-.775-.584c.172-.115.505-.254.88-.378l-.105.962zm-.331%202.302a10.32%2010.32%200%200%201-.828-.502c.202-.143.576-.328.984-.49l-.156.992zm-.45%202.157l-.701-.403c.214-.115.536-.249.891-.376a11.57%2011.57%200%200%201-.19.779zm-.181%201.716c.064.398.194.702.298.893-.194-.051-.435-.162-.736-.398.061-.119.224-.3.438-.495zM8.87%204.141c0%20.152-.123.276-.276.276s-.275-.124-.275-.276.123-.276.276-.276.275.124.275.276zm-.735-.389a1.15%201.15%200%200%200-.314.783%201.16%201.16%200%200%200%201.162%201.162c.457%200%20.842-.27%201.032-.653.026.117.042.238.042.362a1.68%201.68%200%200%201-1.679%201.679%201.68%201.68%200%200%201-1.679-1.679c0-.843.626-1.535%201.436-1.654zM5.059%205.406A1.68%201.68%200%200%201%203.38%207.085a1.68%201.68%200%200%201-1.679-1.679c0-.037.009-.072.011-.109.21.3.541.508.935.508a1.16%201.16%200%200%200%201.162-1.162%201.14%201.14%200%200%200-.474-.912c.015%200%20.03-.005.045-.005.926.001%201.679.754%201.679%201.68zM3.198%204.141c0%20.152-.123.276-.276.276s-.275-.124-.275-.276.123-.276.276-.276.275.124.275.276zM1.375%208.964c0-.52.103-1.035.288-1.52.466.394%201.06.64%201.717.64%201.144%200%202.116-.725%202.499-1.738.383%201.012%201.355%201.738%202.499%201.738.867%200%201.631-.421%202.121-1.062.307.605.478%201.267.478%201.942%200%202.486-2.153%204.51-4.801%204.51s-4.801-2.023-4.801-4.51zm24.342%2019.349c-.985.498-2.267.168-3.813-.979-3.073-2.281-5.453-3.199-7.813-.705-1.315%201.391-4.163%203.365-8.423.97-3.174-1.786-2.239-6.266-1.261-9.479l.146-.492c.276-1.02.395-2.457.444-3.268a6.11%206.11%200%200%200%201.18.115%206.01%206.01%200%200%200%202.536-.562l-.006.175c-.802.215-1.848.612
</a>
</div>
</nav>
2021-11-07 20:53:18 +00:00
<main class="pdoc">
2022-05-09 12:41:30 +00:00
<section class="module-info">
2021-11-07 20:53:18 +00:00
<h1 class="modulename">
pyerrors </h1>
<div class="docstring"><h1 id="what-is-pyerrors">What is pyerrors?</h1>
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> is a python package for error computation and propagation of Markov chain Monte Carlo data.
2021-12-11 23:00:30 +00:00
It is based on the gamma method <a href="https://arxiv.org/abs/hep-lat/0306017">arXiv:hep-lat/0306017</a>. Some of its features are:</p>
2021-11-07 21:04:06 +00:00
<ul>
2022-07-19 12:00:42 +00:00
<li>automatic differentiation for exact linear error propagation as suggested in <a href="https://arxiv.org/abs/1809.01289">arXiv:1809.01289</a> (partly based on the <a href="https://github.com/HIPS/autograd">autograd</a> package).</li>
2021-12-11 23:00:30 +00:00
<li>treatment of slow modes in the simulation as suggested in <a href="https://arxiv.org/abs/1009.5228">arXiv:1009.5228</a>.</li>
<li>coherent error propagation for data from different Markov chains.</li>
<li>non-linear fits with x- and y-errors and exact linear error propagation based on automatic differentiation as introduced in <a href="https://arxiv.org/abs/1809.01289">arXiv:1809.01289</a>.</li>
<li>real and complex matrix operations and their error propagation based on automatic differentiation (Matrix inverse, Cholesky decomposition, calculation of eigenvalues and eigenvectors, singular value decomposition...).</li>
2021-11-07 21:04:06 +00:00
</ul>
2021-11-07 20:53:18 +00:00
2022-05-22 10:39:33 +00:00
<p>More detailed examples can found in the <a href="https://github.com/fjosw/pyerrors/tree/develop/examples">GitHub repository</a> <a href="https://mybinder.org/v2/gh/fjosw/pyerrors/HEAD?labpath=examples"><img src="https://img.shields.io/badge/-try%20it%20out-579ACA.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJXmsrfZ4TuhWn1olL1olJXmsqBi7X1olJXmspZmslbmMhbmsdemsVfl8ZgmsNim8Jpk8F0m7R4m7F5nLB6jbh7jbiDirOEibOGnKaMhq+PnaCVg6qWg6qegKaff6WhnpKofKGtnomxeZy3noG6dZi+n3vCcpPDcpPGn3bLb4/Mb47UbIrVa4rYoGjdaIbeaIXhoWHmZYHobXvpcHjqdHXreHLroVrsfG/uhGnuh2bwj2Hxk17yl1vzmljzm1j0nlX1olL3AJXWAAAAbXRSTlMAEBAQHx8gICAuLjAwMDw9PUBAQEpQUFBXV1hgYGBkcHBwcXl8gICAgoiIkJCQlJicnJ2goKCmqK+wsLC4usDAwMjP0NDQ1NbW3Nzg4ODi5+3v8PDw8/T09PX29vb39/f5+fr7+/z8/Pz9/v7+zczCxgAABC5JREFUeAHN1ul3k0UUBvCb1CTVpmpaitAGSLSpSuKCLWpbTKNJFGlcSMAFF63iUmRccNG6gLbuxkXU66JAUef/9LSpmXnyLr3T5AO/rzl5zj137p136BISy44fKJXuGN/d19PUfYeO67Znqtf2KH33Id1psXoFdW30sPZ1sMvs2D060AHqws4FHeJojLZqnw53cmfvg+XR8mC0OEjuxrXEkX5ydeVJLVIlV0e10PXk5k7dYeHu7Cj1j+49uKg7uLU61tGLw1lq27ugQYlclHC4bgv7VQ+TAyj5Zc/UjsPvs1sd5cWryWObtvWT2EPa4rtnWW3JkpjggEpbOsPr7F7EyNewtpBIslA7p43HCsnwooXTEc3UmPmCNn5lrqTJxy6nRmcavGZVt/3Da2pD5NHvsOHJCrdc1G2r3DITpU7yic7w/7Rxnjc0kt5GC4djiv2Sz3Fb2iEZg41/ddsFDoyuYrIkmFehz0HR2thPgQqMyQYb2OtB0WxsZ3BeG3+wpRb1vzl2UYBog8FfGhttFKjtAclnZYrRo9ryG9uG/FZQU4AEg8ZE9LjGMzTmqKXPLnlWVnIlQQTvxJf8ip7VgjZjyVPrjw1te5otM7RmP7xm+sK2Gv9I8Gi++BRbEkR9EBw8zRUcKxwp73xkaLiqQb+kGduJTNHG72zcW9LoJgqQxpP3/Tj//c3yB0tqzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC" alt="badge" /></a>.</p>
2022-09-30 15:31:21 +00:00
<p>If you use <code><a href="">pyerrors</a></code> for research that leads to a publication please consider citing:</p>
2022-06-24 15:20:34 +00:00
<ul>
2023-04-29 10:10:24 +00:00
<li>Fabian Joswig, Simon Kuberski, Justus T. Kuhlmann, Jan Neuendorf, <em>pyerrors: a python framework for error analysis of Monte Carlo data</em>. Comput.Phys.Commun. 288 (2023) 108750.</li>
2022-06-24 15:20:34 +00:00
<li>Ulli Wolff, <em>Monte Carlo errors with less errors</em>. Comput.Phys.Commun. 156 (2004) 143-153, Comput.Phys.Commun. 176 (2007) 383 (erratum).</li>
<li>Alberto Ramos, <em>Automatic differentiation for error analysis of Monte Carlo data</em>. Comput.Phys.Commun. 238 (2019) 19-35.</li>
</ul>
<p>and</p>
<ul>
<li>Stefan Schaefer, Rainer Sommer, Francesco Virotta, <em>Critical slowing down and error analysis in lattice QCD simulations</em>. Nucl.Phys.B 845 (2011) 93-119.</li>
</ul>
<p>where applicable.</p>
2021-12-11 23:00:30 +00:00
<p>There exist similar publicly available implementations of gamma method error analysis suites in <a href="https://gitlab.ift.uam-csic.es/alberto/aderrors">Fortran</a>, <a href="https://gitlab.ift.uam-csic.es/alberto/aderrors.jl">Julia</a> and <a href="https://github.com/mbruno46/pyobs">Python</a>.</p>
2021-11-30 14:58:46 +00:00
2023-03-13 13:29:24 +00:00
<h2 id="installation">Installation</h2>
<p>Install the most recent release using pip and <a href="https://pypi.org/project/pyerrors/">pypi</a>:</p>
<div class="pdoc-code codehilite">
2023-07-10 15:34:17 +00:00
<pre><span></span><code>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>pyerrors<span class="w"> </span><span class="c1"># Fresh install</span>
python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>-U<span class="w"> </span>pyerrors<span class="w"> </span><span class="c1"># Update</span>
2023-03-13 13:29:24 +00:00
</code></pre>
</div>
<p>Install the most recent release using conda and <a href="https://anaconda.org/conda-forge/pyerrors">conda-forge</a>:</p>
<div class="pdoc-code codehilite">
<pre><span></span><code>conda<span class="w"> </span>install<span class="w"> </span>-c<span class="w"> </span>conda-forge<span class="w"> </span>pyerrors<span class="w"> </span><span class="c1"># Fresh install</span>
conda<span class="w"> </span>update<span class="w"> </span>-c<span class="w"> </span>conda-forge<span class="w"> </span>pyerrors<span class="w"> </span><span class="c1"># Update</span>
</code></pre>
</div>
2023-03-13 13:32:03 +00:00
<p>Install the current <code>develop</code> version:</p>
<div class="pdoc-code codehilite">
2023-07-17 14:35:42 +00:00
<pre><span></span><code>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>-U<span class="w"> </span>--no-deps<span class="w"> </span>--force-reinstall<span class="w"> </span>git+https://github.com/fjosw/pyerrors.git@develop
2023-03-13 13:32:03 +00:00
</code></pre>
</div>
2023-07-17 14:35:42 +00:00
<p>(Also works for any feature branch).</p>
2021-11-16 11:46:28 +00:00
<h2 id="basic-example">Basic example</h2>
2021-11-07 20:53:18 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
2025-01-06 09:47:33 +00:00
<pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pyerrors</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pe</span>
2021-11-07 20:53:18 +00:00
2021-11-16 11:50:48 +00:00
<span class="n">my_obs</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble_name&#39;</span><span class="p">])</span> <span class="c1"># Initialize an Obs object</span>
2021-11-16 11:46:28 +00:00
<span class="n">my_new_obs</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">my_obs</span><span class="p">)</span> <span class="o">/</span> <span class="n">my_obs</span> <span class="o">**</span> <span class="mi">2</span> <span class="c1"># Construct derived Obs object</span>
2021-11-16 11:50:48 +00:00
<span class="n">my_new_obs</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">()</span> <span class="c1"># Estimate the statistical error</span>
<span class="nb">print</span><span class="p">(</span><span class="n">my_new_obs</span><span class="p">)</span> <span class="c1"># Print the result to stdout</span>
2021-11-15 13:13:15 +00:00
<span class="o">&gt;</span> <span class="mf">0.31498</span><span class="p">(</span><span class="mi">72</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-07 20:53:18 +00:00
<h1 id="the-obs-class">The <code>Obs</code> class</h1>
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> introduces a new datatype, <code>Obs</code>, which simplifies error propagation and estimation for auto- and cross-correlated data.
2022-02-21 14:52:31 +00:00
An <code>Obs</code> object can be initialized with two arguments, the first is a list containing the samples for an observable from a Monte Carlo chain.
2021-11-09 11:51:27 +00:00
The samples can either be provided as python list or as numpy array.
2023-01-24 13:10:49 +00:00
The second argument is a list containing the names of the respective Monte Carlo chains as strings. These strings uniquely identify a Monte Carlo chain/ensemble. <strong>It is crucial for the correct error propagation that observations from the same Monte Carlo history are labeled with the same name. See <a href="#multiple-ensemblesreplica">Multiple ensembles/replica</a> for details.</strong></p>
2021-11-09 11:51:27 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
2025-01-06 09:47:33 +00:00
<pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">pyerrors</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pe</span>
2021-11-07 20:53:18 +00:00
<span class="n">my_obs</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble_name&#39;</span><span class="p">])</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-07 20:53:18 +00:00
2021-11-09 11:51:27 +00:00
<h2 id="error-propagation">Error propagation</h2>
2022-02-21 14:52:31 +00:00
<p>When performing mathematical operations on <code>Obs</code> objects the correct error propagation is intrinsically taken care of using a first order Taylor expansion
2021-11-16 11:46:28 +00:00
$$\delta_f^i=\sum_\alpha \bar{f}_\alpha \delta_\alpha^i\,,\quad \delta_\alpha^i=a_\alpha^i-\bar{a}_\alpha\,,$$
2021-11-16 11:50:48 +00:00
as introduced in <a href="https://arxiv.org/abs/hep-lat/0306017">arXiv:hep-lat/0306017</a>.
The required derivatives $\bar{f}_\alpha$ are evaluated up to machine precision via automatic differentiation as suggested in <a href="https://arxiv.org/abs/1809.01289">arXiv:1809.01289</a>.</p>
2021-11-09 11:51:27 +00:00
<p>The <code>Obs</code> class is designed such that mathematical numpy functions can be used on <code>Obs</code> just as for regular floats.</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
2025-01-06 09:47:33 +00:00
<pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pyerrors</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pe</span>
2021-11-09 11:51:27 +00:00
<span class="n">my_obs1</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples1</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble_name&#39;</span><span class="p">])</span>
<span class="n">my_obs2</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples2</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble_name&#39;</span><span class="p">])</span>
<span class="n">my_sum</span> <span class="o">=</span> <span class="n">my_obs1</span> <span class="o">+</span> <span class="n">my_obs2</span>
<span class="n">my_m_eff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">my_obs1</span> <span class="o">/</span> <span class="n">my_obs2</span><span class="p">)</span>
2021-11-16 11:46:28 +00:00
<span class="n">iamzero</span> <span class="o">=</span> <span class="n">my_m_eff</span> <span class="o">-</span> <span class="n">my_m_eff</span>
<span class="c1"># Check that value and fluctuations are zero within machine precision</span>
<span class="nb">print</span><span class="p">(</span><span class="n">iamzero</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="kc">True</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-09 11:51:27 +00:00
<h2 id="error-estimation">Error estimation</h2>
2022-03-09 12:27:09 +00:00
<p>The error estimation within <code><a href="">pyerrors</a></code> is based on the gamma method introduced in <a href="https://arxiv.org/abs/hep-lat/0306017">arXiv:hep-lat/0306017</a>.
2021-11-15 15:17:23 +00:00
After having arrived at the derived quantity of interest the <code>gamma_method</code> can be called as detailed in the following example.</p>
2021-11-15 10:12:16 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_sum</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">()</span>
2021-11-15 15:17:23 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">my_sum</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mf">1.70</span><span class="p">(</span><span class="mi">57</span><span class="p">)</span>
2021-11-15 10:12:16 +00:00
<span class="n">my_sum</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
2021-11-15 15:17:23 +00:00
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">1.70000000e+00</span> <span class="o">+/-</span> <span class="mf">5.72046658e-01</span> <span class="o">+/-</span> <span class="mf">7.56746598e-02</span> <span class="p">(</span><span class="mf">33.650</span><span class="o">%</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">t_int</span> <span class="mf">2.71422900e+00</span> <span class="o">+/-</span> <span class="mf">6.40320983e-01</span> <span class="n">S</span> <span class="o">=</span> <span class="mf">2.00</span>
2021-11-15 10:43:47 +00:00
<span class="o">&gt;</span> <span class="mi">1000</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble_name&#39;</span> <span class="p">:</span> <span class="mi">1000</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">1000</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-15 10:12:16 +00:00
2023-07-10 15:34:17 +00:00
<p>The <code>gamma_method</code> is not automatically called after every intermediate step in order to prevent computational overhead.</p>
2021-11-15 15:50:10 +00:00
<p>We use the following definition of the integrated autocorrelation time established in <a href="https://link.springer.com/article/10.1007/BF01022990">Madras &amp; Sokal 1988</a>
2021-11-16 11:46:28 +00:00
$$\tau_\mathrm{int}=\frac{1}{2}+\sum_{t=1}^{W}\rho(t)\geq \frac{1}{2}\,.$$
2021-12-11 23:07:13 +00:00
The window $W$ is determined via the automatic windowing procedure described in <a href="https://arxiv.org/abs/hep-lat/0306017">arXiv:hep-lat/0306017</a>.
2021-11-15 15:50:10 +00:00
The standard value for the parameter $S$ of this automatic windowing procedure is $S=2$. Other values for $S$ can be passed to the <code>gamma_method</code> as parameter.</p>
2021-11-15 10:12:16 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_sum</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">(</span><span class="n">S</span><span class="o">=</span><span class="mf">3.0</span><span class="p">)</span>
2021-11-15 10:12:16 +00:00
<span class="n">my_sum</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
2021-11-15 15:17:23 +00:00
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">1.70000000e+00</span> <span class="o">+/-</span> <span class="mf">6.30675201e-01</span> <span class="o">+/-</span> <span class="mf">1.04585650e-01</span> <span class="p">(</span><span class="mf">37.099</span><span class="o">%</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">t_int</span> <span class="mf">3.29909703e+00</span> <span class="o">+/-</span> <span class="mf">9.77310102e-01</span> <span class="n">S</span> <span class="o">=</span> <span class="mf">3.00</span>
2021-11-15 10:43:47 +00:00
<span class="o">&gt;</span> <span class="mi">1000</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble_name&#39;</span> <span class="p">:</span> <span class="mi">1000</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">1000</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-15 10:12:16 +00:00
2022-09-27 09:11:55 +00:00
<p>The integrated autocorrelation time $\tau_\mathrm{int}$ and the autocorrelation function $\rho(W)$ can be monitored via the methods <code><a href="pyerrors/obs.html#Obs.plot_tauint">pyerrors.obs.Obs.plot_tauint</a></code> and <code><a href="pyerrors/obs.html#Obs.plot_rho">pyerrors.obs.Obs.plot_rho</a></code>.</p>
2021-11-15 10:12:16 +00:00
2022-07-19 12:00:42 +00:00
<p>If the parameter $S$ is set to zero it is assumed that the dataset does not exhibit any autocorrelation and the window size is chosen to be zero.
2021-11-17 13:43:40 +00:00
In this case the error estimate is identical to the sample standard error.</p>
2021-11-09 11:51:27 +00:00
<h3 id="exponential-tails">Exponential tails</h3>
2021-11-15 10:57:31 +00:00
<p>Slow modes in the Monte Carlo history can be accounted for by attaching an exponential tail to the autocorrelation function $\rho$ as suggested in <a href="https://arxiv.org/abs/1009.5228">arXiv:1009.5228</a>. The longest autocorrelation time in the history, $\tau_\mathrm{exp}$, can be passed to the <code>gamma_method</code> as parameter. In this case the automatic windowing procedure is vacated and the parameter $S$ does not affect the error estimate.</p>
2021-11-15 10:12:16 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_sum</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">(</span><span class="n">tau_exp</span><span class="o">=</span><span class="mf">7.2</span><span class="p">)</span>
2021-11-15 10:12:16 +00:00
<span class="n">my_sum</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
2021-11-15 15:17:23 +00:00
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">1.70000000e+00</span> <span class="o">+/-</span> <span class="mf">6.28097762e-01</span> <span class="o">+/-</span> <span class="mf">5.79077524e-02</span> <span class="p">(</span><span class="mf">36.947</span><span class="o">%</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">t_int</span> <span class="mf">3.27218667e+00</span> <span class="o">+/-</span> <span class="mf">7.99583654e-01</span> <span class="n">tau_exp</span> <span class="o">=</span> <span class="mf">7.20</span><span class="p">,</span> <span class="n">N_sigma</span> <span class="o">=</span> <span class="mi">1</span>
2021-11-15 10:43:47 +00:00
<span class="o">&gt;</span> <span class="mi">1000</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble_name&#39;</span> <span class="p">:</span> <span class="mi">1000</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">1000</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-15 10:12:16 +00:00
2021-12-11 23:07:13 +00:00
<p>For the full API see <code><a href="pyerrors/obs.html#Obs.gamma_method">pyerrors.obs.Obs.gamma_method</a></code>.</p>
2021-11-15 10:12:16 +00:00
2021-11-07 20:53:18 +00:00
<h2 id="multiple-ensemblesreplica">Multiple ensembles/replica</h2>
2021-11-15 10:57:31 +00:00
<p>Error propagation for multiple ensembles (Markov chains with different simulation parameters) is handled automatically. Ensembles are uniquely identified by their <code>name</code>.</p>
2021-11-08 14:53:27 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">obs1</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples1</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">])</span>
2021-11-09 12:09:45 +00:00
<span class="n">obs2</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples2</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble2&#39;</span><span class="p">])</span>
2021-11-08 14:53:27 +00:00
<span class="n">my_sum</span> <span class="o">=</span> <span class="n">obs1</span> <span class="o">+</span> <span class="n">obs2</span>
<span class="n">my_sum</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
2021-11-16 12:00:28 +00:00
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">2.00697958e+00</span>
2021-11-08 14:53:27 +00:00
<span class="o">&gt;</span> <span class="mi">1500</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">2</span> <span class="n">ensembles</span><span class="p">:</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble1&#39;</span> <span class="p">:</span> <span class="mi">1000</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">1000</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble2&#39;</span> <span class="p">:</span> <span class="mi">500</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">500</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-08 14:53:27 +00:00
2023-01-24 13:00:53 +00:00
<p>Observables from the <strong>same Monte Carlo chain</strong> have to be initialized with the <strong>same name</strong> for correct error propagation. If different names were used in this case the data would be treated as statistically independent resulting in loss of relevant information and a potential over or under estimate of the statistical error.</p>
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> identifies multiple replica (independent Markov chains with identical simulation parameters) by the vertical bar <code>|</code> in the name of the data set.</p>
2021-11-08 14:53:27 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">obs1</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples1</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1|r01&#39;</span><span class="p">])</span>
2021-11-09 12:09:45 +00:00
<span class="n">obs2</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples2</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1|r02&#39;</span><span class="p">])</span>
2021-11-08 14:53:27 +00:00
2021-11-15 09:55:51 +00:00
<span class="o">&gt;</span> <span class="n">my_sum</span> <span class="o">=</span> <span class="n">obs1</span> <span class="o">+</span> <span class="n">obs2</span>
<span class="o">&gt;</span> <span class="n">my_sum</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
2021-11-16 12:00:28 +00:00
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">2.00697958e+00</span>
2021-11-08 14:53:27 +00:00
<span class="o">&gt;</span> <span class="mi">1500</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2021-11-15 09:55:51 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble1&#39;</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Replicum</span> <span class="s1">&#39;r01&#39;</span> <span class="p">:</span> <span class="mi">1000</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">1000</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Replicum</span> <span class="s1">&#39;r02&#39;</span> <span class="p">:</span> <span class="mi">500</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">1</span> <span class="n">to</span> <span class="mi">500</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-08 14:53:27 +00:00
2021-11-15 10:12:16 +00:00
<h3 id="error-estimation-for-multiple-ensembles">Error estimation for multiple ensembles</h3>
2021-11-15 10:57:31 +00:00
<p>In order to keep track of different error analysis parameters for different ensembles one can make use of global dictionaries as detailed in the following example.</p>
2021-11-15 10:12:16 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="o">.</span><span class="n">S_dict</span><span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.5</span>
2021-11-15 10:12:16 +00:00
<span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="o">.</span><span class="n">tau_exp_dict</span><span class="p">[</span><span class="s1">&#39;ensemble2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">8.0</span>
<span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="o">.</span><span class="n">tau_exp_dict</span><span class="p">[</span><span class="s1">&#39;ensemble3&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.0</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-15 10:12:16 +00:00
2021-11-15 10:43:47 +00:00
<p>In case the <code>gamma_method</code> is called without any parameters it will use the values specified in the dictionaries for the respective ensembles.
Passing arguments to the <code>gamma_method</code> still dominates over the dictionaries.</p>
2021-11-07 20:53:18 +00:00
<h2 id="irregular-monte-carlo-chains">Irregular Monte Carlo chains</h2>
2022-01-21 14:55:18 +00:00
<p><code>Obs</code> objects defined on irregular Monte Carlo chains can be initialized with the parameter <code>idl</code>.</p>
2021-11-08 14:53:27 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="c1"># Observable defined on configurations 20 to 519</span>
2021-11-08 15:04:55 +00:00
<span class="n">obs1</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples1</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">],</span> <span class="n">idl</span><span class="o">=</span><span class="p">[</span><span class="nb">range</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">520</span><span class="p">)])</span>
2021-11-16 12:00:28 +00:00
<span class="n">obs1</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">9.98319881e-01</span>
<span class="o">&gt;</span> <span class="mi">500</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble1&#39;</span> <span class="p">:</span> <span class="mi">500</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">20</span> <span class="n">to</span> <span class="mi">519</span><span class="p">)</span>
2021-11-08 15:10:26 +00:00
2021-11-08 15:04:55 +00:00
<span class="c1"># Observable defined on every second configuration between 5 and 1003</span>
<span class="n">obs2</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples2</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">],</span> <span class="n">idl</span><span class="o">=</span><span class="p">[</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">1005</span><span class="p">,</span> <span class="mi">2</span><span class="p">)])</span>
2021-11-16 12:00:28 +00:00
<span class="n">obs2</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">9.99100712e-01</span>
<span class="o">&gt;</span> <span class="mi">500</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2025-01-06 09:47:33 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble1&#39;</span> <span class="p">:</span> <span class="mi">500</span> <span class="n">configurations</span> <span class="p">(</span><span class="kn">from</span><span class="w"> </span><span class="mi">5</span> <span class="n">to</span> <span class="mi">1003</span> <span class="ow">in</span> <span class="n">steps</span> <span class="n">of</span> <span class="mi">2</span><span class="p">)</span>
2021-11-08 15:10:26 +00:00
2021-11-08 15:04:55 +00:00
<span class="c1"># Observable defined on configurations 2, 9, 28, 29 and 501</span>
<span class="n">obs3</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples3</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">],</span> <span class="n">idl</span><span class="o">=</span><span class="p">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">28</span><span class="p">,</span> <span class="mi">29</span><span class="p">,</span> <span class="mi">501</span><span class="p">]])</span>
2021-11-16 12:00:28 +00:00
<span class="n">obs3</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">1.01718064e+00</span>
<span class="o">&gt;</span> <span class="mi">5</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Ensemble</span> <span class="s1">&#39;ensemble1&#39;</span> <span class="p">:</span> <span class="mi">5</span> <span class="n">configurations</span> <span class="p">(</span><span class="n">irregular</span> <span class="nb">range</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-08 14:53:27 +00:00
2022-02-21 17:51:14 +00:00
<p><code>Obs</code> objects defined on regular and irregular histories of the same ensemble can be combined with each other and the correct error propagation and estimation is automatically taken care of.</p>
2022-01-21 14:55:18 +00:00
2021-11-08 15:04:55 +00:00
<p><strong>Warning:</strong> Irregular Monte Carlo chains can result in odd patterns in the autocorrelation functions.
2021-11-15 10:57:31 +00:00
Make sure to check the autocorrelation time with e.g. <code><a href="pyerrors/obs.html#Obs.plot_rho">pyerrors.obs.Obs.plot_rho</a></code> or <code><a href="pyerrors/obs.html#Obs.plot_tauint">pyerrors.obs.Obs.plot_tauint</a></code>.</p>
2021-11-08 15:04:55 +00:00
2021-12-11 23:07:13 +00:00
<p>For the full API see <code><a href="pyerrors/obs.html#Obs">pyerrors.obs.Obs</a></code>.</p>
2021-11-07 20:53:18 +00:00
2021-11-09 11:51:27 +00:00
<h1 id="correlators">Correlators</h1>
2021-11-07 20:53:18 +00:00
2022-03-09 12:27:09 +00:00
<p>When one is not interested in single observables but correlation functions, <code><a href="">pyerrors</a></code> offers the <code>Corr</code> class which simplifies the corresponding error propagation and provides the user with a set of standard methods. In order to initialize a <code>Corr</code> objects one needs to arrange the data as a list of <code>Obs</code></p>
2021-12-23 15:43:56 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_corr</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Corr</span><span class="p">([</span><span class="n">obs_0</span><span class="p">,</span> <span class="n">obs_1</span><span class="p">,</span> <span class="n">obs_2</span><span class="p">,</span> <span class="n">obs_3</span><span class="p">])</span>
2021-12-23 15:43:56 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">my_corr</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">x0</span><span class="o">/</span><span class="n">a</span> <span class="n">Corr</span><span class="p">(</span><span class="n">x0</span><span class="o">/</span><span class="n">a</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="o">------------------</span>
<span class="o">&gt;</span> <span class="mi">0</span> <span class="mf">0.7957</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">1</span> <span class="mf">0.5156</span><span class="p">(</span><span class="mi">51</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">2</span> <span class="mf">0.3227</span><span class="p">(</span><span class="mi">33</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">3</span> <span class="mf">0.2041</span><span class="p">(</span><span class="mi">21</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-12-23 15:43:56 +00:00
<p>In case the correlation functions are not defined on the outermost timeslices, for example because of fixed boundary conditions, a padding can be introduced.</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_corr</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Corr</span><span class="p">([</span><span class="n">obs_0</span><span class="p">,</span> <span class="n">obs_1</span><span class="p">,</span> <span class="n">obs_2</span><span class="p">,</span> <span class="n">obs_3</span><span class="p">],</span> <span class="n">padding</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
2021-12-23 15:43:56 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">my_corr</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">x0</span><span class="o">/</span><span class="n">a</span> <span class="n">Corr</span><span class="p">(</span><span class="n">x0</span><span class="o">/</span><span class="n">a</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="o">------------------</span>
<span class="o">&gt;</span> <span class="mi">0</span>
<span class="o">&gt;</span> <span class="mi">1</span> <span class="mf">0.7957</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">2</span> <span class="mf">0.5156</span><span class="p">(</span><span class="mi">51</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">3</span> <span class="mf">0.3227</span><span class="p">(</span><span class="mi">33</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">4</span> <span class="mf">0.2041</span><span class="p">(</span><span class="mi">21</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">5</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-12-23 15:43:56 +00:00
<p>The individual entries of a correlator can be accessed via slicing</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="n">my_corr</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
2021-12-23 15:43:56 +00:00
<span class="o">&gt;</span> <span class="mf">0.3227</span><span class="p">(</span><span class="mi">33</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-12-23 15:43:56 +00:00
<p>Error propagation with the <code>Corr</code> class works very similar to <code>Obs</code> objects. Mathematical operations are overloaded and <code>Corr</code> objects can be computed together with other <code>Corr</code> objects, <code>Obs</code> objects or real numbers and integers.</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_new_corr</span> <span class="o">=</span> <span class="mf">0.3</span> <span class="o">*</span> <span class="n">my_corr</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">my_corr</span> <span class="o">*</span> <span class="n">my_corr</span> <span class="o">+</span> <span class="mi">12</span> <span class="o">/</span> <span class="n">my_corr</span>
</code></pre>
</div>
2021-12-23 15:43:56 +00:00
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> provides the user with a set of regularly used methods for the manipulation of correlator objects:</p>
2021-12-23 15:43:56 +00:00
<ul>
<li><code>Corr.gamma_method</code> applies the gamma method to all entries of the correlator.</li>
<li><code>Corr.m_eff</code> to construct effective masses. Various variants for periodic and fixed temporal boundary conditions are available.</li>
<li><code>Corr.deriv</code> returns the first derivative of the correlator as <code>Corr</code>. Different discretizations of the numerical derivative are available.</li>
<li><code>Corr.second_deriv</code> returns the second derivative of the correlator as <code>Corr</code>. Different discretizations of the numerical derivative are available.</li>
<li><code>Corr.symmetric</code> symmetrizes parity even correlations functions, assuming periodic boundary conditions.</li>
<li><code>Corr.anti_symmetric</code> anti-symmetrizes parity odd correlations functions, assuming periodic boundary conditions.</li>
<li><code>Corr.T_symmetry</code> averages a correlator with its time symmetry partner, assuming fixed boundary conditions.</li>
<li><code>Corr.plateau</code> extracts a plateau value from the correlator in a given range.</li>
<li><code>Corr.roll</code> periodically shifts the correlator.</li>
<li><code>Corr.reverse</code> reverses the time ordering of the correlator.</li>
<li><code>Corr.correlate</code> constructs a disconnected correlation function from the correlator and another <code>Corr</code> or <code>Obs</code> object.</li>
<li><code>Corr.reweight</code> reweights the correlator.</li>
</ul>
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> can also handle matrices of correlation functions and extract energy states from these matrices via a generalized eigenvalue problem (see <code><a href="pyerrors/correlators.html#Corr.GEVP">pyerrors.correlators.Corr.GEVP</a></code>).</p>
2021-12-23 15:43:56 +00:00
2021-12-11 23:07:13 +00:00
<p>For the full API see <code><a href="pyerrors/correlators.html#Corr">pyerrors.correlators.Corr</a></code>.</p>
2021-11-07 20:53:18 +00:00
2022-02-14 14:08:21 +00:00
<h1 id="complex-valued-observables">Complex valued observables</h1>
2021-11-07 21:09:48 +00:00
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> can handle complex valued observables via the class <code><a href="pyerrors/obs.html#CObs">pyerrors.obs.CObs</a></code>.
2021-11-15 14:59:01 +00:00
<code>CObs</code> are initialized with a real and an imaginary part which both can be <code>Obs</code> valued.</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_real_part</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples1</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">])</span>
2021-11-15 14:59:01 +00:00
<span class="n">my_imag_part</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples2</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;ensemble1&#39;</span><span class="p">])</span>
<span class="n">my_cobs</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">CObs</span><span class="p">(</span><span class="n">my_real_part</span><span class="p">,</span> <span class="n">my_imag_part</span><span class="p">)</span>
<span class="n">my_cobs</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">my_cobs</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="p">(</span><span class="mf">0.9959</span><span class="p">(</span><span class="mi">91</span><span class="p">)</span><span class="o">+</span><span class="mf">0.659</span><span class="p">(</span><span class="mi">28</span><span class="p">)</span><span class="n">j</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-15 14:59:01 +00:00
<p>Elementary mathematical operations are overloaded and samples are properly propagated as for the <code>Obs</code> class.</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_derived_cobs</span> <span class="o">=</span> <span class="p">(</span><span class="n">my_cobs</span> <span class="o">+</span> <span class="n">my_cobs</span><span class="o">.</span><span class="n">conjugate</span><span class="p">())</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">my_cobs</span><span class="p">)</span>
2021-11-15 14:59:01 +00:00
<span class="n">my_derived_cobs</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">my_derived_cobs</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="p">(</span><span class="mf">1.668</span><span class="p">(</span><span class="mi">23</span><span class="p">)</span><span class="o">+</span><span class="mf">0.0</span><span class="n">j</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-07 21:09:48 +00:00
2022-02-22 09:51:41 +00:00
<h1 id="the-covobs-class">The <code>Covobs</code> class</h1>
2022-03-09 12:27:09 +00:00
<p>In many projects, auxiliary data that is not based on Monte Carlo chains enters. Examples are experimentally determined mesons masses which are used to set the scale or renormalization constants. These numbers come with an error that has to be propagated through the analysis. The <code>Covobs</code> class allows to define such quantities in <code><a href="">pyerrors</a></code>. Furthermore, external input might consist of correlated quantities. An example are the parameters of an interpolation formula, which are defined via mean values and a covariance matrix between all parameters. The contribution of the interpolation formula to the error of a derived quantity therefore might depend on the complete covariance matrix.</p>
2022-02-22 09:51:41 +00:00
2023-07-10 15:34:17 +00:00
<p>This concept is built into the definition of <code>Covobs</code>. In <code><a href="">pyerrors</a></code>, external input is defined by $M$ mean values, a $M\times M$ covariance matrix, where $M=1$ is permissible, and a name that uniquely identifies the covariance matrix. Below, we define the pion mass, based on its mean value and error, 134.9768(5). <strong>Note, that the square of the error enters <code>cov_Obs</code></strong>, since the second argument of this function is the covariance matrix of the <code>Covobs</code>.</p>
2022-02-22 09:51:41 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
2025-01-06 09:47:33 +00:00
<pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn"><a href="pyerrors/obs.html">pyerrors.obs</a></span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pe</span>
2022-02-22 09:51:41 +00:00
<span class="n">mpi</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">cov_Obs</span><span class="p">(</span><span class="mf">134.9768</span><span class="p">,</span> <span class="mf">0.0005</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;pi^0 mass&#39;</span><span class="p">)</span>
<span class="n">mpi</span><span class="o">.</span><span class="n">gamma_method</span><span class="p">()</span>
<span class="n">mpi</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
<span class="o">&gt;</span> <span class="n">Result</span> <span class="mf">1.34976800e+02</span> <span class="o">+/-</span> <span class="mf">5.00000000e-04</span> <span class="o">+/-</span> <span class="mf">0.00000000e+00</span> <span class="p">(</span><span class="mf">0.000</span><span class="o">%</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">pi</span><span class="o">^</span><span class="mi">0</span> <span class="n">mass</span> <span class="mf">5.00000000e-04</span>
<span class="o">&gt;</span> <span class="mi">0</span> <span class="n">samples</span> <span class="ow">in</span> <span class="mi">1</span> <span class="n">ensemble</span><span class="p">:</span>
2022-02-22 09:58:49 +00:00
<span class="o">&gt;</span> <span class="err">·</span> <span class="n">Covobs</span> <span class="s1">&#39;pi^0 mass&#39;</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2022-02-22 09:51:41 +00:00
2022-02-22 09:58:49 +00:00
<p>The resulting object <code>mpi</code> is an <code>Obs</code> that contains a <code>Covobs</code>. In the following, it may be handled as any other <code>Obs</code>. The contribution of the covariance matrix to the error of an <code>Obs</code> is determined from the $M \times M$ covariance matrix $\Sigma$ and the gradient of the <code>Obs</code> with respect to the external quantities, which is the $1\times M$ Jacobian matrix $J$, via
2022-02-22 09:51:41 +00:00
$$s = \sqrt{J^T \Sigma J}\,,$$
2022-02-22 09:58:49 +00:00
where the Jacobian is computed for each derived quantity via automatic differentiation.</p>
2022-02-22 09:51:41 +00:00
<p>Correlated auxiliary data is defined similarly to above, e.g., via</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">RAP</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">cov_Obs</span><span class="p">([</span><span class="mf">16.7457</span><span class="p">,</span> <span class="o">-</span><span class="mf">19.0475</span><span class="p">],</span> <span class="p">[[</span><span class="mf">3.49591</span><span class="p">,</span> <span class="o">-</span><span class="mf">6.07560</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mf">6.07560</span><span class="p">,</span> <span class="mf">10.5834</span><span class="p">]],</span> <span class="s1">&#39;R_AP, 1906.03445, (5.3a)&#39;</span><span class="p">)</span>
2022-02-22 09:51:41 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">RAP</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="p">[</span><span class="n">Obs</span><span class="p">[</span><span class="mf">16.7</span><span class="p">(</span><span class="mf">1.9</span><span class="p">)],</span> <span class="n">Obs</span><span class="p">[</span><span class="o">-</span><span class="mf">19.0</span><span class="p">(</span><span class="mf">3.3</span><span class="p">)]]</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2022-02-22 09:51:41 +00:00
<p>where <code>RAP</code> now is a list of two <code>Obs</code> that contains the two correlated parameters.</p>
2022-02-22 09:58:49 +00:00
<p>Since the gradient of a derived observable with respect to an external covariance matrix is propagated through the entire analysis, the <code>Covobs</code> class allows to quote the derivative of a result with respect to the external quantities. If these derivatives are published together with the result, small shifts in the definition of external quantities, e.g., the definition of the physical point, can be performed a posteriori based on the published information. This may help to compare results of different groups. The gradient of an <code>Obs</code> <code>o</code> with respect to a covariance matrix with the identifying string <code>k</code> may be accessed via</p>
2022-02-22 09:51:41 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">o</span><span class="o">.</span><span class="n">covobs</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">grad</span>
</code></pre>
</div>
2022-02-22 09:51:41 +00:00
2022-02-14 14:08:21 +00:00
<h1 id="error-propagation-in-iterative-algorithms">Error propagation in iterative algorithms</h1>
2022-07-19 12:00:42 +00:00
<p><code><a href="">pyerrors</a></code> supports exact linear error propagation for iterative algorithms like various variants of non-linear least squares fits or root finding. The derivatives required for the error propagation are calculated as described in <a href="https://arxiv.org/abs/1809.01289">arXiv:1809.01289</a>.</p>
2022-02-14 14:08:21 +00:00
<h2 id="least-squares-fits">Least squares fits</h2>
<p>Standard non-linear least square fits with errors on the dependent but not the independent variables can be performed with <code><a href="pyerrors/fits.html#least_squares">pyerrors.fits.least_squares</a></code>. As default solver the Levenberg-Marquardt algorithm implemented in <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html">scipy</a> is used.</p>
<p>Fit functions have to be of the following form</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
2025-01-06 09:47:33 +00:00
<pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">autograd.numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">anp</span>
2022-02-14 14:08:21 +00:00
2025-01-06 09:47:33 +00:00
<span class="k">def</span><span class="w"> </span><span class="nf">func</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
2022-02-14 14:08:21 +00:00
<span class="k">return</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">anp</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">x</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2022-02-14 14:08:21 +00:00
2022-02-21 14:52:31 +00:00
<p><strong>It is important that numerical functions refer to <code>autograd.numpy</code> instead of <code>numpy</code> for the automatic differentiation in iterative algorithms to work properly.</strong></p>
2022-02-14 14:08:21 +00:00
<p>Fits can then be performed via</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">fit_result</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">fits</span><span class="o">.</span><span class="n">least_squares</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">func</span><span class="p">)</span>
2022-02-14 14:08:21 +00:00
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">fit_result</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">Fit</span> <span class="k">with</span> <span class="mi">2</span> <span class="n">parameters</span>
<span class="o">&gt;</span> <span class="n">Method</span><span class="p">:</span> <span class="n">Levenberg</span><span class="o">-</span><span class="n">Marquardt</span>
<span class="o">&gt;</span> <span class="err">`</span><span class="n">ftol</span><span class="err">`</span> <span class="n">termination</span> <span class="n">condition</span> <span class="ow">is</span> <span class="n">satisfied</span><span class="o">.</span>
<span class="o">&gt;</span> <span class="n">chisquare</span><span class="o">/</span><span class="n">d</span><span class="o">.</span><span class="n">o</span><span class="o">.</span><span class="n">f</span><span class="o">.</span><span class="p">:</span> <span class="mf">0.9593035785160936</span>
<span class="o">&gt;</span> <span class="n">Goodness</span> <span class="n">of</span> <span class="n">fit</span><span class="p">:</span>
<span class="o">&gt;</span> <span class="n">χ</span><span class="err">²</span><span class="o">/</span><span class="n">d</span><span class="o">.</span><span class="n">o</span><span class="o">.</span><span class="n">f</span><span class="o">.</span> <span class="o">=</span> <span class="mf">0.959304</span>
<span class="o">&gt;</span> <span class="n">p</span><span class="o">-</span><span class="n">value</span> <span class="o">=</span> <span class="mf">0.5673</span>
<span class="o">&gt;</span> <span class="n">Fit</span> <span class="n">parameters</span><span class="p">:</span>
<span class="o">&gt;</span> <span class="mi">0</span> <span class="mf">0.0548</span><span class="p">(</span><span class="mi">28</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="mi">1</span> <span class="mf">1.933</span><span class="p">(</span><span class="mi">64</span><span class="p">)</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2022-02-14 14:08:21 +00:00
<p>where x is a <code>list</code> or <code>numpy.array</code> of <code>floats</code> and y is a <code>list</code> or <code>numpy.array</code> of <code>Obs</code>.</p>
<p>Data stored in <code>Corr</code> objects can be fitted directly using the <code>Corr.fit</code> method.</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_corr</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Corr</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
2022-02-14 14:08:21 +00:00
<span class="n">fit_result</span> <span class="o">=</span> <span class="n">my_corr</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">fitrange</span><span class="o">=</span><span class="p">[</span><span class="mi">12</span><span class="p">,</span> <span class="mi">25</span><span class="p">])</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2022-02-14 14:08:21 +00:00
<p>this can simplify working with absolute fit ranges and takes care of gaps in the data automatically.</p>
<p>For fit functions with multiple independent variables the fit function can be of the form</p>
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
2025-01-06 09:47:33 +00:00
<pre><span></span><code><span class="k">def</span><span class="w"> </span><span class="nf">func</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
2022-02-14 14:08:21 +00:00
<span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">)</span> <span class="o">=</span> <span class="n">x</span>
<span class="k">return</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">x1</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">x2</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2021-11-07 20:53:18 +00:00
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> also supports correlated fits which can be triggered via the parameter <code>correlated_fit=True</code>.
2023-07-10 15:34:17 +00:00
Details about how the required covariance matrix is estimated can be found in <code><a href="pyerrors/obs.html#covariance">pyerrors.obs.covariance</a></code>.
Direct visualizations of the performed fits can be triggered via <code>resplot=True</code> or <code>qqplot=True</code>.</p>
2022-03-05 08:14:33 +00:00
2023-07-10 15:34:17 +00:00
<p>For all available options including combined fits to multiple datasets see <code><a href="pyerrors/fits.html#least_squares">pyerrors.fits.least_squares</a></code>.</p>
2022-03-05 08:14:33 +00:00
2022-02-14 14:08:21 +00:00
<h2 id="total-least-squares-fits">Total least squares fits</h2>
2023-07-10 15:34:17 +00:00
<p><code><a href="">pyerrors</a></code> can also fit data with errors on both the dependent and independent variables using the total least squares method also referred to as orthogonal distance regression as implemented in <a href="https://docs.scipy.org/doc/scipy/reference/odr.html">scipy</a>, see <code><a href="pyerrors/fits.html#least_squares">pyerrors.fits.least_squares</a></code>. The syntax is identical to the standard least squares case, the only difference being that <code>x</code> also has to be a <code>list</code> or <code>numpy.array</code> of <code>Obs</code>.</p>
2022-02-14 14:08:21 +00:00
2022-03-09 12:27:09 +00:00
<p>For the full API see <code><a href="pyerrors/fits.html">pyerrors.fits</a></code> for fits and <code><a href="pyerrors/roots.html">pyerrors.roots</a></code> for finding roots of functions.</p>
2021-11-07 21:09:48 +00:00
2021-11-07 20:53:18 +00:00
<h1 id="matrix-operations">Matrix operations</h1>
2022-03-09 12:27:09 +00:00
<p><code><a href="">pyerrors</a></code> provides wrappers for <code>Obs</code>- and <code>CObs</code>-valued matrix operations based on <code>numpy.linalg</code>. The supported functions include:</p>
2022-01-21 14:55:18 +00:00
<ul>
<li><code>inv</code> for the matrix inverse.</li>
<li><code>cholseky</code> for the Cholesky decomposition.</li>
<li><code>det</code> for the matrix determinant.</li>
<li><code>eigh</code> for eigenvalues and eigenvectors of hermitean matrices.</li>
<li><code>eig</code> for eigenvalues of general matrices.</li>
<li><code>pinv</code> for the Moore-Penrose pseudoinverse.</li>
<li><code>svd</code> for the singular-value-decomposition.</li>
</ul>
2022-03-09 12:27:09 +00:00
<p>For the full API see <code><a href="pyerrors/linalg.html">pyerrors.linalg</a></code>.</p>
2021-11-07 21:09:48 +00:00
2021-11-15 14:30:41 +00:00
<h1 id="export-data">Export data</h1>
2023-03-13 16:35:05 +00:00
<p><a href="https://xkcd.com/927/"><img src="https://imgs.xkcd.com/comics/standards_2x.png" width="75%" height="75%"></a></p>
2023-03-13 16:21:47 +00:00
2022-03-09 12:27:09 +00:00
<p>The preferred exported file format within <code><a href="">pyerrors</a></code> is json.gz. Files written to this format are valid JSON files that have been compressed using gzip. The structure of the content is inspired by the dobs format of the ALPHA collaboration. The aim of the format is to facilitate the storage of data in a self-contained way such that, even years after the creation of the file, it is possible to extract all necessary information:</p>
2022-02-21 17:51:14 +00:00
<ul>
<li>What observables are stored? Possibly: How exactly are they defined.</li>
<li>How does each single ensemble or external quantity contribute to the error of the observable?</li>
<li>Who did write the file when and on which machine?</li>
</ul>
2022-03-09 12:27:09 +00:00
<p>This can be achieved by storing all information in one single file. The export routines of <code><a href="">pyerrors</a></code> are written such that as much information as possible is written automatically as described in the following example</p>
2022-02-22 10:11:24 +00:00
2022-09-27 09:06:57 +00:00
<div class="pdoc-code codehilite">
<pre><span></span><code><span class="n">my_obs</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">Obs</span><span class="p">([</span><span class="n">samples</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;test_ensemble&quot;</span><span class="p">])</span>
2022-02-22 10:11:24 +00:00
<span class="n">my_obs</span><span class="o">.</span><span class="n">tag</span> <span class="o">=</span> <span class="s2">&quot;My observable&quot;</span>
<span class="n">pe</span><span class="o">.</span><span class="n">input</span><span class="o">.</span><span class="n">json</span><span class="o">.</span><span class="n">dump_to_json</span><span class="p">(</span><span class="n">my_obs</span><span class="p">,</span> <span class="s2">&quot;test_output_file&quot;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s2">&quot;This file contains a test observable&quot;</span><span class="p">)</span>
<span class="c1"># For a single observable one can equivalently use the class method dump</span>
2022-02-22 10:16:37 +00:00
<span class="n">my_obs</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="s2">&quot;test_output_file&quot;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s2">&quot;This file contains a test observable&quot;</span><span class="p">)</span>
2022-02-22 10:11:24 +00:00
<span class="n">check</span> <span class="o">=</span> <span class="n">pe</span><span class="o">.</span><span class="n">input</span><span class="o">.</span><span class="n">json</span><span class="o">.</span><span class="n">load_json</span><span class="p">(</span><span class="s2">&quot;test_output_file&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">my_obs</span> <span class="o">==</span> <span class="n">check</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="kc">True</span>
2022-09-27 09:06:57 +00:00
</code></pre>
</div>
2022-02-22 10:11:24 +00:00
2022-02-22 10:16:37 +00:00
<p>The format also allows to directly write out the content of <code>Corr</code> objects or lists and arrays of <code>Obs</code> objects by passing the desired data to <code><a href="pyerrors/input/json.html#dump_to_json">pyerrors.input.json.dump_to_json</a></code>.</p>
2022-02-22 10:11:24 +00:00
<h2 id="jsongz-format-specification">json.gz format specification</h2>
<p>The first entries of the file provide optional auxiliary information:</p>
2022-02-21 17:51:14 +00:00
<ul>
<li><code>program</code> is a string that indicates which program was used to write the file.</li>
<li><code>version</code> is a string that specifies the version of the format.</li>
<li><code>who</code> is a string that specifies the user name of the creator of the file.</li>
<li><code>date</code> is a string and contains the creation date of the file.</li>
<li><code>host</code> is a string and contains the hostname of the machine where the file has been written.</li>
2022-03-09 12:27:09 +00:00
<li><code>description</code> contains information on the content of the file. This field is not filled automatically in <code><a href="">pyerrors</a></code>. The user is advised to provide as detailed information as possible in this field. Examples are: Input files of measurements or simulations, LaTeX formulae or references to publications to specify how the observables have been computed, details on the analysis strategy, ... This field may be any valid JSON type. Strings, arrays or objects (equivalent to dicts in python) are well suited to provide information.</li>
2022-02-21 17:51:14 +00:00
</ul>
2022-02-21 18:07:44 +00:00
<p>The only necessary entry of the file is the field
2022-02-21 17:51:14 +00:00
-<code>obsdata</code>, an array that contains the actual data.</p>
2022-02-21 18:07:44 +00:00
<p>Each entry of the array belongs to a single structure of observables. Currently, these structures can be either of <code>Obs</code>, <code>list</code>, <code>numpy.ndarray</code>, <code>Corr</code>. All <code>Obs</code> inside a structure (with dimension &gt; 0) have to be defined on the same set of configurations. Different structures, that are represented by entries of the array <code>obsdata</code>, are treated independently. Each entry of the array <code>obsdata</code> has the following required entries:</p>
2022-02-21 17:51:14 +00:00
<ul>
<li><code>type</code> is a string that specifies the type of the structure. This allows to parse the content to the correct form after reading the file. It is always possible to interpret the content as list of Obs.</li>
<li><code>value</code> is an array that contains the mean values of the Obs inside the structure.
The following entries are optional:</li>
<li><code>layout</code> is a string that specifies the layout of multi-dimensional structures. Examples are "2, 2" for a 2x2 dimensional matrix or "64, 4, 4" for a Corr with $T=64$ and 4x4 matrices on each time slices. "1" denotes a single Obs. Multi-dimensional structures are stored in row-major format (see below).</li>
2022-03-09 12:27:09 +00:00
<li><code>tag</code> is any JSON type. It contains additional information concerning the structure. The <code>tag</code> of an <code>Obs</code> in <code><a href="">pyerrors</a></code> is written here.</li>
2022-02-21 17:51:14 +00:00
<li><code>reweighted</code> is a Bool that may be used to specify, whether the <code>Obs</code> in the structure have been reweighted.</li>
<li><code>data</code> is an array that contains the data from MC chains. We will define it below.</li>
2022-03-09 12:27:09 +00:00
<li><code>cdata</code> is an array that contains the data from external quantities with an error (<code>Covobs</code> in <code><a href="">pyerrors</a></code>). We will define it below.</li>
2022-02-21 17:51:14 +00:00
</ul>
<p>The array <code>data</code> contains the data from MC chains. Each entry of the array corresponds to one ensemble and contains:</p>
<ul>
<li><code>id</code>, a string that contains the name of the ensemble</li>
2022-02-21 18:07:44 +00:00
<li><code>replica</code>, an array that contains an entry per replica of the ensemble.</li>
2022-02-21 17:51:14 +00:00
</ul>
<p>Each entry of <code>replica</code> contains
<code>name</code>, a string that contains the name of the replica
2022-02-21 18:07:44 +00:00
<code>deltas</code>, an array that contains the actual data.</p>
2022-02-21 17:51:14 +00:00
<p>Each entry in <code>deltas</code> corresponds to one configuration of the replica and has $1+N$ many entries. The first entry is an integer that specifies the configuration number that, together with ensemble and replica name, may be used to uniquely identify the configuration on which the data has been obtained. The following N entries specify the deltas, i.e., the deviation of the observable from the mean value on this configuration, of each <code>Obs</code> inside the structure. Multi-dimensional structures are stored in a row-major format. For primary observables, such as correlation functions, $value + delta_i$ matches the primary data obtained on the configuration.</p>
2022-03-09 12:27:09 +00:00
<p>The array <code>cdata</code> contains information about the contribution of auxiliary observables, represented by <code>Covobs</code> in <code><a href="">pyerrors</a></code>, to the total error of the observables. Each entry of the array belongs to one auxiliary covariance matrix and contains:</p>
2022-02-21 17:51:14 +00:00
<ul>
<li><code>id</code>, a string that identifies the covariance matrix</li>
<li><code>layout</code>, a string that defines the dimensions of the $M\times M$ covariance matrix (has to be "M, M" or "1").</li>
<li><code>cov</code>, an array that contains the $M\times M$ many entries of the covariance matrix, stored in row-major format.</li>
<li><code>grad</code>, an array that contains N entries, one for each <code>Obs</code> inside the structure. Each entry itself is an array, that contains the M gradients of the Nth observable with respect to the quantity that corresponds to the Mth diagonal entry of the covariance matrix.</li>
</ul>
<p>A JSON schema that may be used to verify the correctness of a file with respect to the format definition is stored in ./examples/json_schema.json. The schema is a self-descriptive format definition and contains an exemplary file.</p>
2021-11-15 14:30:41 +00:00
2022-02-21 18:07:44 +00:00
<p>Julia I/O routines for the json.gz format, compatible with <a href="https://gitlab.ift.uam-csic.es/alberto/aderrors.jl">ADerrors.jl</a>, can be found <a href="https://github.com/fjosw/ADjson.jl">here</a>.</p>
2021-11-07 20:53:18 +00:00
</div>
2022-09-27 09:06:57 +00:00
<input id="mod-pyerrors-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
2022-05-16 09:57:06 +00:00
2022-09-27 09:06:57 +00:00
<label class="view-source-button" for="mod-pyerrors-view-source"><span>View Source</span></label>
2022-05-16 09:57:06 +00:00
<div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="sa">r</span><span class="sd">&#39;&#39;&#39;</span>
</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a><span class="sd"># What is pyerrors?</span>
</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="sd">`pyerrors` is a python package for error computation and propagation of Markov chain Monte Carlo data.</span>
</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a><span class="sd">It is based on the gamma method [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017). Some of its features are:</span>
2022-07-19 12:00:42 +00:00
</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="sd">- automatic differentiation for exact linear error propagation as suggested in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289) (partly based on the [autograd](https://github.com/HIPS/autograd) package).</span>
2022-05-16 09:57:06 +00:00
</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a><span class="sd">- treatment of slow modes in the simulation as suggested in [arXiv:1009.5228](https://arxiv.org/abs/1009.5228).</span>
</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a><span class="sd">- coherent error propagation for data from different Markov chains.</span>
</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="sd">- non-linear fits with x- and y-errors and exact linear error propagation based on automatic differentiation as introduced in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289).</span>
</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a><span class="sd">- real and complex matrix operations and their error propagation based on automatic differentiation (Matrix inverse, Cholesky decomposition, calculation of eigenvalues and eigenvectors, singular value decomposition...).</span>
</span><span id="L-10"><a href="#L-10"><span class="linenos"> 10</span></a>
2022-05-22 10:39:33 +00:00
</span><span id="L-11"><a href="#L-11"><span class="linenos"> 11</span></a><span class="sd">More detailed examples can found in the [GitHub repository](https://github.com/fjosw/pyerrors/tree/develop/examples) [![badge](https://img.shields.io/badge/-try%20it%20out-579ACA.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJXmsrfZ4TuhWn1olL1olJXmsqBi7X1olJXmspZmslbmMhbmsdemsVfl8ZgmsNim8Jpk8F0m7R4m7F5nLB6jbh7jbiDirOEibOGnKaMhq+PnaCVg6qWg6qegKaff6WhnpKofKGtnomxeZy3noG6dZi+n3vCcpPDcpPGn3bLb4/Mb47UbIrVa4rYoGjdaIbeaIXhoWHmZYHobXvpcHjqdHXreHLroVrsfG/uhGnuh2bwj2Hxk17yl1vzmljzm1j0nlX1olL3AJXWAAAAbXRSTlMAEBAQHx8gICAuLjAwMDw9PUBAQEpQUFBXV1hgYGBkcHBwcXl8gICAgoiIkJCQlJicnJ2goKCmqK+wsLC4usDAwMjP0NDQ1NbW3Nzg4ODi5+3v8PDw8/T09PX29vb39/f5+fr7+/z8/Pz9/v7+zczCxgAABC5JREFUeAHN1ul3k0UUBvCb1CTVpmpaitAGSLSpSuKCLWpbTKNJFGlcSMAFF63iUmRccNG6gLbuxkXU66JAUef/9LSpmXnyLr3T5AO/rzl5zj137p136BISy44fKJXuGN/d19PUfYeO67Znqtf2KH33Id1psXoFdW30sPZ1sMvs2D060AHqws4FHeJojLZqnw53cmfvg+XR8mC0OEjuxrXEkX5ydeVJLVIlV0e10PXk5k7dYeHu7Cj1j+49uKg7uLU61tGLw1lq27ugQYlclHC4bgv7VQ+TAyj5Zc/UjsPvs1sd5cWryWObtvWT2EPa4rtnWW3JkpjggEpbOsPr7F7EyNewtpBIslA7p43HCsnwooXTEc3UmPmCNn5lrqTJxy6nRmcavGZVt/3Da2pD5NHvsOHJCrdc1G2r3DITpU7yic7w/7Rxnjc0kt5GC4djiv2Sz3Fb2iEZg41/ddsFDoyuYrIkmFehz0HR2thPgQqMyQYb2OtB0WxsZ3BeG3+wpRb1vzl2UYBog8FfGhttFKjtAclnZYrRo9ryG9uG/FZQU4AEg8ZE9LjGMzTmqKXPLnlWVnIlQQTvxJf8ip7VgjZjyVPrjw1te5otM7RmP7xm+sK2Gv9I8Gi++BRbEkR9EBw8zRUcKxwp73xkaLiqQb+kGduJTNHG72zcW9LoJgqQxpP3/Tj//c3yB0tqzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC)](https://mybinder.org/v2/gh/fjosw/pyerrors/HEAD?labpath=examples).</span>
2022-05-16 09:57:06 +00:00
</span><span id="L-12"><a href="#L-12"><span class="linenos"> 12</span></a>
2022-06-24 15:20:34 +00:00
</span><span id="L-13"><a href="#L-13"><span class="linenos"> 13</span></a><span class="sd">If you use `pyerrors` for research that leads to a publication please consider citing:</span>
2023-04-29 10:10:24 +00:00
</span><span id="L-14"><a href="#L-14"><span class="linenos"> 14</span></a><span class="sd">- Fabian Joswig, Simon Kuberski, Justus T. Kuhlmann, Jan Neuendorf, *pyerrors: a python framework for error analysis of Monte Carlo data*. Comput.Phys.Commun. 288 (2023) 108750.</span>
2022-09-30 15:27:14 +00:00
</span><span id="L-15"><a href="#L-15"><span class="linenos"> 15</span></a><span class="sd">- Ulli Wolff, *Monte Carlo errors with less errors*. Comput.Phys.Commun. 156 (2004) 143-153, Comput.Phys.Commun. 176 (2007) 383 (erratum).</span>
</span><span id="L-16"><a href="#L-16"><span class="linenos"> 16</span></a><span class="sd">- Alberto Ramos, *Automatic differentiation for error analysis of Monte Carlo data*. Comput.Phys.Commun. 238 (2019) 19-35.</span>
</span><span id="L-17"><a href="#L-17"><span class="linenos"> 17</span></a>
</span><span id="L-18"><a href="#L-18"><span class="linenos"> 18</span></a><span class="sd">and</span>
</span><span id="L-19"><a href="#L-19"><span class="linenos"> 19</span></a>
</span><span id="L-20"><a href="#L-20"><span class="linenos"> 20</span></a><span class="sd">- Stefan Schaefer, Rainer Sommer, Francesco Virotta, *Critical slowing down and error analysis in lattice QCD simulations*. Nucl.Phys.B 845 (2011) 93-119.</span>
</span><span id="L-21"><a href="#L-21"><span class="linenos"> 21</span></a>
</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</span></a><span class="sd">where applicable.</span>
</span><span id="L-23"><a href="#L-23"><span class="linenos"> 23</span></a>
</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a><span class="sd">There exist similar publicly available implementations of gamma method error analysis suites in [Fortran](https://gitlab.ift.uam-csic.es/alberto/aderrors), [Julia](https://gitlab.ift.uam-csic.es/alberto/aderrors.jl) and [Python](https://github.com/mbruno46/pyobs).</span>
</span><span id="L-25"><a href="#L-25"><span class="linenos"> 25</span></a>
2023-03-13 13:29:24 +00:00
</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a><span class="sd">## Installation</span>
2022-09-30 15:27:14 +00:00
</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a>
2023-03-13 13:29:24 +00:00
</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a><span class="sd">Install the most recent release using pip and [pypi](https://pypi.org/project/pyerrors/):</span>
</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a><span class="sd">```bash</span>
2023-07-10 15:34:17 +00:00
</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a><span class="sd">python -m pip install pyerrors # Fresh install</span>
</span><span id="L-31"><a href="#L-31"><span class="linenos"> 31</span></a><span class="sd">python -m pip install -U pyerrors # Update</span>
2023-03-13 13:29:24 +00:00
</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a><span class="sd">```</span>
</span><span id="L-33"><a href="#L-33"><span class="linenos"> 33</span></a><span class="sd">Install the most recent release using conda and [conda-forge](https://anaconda.org/conda-forge/pyerrors):</span>
</span><span id="L-34"><a href="#L-34"><span class="linenos"> 34</span></a><span class="sd">```bash</span>
</span><span id="L-35"><a href="#L-35"><span class="linenos"> 35</span></a><span class="sd">conda install -c conda-forge pyerrors # Fresh install</span>
</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a><span class="sd">conda update -c conda-forge pyerrors # Update</span>
2022-09-30 15:27:14 +00:00
</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a><span class="sd">```</span>
2023-03-13 13:32:03 +00:00
</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a><span class="sd">Install the current `develop` version:</span>
</span><span id="L-39"><a href="#L-39"><span class="linenos"> 39</span></a><span class="sd">```bash</span>
2023-07-17 14:35:42 +00:00
</span><span id="L-40"><a href="#L-40"><span class="linenos"> 40</span></a><span class="sd">python -m pip install -U --no-deps --force-reinstall git+https://github.com/fjosw/pyerrors.git@develop</span>
2023-03-13 13:32:03 +00:00
</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a><span class="sd">```</span>
2023-07-17 14:35:42 +00:00
</span><span id="L-42"><a href="#L-42"><span class="linenos"> 42</span></a><span class="sd">(Also works for any feature branch).</span>
</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a>
</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a><span class="sd">## Basic example</span>
</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a>
</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a><span class="sd">```python</span>
</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a><span class="sd">import numpy as np</span>
</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a><span class="sd">import pyerrors as pe</span>
</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a>
</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a><span class="sd">my_obs = pe.Obs([samples], [&#39;ensemble_name&#39;]) # Initialize an Obs object</span>
</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a><span class="sd">my_new_obs = 2 * np.log(my_obs) / my_obs ** 2 # Construct derived Obs object</span>
</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a><span class="sd">my_new_obs.gamma_method() # Estimate the statistical error</span>
</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a><span class="sd">print(my_new_obs) # Print the result to stdout</span>
</span><span id="L-54"><a href="#L-54"><span class="linenos"> 54</span></a><span class="sd">&gt; 0.31498(72)</span>
</span><span id="L-55"><a href="#L-55"><span class="linenos"> 55</span></a><span class="sd">```</span>
</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a>
</span><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a><span class="sd"># The `Obs` class</span>
</span><span id="L-58"><a href="#L-58"><span class="linenos"> 58</span></a>
</span><span id="L-59"><a href="#L-59"><span class="linenos"> 59</span></a><span class="sd">`pyerrors` introduces a new datatype, `Obs`, which simplifies error propagation and estimation for auto- and cross-correlated data.</span>
</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a><span class="sd">An `Obs` object can be initialized with two arguments, the first is a list containing the samples for an observable from a Monte Carlo chain.</span>
</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a><span class="sd">The samples can either be provided as python list or as numpy array.</span>
</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a><span class="sd">The second argument is a list containing the names of the respective Monte Carlo chains as strings. These strings uniquely identify a Monte Carlo chain/ensemble. **It is crucial for the correct error propagation that observations from the same Monte Carlo history are labeled with the same name. See [Multiple ensembles/replica](#multiple-ensemblesreplica) for details.**</span>
</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a>
</span><span id="L-64"><a href="#L-64"><span class="linenos"> 64</span></a><span class="sd">```python</span>
</span><span id="L-65"><a href="#L-65"><span class="linenos"> 65</span></a><span class="sd">import pyerrors as pe</span>
</span><span id="L-66"><a href="#L-66"><span class="linenos"> 66</span></a>
</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a><span class="sd">my_obs = pe.Obs([samples], [&#39;ensemble_name&#39;])</span>
</span><span id="L-68"><a href="#L-68"><span class="linenos"> 68</span></a><span class="sd">```</span>
</span><span id="L-69"><a href="#L-69"><span class="linenos"> 69</span></a>
</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a><span class="sd">## Error propagation</span>
</span><span id="L-71"><a href="#L-71"><span class="linenos"> 71</span></a>
</span><span id="L-72"><a href="#L-72"><span class="linenos"> 72</span></a><span class="sd">When performing mathematical operations on `Obs` objects the correct error propagation is intrinsically taken care of using a first order Taylor expansion</span>
</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a><span class="sd">$$\delta_f^i=\sum_\alpha \bar{f}_\alpha \delta_\alpha^i\,,\quad \delta_\alpha^i=a_\alpha^i-\bar{a}_\alpha\,,$$</span>
</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a><span class="sd">as introduced in [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017).</span>
</span><span id="L-75"><a href="#L-75"><span class="linenos"> 75</span></a><span class="sd">The required derivatives $\bar{f}_\alpha$ are evaluated up to machine precision via automatic differentiation as suggested in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289).</span>
</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a>
</span><span id="L-77"><a href="#L-77"><span class="linenos"> 77</span></a><span class="sd">The `Obs` class is designed such that mathematical numpy functions can be used on `Obs` just as for regular floats.</span>
</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a>
</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a><span class="sd">```python</span>
</span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a><span class="sd">import numpy as np</span>
</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a><span class="sd">import pyerrors as pe</span>
</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a>
</span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a><span class="sd">my_obs1 = pe.Obs([samples1], [&#39;ensemble_name&#39;])</span>
</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a><span class="sd">my_obs2 = pe.Obs([samples2], [&#39;ensemble_name&#39;])</span>
</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a>
</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a><span class="sd">my_sum = my_obs1 + my_obs2</span>
</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a>
</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a><span class="sd">my_m_eff = np.log(my_obs1 / my_obs2)</span>
</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a>
</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a><span class="sd">iamzero = my_m_eff - my_m_eff</span>
</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a><span class="sd"># Check that value and fluctuations are zero within machine precision</span>
</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a><span class="sd">print(iamzero == 0.0)</span>
</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a><span class="sd">&gt; True</span>
</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a><span class="sd">```</span>
</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a>
</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a><span class="sd">## Error estimation</span>
</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a>
</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a><span class="sd">The error estimation within `pyerrors` is based on the gamma method introduced in [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017).</span>
</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a><span class="sd">After having arrived at the derived quantity of interest the `gamma_method` can be called as detailed in the following example.</span>
</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a>
</span><span id="L-101"><a href="#L-101"><span class="linenos">101</span></a><span class="sd">```python</span>
</span><span id="L-102"><a href="#L-102"><span class="linenos">102</span></a><span class="sd">my_sum.gamma_method()</span>
</span><span id="L-103"><a href="#L-103"><span class="linenos">103</span></a><span class="sd">print(my_sum)</span>
</span><span id="L-104"><a href="#L-104"><span class="linenos">104</span></a><span class="sd">&gt; 1.70(57)</span>
</span><span id="L-105"><a href="#L-105"><span class="linenos">105</span></a><span class="sd">my_sum.details()</span>
</span><span id="L-106"><a href="#L-106"><span class="linenos">106</span></a><span class="sd">&gt; Result 1.70000000e+00 +/- 5.72046658e-01 +/- 7.56746598e-02 (33.650%)</span>
</span><span id="L-107"><a href="#L-107"><span class="linenos">107</span></a><span class="sd">&gt; t_int 2.71422900e+00 +/- 6.40320983e-01 S = 2.00</span>
</span><span id="L-108"><a href="#L-108"><span class="linenos">108</span></a><span class="sd">&gt; 1000 samples in 1 ensemble:</span>
</span><span id="L-109"><a href="#L-109"><span class="linenos">109</span></a><span class="sd">&gt; · Ensemble &#39;ensemble_name&#39; : 1000 configurations (from 1 to 1000)</span>
</span><span id="L-110"><a href="#L-110"><span class="linenos">110</span></a>
</span><span id="L-111"><a href="#L-111"><span class="linenos">111</span></a><span class="sd">```</span>
</span><span id="L-112"><a href="#L-112"><span class="linenos">112</span></a><span class="sd">The `gamma_method` is not automatically called after every intermediate step in order to prevent computational overhead.</span>
</span><span id="L-113"><a href="#L-113"><span class="linenos">113</span></a>
</span><span id="L-114"><a href="#L-114"><span class="linenos">114</span></a><span class="sd">We use the following definition of the integrated autocorrelation time established in [Madras &amp; Sokal 1988](https://link.springer.com/article/10.1007/BF01022990)</span>
</span><span id="L-115"><a href="#L-115"><span class="linenos">115</span></a><span class="sd">$$\tau_\mathrm{int}=\frac{1}{2}+\sum_{t=1}^{W}\rho(t)\geq \frac{1}{2}\,.$$</span>
</span><span id="L-116"><a href="#L-116"><span class="linenos">116</span></a><span class="sd">The window $W$ is determined via the automatic windowing procedure described in [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017).</span>
</span><span id="L-117"><a href="#L-117"><span class="linenos">117</span></a><span class="sd">The standard value for the parameter $S$ of this automatic windowing procedure is $S=2$. Other values for $S$ can be passed to the `gamma_method` as parameter.</span>
</span><span id="L-118"><a href="#L-118"><span class="linenos">118</span></a>
</span><span id="L-119"><a href="#L-119"><span class="linenos">119</span></a><span class="sd">```python</span>
</span><span id="L-120"><a href="#L-120"><span class="linenos">120</span></a><span class="sd">my_sum.gamma_method(S=3.0)</span>
</span><span id="L-121"><a href="#L-121"><span class="linenos">121</span></a><span class="sd">my_sum.details()</span>
</span><span id="L-122"><a href="#L-122"><span class="linenos">122</span></a><span class="sd">&gt; Result 1.70000000e+00 +/- 6.30675201e-01 +/- 1.04585650e-01 (37.099%)</span>
</span><span id="L-123"><a href="#L-123"><span class="linenos">123</span></a><span class="sd">&gt; t_int 3.29909703e+00 +/- 9.77310102e-01 S = 3.00</span>
</span><span id="L-124"><a href="#L-124"><span class="linenos">124</span></a><span class="sd">&gt; 1000 samples in 1 ensemble:</span>
</span><span id="L-125"><a href="#L-125"><span class="linenos">125</span></a><span class="sd">&gt; · Ensemble &#39;ensemble_name&#39; : 1000 configurations (from 1 to 1000)</span>
</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a>
</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a><span class="sd">```</span>
</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a>
</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a><span class="sd">The integrated autocorrelation time $\tau_\mathrm{int}$ and the autocorrelation function $\rho(W)$ can be monitored via the methods `pyerrors.obs.Obs.plot_tauint` and `pyerrors.obs.Obs.plot_rho`.</span>
</span><span id="L-130"><a href="#L-130"><span class="linenos">130</span></a>
</span><span id="L-131"><a href="#L-131"><span class="linenos">131</span></a><span class="sd">If the parameter $S$ is set to zero it is assumed that the dataset does not exhibit any autocorrelation and the window size is chosen to be zero.</span>
</span><span id="L-132"><a href="#L-132"><span class="linenos">132</span></a><span class="sd">In this case the error estimate is identical to the sample standard error.</span>
</span><span id="L-133"><a href="#L-133"><span class="linenos">133</span></a>
</span><span id="L-134"><a href="#L-134"><span class="linenos">134</span></a><span class="sd">### Exponential tails</span>
</span><span id="L-135"><a href="#L-135"><span class="linenos">135</span></a>
</span><span id="L-136"><a href="#L-136"><span class="linenos">136</span></a><span class="sd">Slow modes in the Monte Carlo history can be accounted for by attaching an exponential tail to the autocorrelation function $\rho$ as suggested in [arXiv:1009.5228](https://arxiv.org/abs/1009.5228). The longest autocorrelation time in the history, $\tau_\mathrm{exp}$, can be passed to the `gamma_method` as parameter. In this case the automatic windowing procedure is vacated and the parameter $S$ does not affect the error estimate.</span>
</span><span id="L-137"><a href="#L-137"><span class="linenos">137</span></a>
</span><span id="L-138"><a href="#L-138"><span class="linenos">138</span></a><span class="sd">```python</span>
</span><span id="L-139"><a href="#L-139"><span class="linenos">139</span></a><span class="sd">my_sum.gamma_method(tau_exp=7.2)</span>
</span><span id="L-140"><a href="#L-140"><span class="linenos">140</span></a><span class="sd">my_sum.details()</span>
</span><span id="L-141"><a href="#L-141"><span class="linenos">141</span></a><span class="sd">&gt; Result 1.70000000e+00 +/- 6.28097762e-01 +/- 5.79077524e-02 (36.947%)</span>
</span><span id="L-142"><a href="#L-142"><span class="linenos">142</span></a><span class="sd">&gt; t_int 3.27218667e+00 +/- 7.99583654e-01 tau_exp = 7.20, N_sigma = 1</span>
</span><span id="L-143"><a href="#L-143"><span class="linenos">143</span></a><span class="sd">&gt; 1000 samples in 1 ensemble:</span>
</span><span id="L-144"><a href="#L-144"><span class="linenos">144</span></a><span class="sd">&gt; · Ensemble &#39;ensemble_name&#39; : 1000 configurations (from 1 to 1000)</span>
</span><span id="L-145"><a href="#L-145"><span class="linenos">145</span></a><span class="sd">```</span>
</span><span id="L-146"><a href="#L-146"><span class="linenos">146</span></a>
</span><span id="L-147"><a href="#L-147"><span class="linenos">147</span></a><span class="sd">For the full API see `pyerrors.obs.Obs.gamma_method`.</span>
</span><span id="L-148"><a href="#L-148"><span class="linenos">148</span></a>
</span><span id="L-149"><a href="#L-149"><span class="linenos">149</span></a><span class="sd">## Multiple ensembles/replica</span>
</span><span id="L-150"><a href="#L-150"><span class="linenos">150</span></a>
</span><span id="L-151"><a href="#L-151"><span class="linenos">151</span></a><span class="sd">Error propagation for multiple ensembles (Markov chains with different simulation parameters) is handled automatically. Ensembles are uniquely identified by their `name`.</span>
</span><span id="L-152"><a href="#L-152"><span class="linenos">152</span></a>
</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a><span class="sd">```python</span>
</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a><span class="sd">obs1 = pe.Obs([samples1], [&#39;ensemble1&#39;])</span>
</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a><span class="sd">obs2 = pe.Obs([samples2], [&#39;ensemble2&#39;])</span>
</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a>
</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a><span class="sd">my_sum = obs1 + obs2</span>
</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a><span class="sd">my_sum.details()</span>
</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a><span class="sd">&gt; Result 2.00697958e+00</span>
</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a><span class="sd">&gt; 1500 samples in 2 ensembles:</span>
</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a><span class="sd">&gt; · Ensemble &#39;ensemble1&#39; : 1000 configurations (from 1 to 1000)</span>
</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a><span class="sd">&gt; · Ensemble &#39;ensemble2&#39; : 500 configurations (from 1 to 500)</span>
</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a><span class="sd">```</span>
</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a><span class="sd">Observables from the **same Monte Carlo chain** have to be initialized with the **same name** for correct error propagation. If different names were used in this case the data would be treated as statistically independent resulting in loss of relevant information and a potential over or under estimate of the statistical error.</span>
2023-07-10 15:34:17 +00:00
</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a>
2023-07-17 14:35:42 +00:00
</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a>
</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a><span class="sd">`pyerrors` identifies multiple replica (independent Markov chains with identical simulation parameters) by the vertical bar `|` in the name of the data set.</span>
</span><span id="L-168"><a href="#L-168"><span class="linenos">168</span></a>
</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a><span class="sd">```python</span>
</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a><span class="sd">obs1 = pe.Obs([samples1], [&#39;ensemble1|r01&#39;])</span>
</span><span id="L-171"><a href="#L-171"><span class="linenos">171</span></a><span class="sd">obs2 = pe.Obs([samples2], [&#39;ensemble1|r02&#39;])</span>
</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a>
</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a><span class="sd">&gt; my_sum = obs1 + obs2</span>
</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a><span class="sd">&gt; my_sum.details()</span>
</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a><span class="sd">&gt; Result 2.00697958e+00</span>
</span><span id="L-176"><a href="#L-176"><span class="linenos">176</span></a><span class="sd">&gt; 1500 samples in 1 ensemble:</span>
</span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a><span class="sd">&gt; · Ensemble &#39;ensemble1&#39;</span>
</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a><span class="sd">&gt; · Replicum &#39;r01&#39; : 1000 configurations (from 1 to 1000)</span>
</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a><span class="sd">&gt; · Replicum &#39;r02&#39; : 500 configurations (from 1 to 500)</span>
</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a><span class="sd">```</span>
</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a>
</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a><span class="sd">### Error estimation for multiple ensembles</span>
</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a>
</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a><span class="sd">In order to keep track of different error analysis parameters for different ensembles one can make use of global dictionaries as detailed in the following example.</span>
</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a>
</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a><span class="sd">```python</span>
</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a><span class="sd">pe.Obs.S_dict[&#39;ensemble1&#39;] = 2.5</span>
</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a><span class="sd">pe.Obs.tau_exp_dict[&#39;ensemble2&#39;] = 8.0</span>
</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a><span class="sd">pe.Obs.tau_exp_dict[&#39;ensemble3&#39;] = 2.0</span>
</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a><span class="sd">```</span>
</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a>
</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a><span class="sd">In case the `gamma_method` is called without any parameters it will use the values specified in the dictionaries for the respective ensembles.</span>
</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a><span class="sd">Passing arguments to the `gamma_method` still dominates over the dictionaries.</span>
2023-07-10 15:34:17 +00:00
</span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a>
2023-07-17 14:35:42 +00:00
</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a>
</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a><span class="sd">## Irregular Monte Carlo chains</span>
</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a>
</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a><span class="sd">`Obs` objects defined on irregular Monte Carlo chains can be initialized with the parameter `idl`.</span>
</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a>
</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a><span class="sd">```python</span>
</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a><span class="sd"># Observable defined on configurations 20 to 519</span>
</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a><span class="sd">obs1 = pe.Obs([samples1], [&#39;ensemble1&#39;], idl=[range(20, 520)])</span>
</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a><span class="sd">obs1.details()</span>
</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a><span class="sd">&gt; Result 9.98319881e-01</span>
</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a><span class="sd">&gt; 500 samples in 1 ensemble:</span>
</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a><span class="sd">&gt; · Ensemble &#39;ensemble1&#39; : 500 configurations (from 20 to 519)</span>
</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a>
</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a><span class="sd"># Observable defined on every second configuration between 5 and 1003</span>
</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a><span class="sd">obs2 = pe.Obs([samples2], [&#39;ensemble1&#39;], idl=[range(5, 1005, 2)])</span>
</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a><span class="sd">obs2.details()</span>
</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a><span class="sd">&gt; Result 9.99100712e-01</span>
</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a><span class="sd">&gt; 500 samples in 1 ensemble:</span>
</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a><span class="sd">&gt; · Ensemble &#39;ensemble1&#39; : 500 configurations (from 5 to 1003 in steps of 2)</span>
</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a>
</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a><span class="sd"># Observable defined on configurations 2, 9, 28, 29 and 501</span>
</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a><span class="sd">obs3 = pe.Obs([samples3], [&#39;ensemble1&#39;], idl=[[2, 9, 28, 29, 501]])</span>
</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a><span class="sd">obs3.details()</span>
</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a><span class="sd">&gt; Result 1.01718064e+00</span>
</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a><span class="sd">&gt; 5 samples in 1 ensemble:</span>
</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a><span class="sd">&gt; · Ensemble &#39;ensemble1&#39; : 5 configurations (irregular range)</span>
</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a>
</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a><span class="sd">```</span>
</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a>
</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a><span class="sd">`Obs` objects defined on regular and irregular histories of the same ensemble can be combined with each other and the correct error propagation and estimation is automatically taken care of.</span>
</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a>
</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a><span class="sd">**Warning:** Irregular Monte Carlo chains can result in odd patterns in the autocorrelation functions.</span>
</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a><span class="sd">Make sure to check the autocorrelation time with e.g. `pyerrors.obs.Obs.plot_rho` or `pyerrors.obs.Obs.plot_tauint`.</span>
</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a>
</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a><span class="sd">For the full API see `pyerrors.obs.Obs`.</span>
</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a>
</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a><span class="sd"># Correlators</span>
</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a><span class="sd">When one is not interested in single observables but correlation functions, `pyerrors` offers the `Corr` class which simplifies the corresponding error propagation and provides the user with a set of standard methods. In order to initialize a `Corr` objects one needs to arrange the data as a list of `Obs`</span>
</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a><span class="sd">```python</span>
</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a><span class="sd">my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3])</span>
</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a><span class="sd">print(my_corr)</span>
</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a><span class="sd">&gt; x0/a Corr(x0/a)</span>
</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a><span class="sd">&gt; ------------------</span>
</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a><span class="sd">&gt; 0 0.7957(80)</span>
</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a><span class="sd">&gt; 1 0.5156(51)</span>
</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a><span class="sd">&gt; 2 0.3227(33)</span>
</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a><span class="sd">&gt; 3 0.2041(21)</span>
</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a><span class="sd">```</span>
</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a><span class="sd">In case the correlation functions are not defined on the outermost timeslices, for example because of fixed boundary conditions, a padding can be introduced.</span>
</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a><span class="sd">```python</span>
</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a><span class="sd">my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3], padding=[1, 1])</span>
</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a><span class="sd">print(my_corr)</span>
</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a><span class="sd">&gt; x0/a Corr(x0/a)</span>
</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a><span class="sd">&gt; ------------------</span>
</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a><span class="sd">&gt; 0</span>
</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a><span class="sd">&gt; 1 0.7957(80)</span>
</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a><span class="sd">&gt; 2 0.5156(51)</span>
</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a><span class="sd">&gt; 3 0.3227(33)</span>
</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a><span class="sd">&gt; 4 0.2041(21)</span>
</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a><span class="sd">&gt; 5</span>
</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a><span class="sd">```</span>
</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a><span class="sd">The individual entries of a correlator can be accessed via slicing</span>
</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a><span class="sd">```python</span>
</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a><span class="sd">print(my_corr[3])</span>
</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a><span class="sd">&gt; 0.3227(33)</span>
</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a><span class="sd">```</span>
</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a><span class="sd">Error propagation with the `Corr` class works very similar to `Obs` objects. Mathematical operations are overloaded and `Corr` objects can be computed together with other `Corr` objects, `Obs` objects or real numbers and integers.</span>
</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a><span class="sd">```python</span>
</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a><span class="sd">my_new_corr = 0.3 * my_corr[2] * my_corr * my_corr + 12 / my_corr</span>
</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a><span class="sd">```</span>
</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a>
</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a><span class="sd">`pyerrors` provides the user with a set of regularly used methods for the manipulation of correlator objects:</span>
</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a><span class="sd">- `Corr.gamma_method` applies the gamma method to all entries of the correlator.</span>
</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a><span class="sd">- `Corr.m_eff` to construct effective masses. Various variants for periodic and fixed temporal boundary conditions are available.</span>
</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a><span class="sd">- `Corr.deriv` returns the first derivative of the correlator as `Corr`. Different discretizations of the numerical derivative are available.</span>
</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a><span class="sd">- `Corr.second_deriv` returns the second derivative of the correlator as `Corr`. Different discretizations of the numerical derivative are available.</span>
</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a><span class="sd">- `Corr.symmetric` symmetrizes parity even correlations functions, assuming periodic boundary conditions.</span>
</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a><span class="sd">- `Corr.anti_symmetric` anti-symmetrizes parity odd correlations functions, assuming periodic boundary conditions.</span>
</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a><span class="sd">- `Corr.T_symmetry` averages a correlator with its time symmetry partner, assuming fixed boundary conditions.</span>
</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a><span class="sd">- `Corr.plateau` extracts a plateau value from the correlator in a given range.</span>
</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a><span class="sd">- `Corr.roll` periodically shifts the correlator.</span>
</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a><span class="sd">- `Corr.reverse` reverses the time ordering of the correlator.</span>
</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a><span class="sd">- `Corr.correlate` constructs a disconnected correlation function from the correlator and another `Corr` or `Obs` object.</span>
</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a><span class="sd">- `Corr.reweight` reweights the correlator.</span>
</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a>
</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a><span class="sd">`pyerrors` can also handle matrices of correlation functions and extract energy states from these matrices via a generalized eigenvalue problem (see `pyerrors.correlators.Corr.GEVP`).</span>
</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a>
</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a><span class="sd">For the full API see `pyerrors.correlators.Corr`.</span>
</span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a>
</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a><span class="sd"># Complex valued observables</span>
</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a>
</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a><span class="sd">`pyerrors` can handle complex valued observables via the class `pyerrors.obs.CObs`.</span>
</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a><span class="sd">`CObs` are initialized with a real and an imaginary part which both can be `Obs` valued.</span>
</span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a>
</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a><span class="sd">```python</span>
</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a><span class="sd">my_real_part = pe.Obs([samples1], [&#39;ensemble1&#39;])</span>
</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a><span class="sd">my_imag_part = pe.Obs([samples2], [&#39;ensemble1&#39;])</span>
</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a>
</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a><span class="sd">my_cobs = pe.CObs(my_real_part, my_imag_part)</span>
</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a><span class="sd">my_cobs.gamma_method()</span>
</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a><span class="sd">print(my_cobs)</span>
</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a><span class="sd">&gt; (0.9959(91)+0.659(28)j)</span>
</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a><span class="sd">```</span>
</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a>
</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a><span class="sd">Elementary mathematical operations are overloaded and samples are properly propagated as for the `Obs` class.</span>
</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a><span class="sd">```python</span>
</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a><span class="sd">my_derived_cobs = (my_cobs + my_cobs.conjugate()) / np.abs(my_cobs)</span>
</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a><span class="sd">my_derived_cobs.gamma_method()</span>
</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a><span class="sd">print(my_derived_cobs)</span>
</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a><span class="sd">&gt; (1.668(23)+0.0j)</span>
</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a><span class="sd">```</span>
</span><span id="L-306"><a href="#L-306"><span class="linenos">306</span></a>
</span><span id="L-307"><a href="#L-307"><span class="linenos">307</span></a><span class="sd"># The `Covobs` class</span>
</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a><span class="sd">In many projects, auxiliary data that is not based on Monte Carlo chains enters. Examples are experimentally determined mesons masses which are used to set the scale or renormalization constants. These numbers come with an error that has to be propagated through the analysis. The `Covobs` class allows to define such quantities in `pyerrors`. Furthermore, external input might consist of correlated quantities. An example are the parameters of an interpolation formula, which are defined via mean values and a covariance matrix between all parameters. The contribution of the interpolation formula to the error of a derived quantity therefore might depend on the complete covariance matrix.</span>
</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a>
</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a><span class="sd">This concept is built into the definition of `Covobs`. In `pyerrors`, external input is defined by $M$ mean values, a $M\times M$ covariance matrix, where $M=1$ is permissible, and a name that uniquely identifies the covariance matrix. Below, we define the pion mass, based on its mean value and error, 134.9768(5). **Note, that the square of the error enters `cov_Obs`**, since the second argument of this function is the covariance matrix of the `Covobs`.</span>
</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a>
</span><span id="L-312"><a href="#L-312"><span class="linenos">312</span></a><span class="sd">```python</span>
</span><span id="L-313"><a href="#L-313"><span class="linenos">313</span></a><span class="sd">import pyerrors.obs as pe</span>
</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a>
</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a><span class="sd">mpi = pe.cov_Obs(134.9768, 0.0005**2, &#39;pi^0 mass&#39;)</span>
</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a><span class="sd">mpi.gamma_method()</span>
</span><span id="L-317"><a href="#L-317"><span class="linenos">317</span></a><span class="sd">mpi.details()</span>
</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a><span class="sd">&gt; Result 1.34976800e+02 +/- 5.00000000e-04 +/- 0.00000000e+00 (0.000%)</span>
</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a><span class="sd">&gt; pi^0 mass 5.00000000e-04</span>
</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a><span class="sd">&gt; 0 samples in 1 ensemble:</span>
</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a><span class="sd">&gt; · Covobs &#39;pi^0 mass&#39;</span>
</span><span id="L-322"><a href="#L-322"><span class="linenos">322</span></a><span class="sd">```</span>
</span><span id="L-323"><a href="#L-323"><span class="linenos">323</span></a><span class="sd">The resulting object `mpi` is an `Obs` that contains a `Covobs`. In the following, it may be handled as any other `Obs`. The contribution of the covariance matrix to the error of an `Obs` is determined from the $M \times M$ covariance matrix $\Sigma$ and the gradient of the `Obs` with respect to the external quantities, which is the $1\times M$ Jacobian matrix $J$, via</span>
</span><span id="L-324"><a href="#L-324"><span class="linenos">324</span></a><span class="sd">$$s = \sqrt{J^T \Sigma J}\,,$$</span>
</span><span id="L-325"><a href="#L-325"><span class="linenos">325</span></a><span class="sd">where the Jacobian is computed for each derived quantity via automatic differentiation.</span>
</span><span id="L-326"><a href="#L-326"><span class="linenos">326</span></a>
</span><span id="L-327"><a href="#L-327"><span class="linenos">327</span></a><span class="sd">Correlated auxiliary data is defined similarly to above, e.g., via</span>
</span><span id="L-328"><a href="#L-328"><span class="linenos">328</span></a><span class="sd">```python</span>
</span><span id="L-329"><a href="#L-329"><span class="linenos">329</span></a><span class="sd">RAP = pe.cov_Obs([16.7457, -19.0475], [[3.49591, -6.07560], [-6.07560, 10.5834]], &#39;R_AP, 1906.03445, (5.3a)&#39;)</span>
</span><span id="L-330"><a href="#L-330"><span class="linenos">330</span></a><span class="sd">print(RAP)</span>
</span><span id="L-331"><a href="#L-331"><span class="linenos">331</span></a><span class="sd">&gt; [Obs[16.7(1.9)], Obs[-19.0(3.3)]]</span>
</span><span id="L-332"><a href="#L-332"><span class="linenos">332</span></a><span class="sd">```</span>
</span><span id="L-333"><a href="#L-333"><span class="linenos">333</span></a><span class="sd">where `RAP` now is a list of two `Obs` that contains the two correlated parameters.</span>
</span><span id="L-334"><a href="#L-334"><span class="linenos">334</span></a>
</span><span id="L-335"><a href="#L-335"><span class="linenos">335</span></a><span class="sd">Since the gradient of a derived observable with respect to an external covariance matrix is propagated through the entire analysis, the `Covobs` class allows to quote the derivative of a result with respect to the external quantities. If these derivatives are published together with the result, small shifts in the definition of external quantities, e.g., the definition of the physical point, can be performed a posteriori based on the published information. This may help to compare results of different groups. The gradient of an `Obs` `o` with respect to a covariance matrix with the identifying string `k` may be accessed via</span>
</span><span id="L-336"><a href="#L-336"><span class="linenos">336</span></a><span class="sd">```python</span>
</span><span id="L-337"><a href="#L-337"><span class="linenos">337</span></a><span class="sd">o.covobs[k].grad</span>
</span><span id="L-338"><a href="#L-338"><span class="linenos">338</span></a><span class="sd">```</span>
</span><span id="L-339"><a href="#L-339"><span class="linenos">339</span></a>
</span><span id="L-340"><a href="#L-340"><span class="linenos">340</span></a><span class="sd"># Error propagation in iterative algorithms</span>
</span><span id="L-341"><a href="#L-341"><span class="linenos">341</span></a>
</span><span id="L-342"><a href="#L-342"><span class="linenos">342</span></a><span class="sd">`pyerrors` supports exact linear error propagation for iterative algorithms like various variants of non-linear least squares fits or root finding. The derivatives required for the error propagation are calculated as described in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289).</span>
</span><span id="L-343"><a href="#L-343"><span class="linenos">343</span></a>
</span><span id="L-344"><a href="#L-344"><span class="linenos">344</span></a><span class="sd">## Least squares fits</span>
</span><span id="L-345"><a href="#L-345"><span class="linenos">345</span></a>
</span><span id="L-346"><a href="#L-346"><span class="linenos">346</span></a><span class="sd">Standard non-linear least square fits with errors on the dependent but not the independent variables can be performed with `pyerrors.fits.least_squares`. As default solver the Levenberg-Marquardt algorithm implemented in [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html) is used.</span>
</span><span id="L-347"><a href="#L-347"><span class="linenos">347</span></a>
</span><span id="L-348"><a href="#L-348"><span class="linenos">348</span></a><span class="sd">Fit functions have to be of the following form</span>
</span><span id="L-349"><a href="#L-349"><span class="linenos">349</span></a><span class="sd">```python</span>
</span><span id="L-350"><a href="#L-350"><span class="linenos">350</span></a><span class="sd">import autograd.numpy as anp</span>
</span><span id="L-351"><a href="#L-351"><span class="linenos">351</span></a>
</span><span id="L-352"><a href="#L-352"><span class="linenos">352</span></a><span class="sd">def func(a, x):</span>
</span><span id="L-353"><a href="#L-353"><span class="linenos">353</span></a><span class="sd"> return a[1] * anp.exp(-a[0] * x)</span>
</span><span id="L-354"><a href="#L-354"><span class="linenos">354</span></a><span class="sd">```</span>
</span><span id="L-355"><a href="#L-355"><span class="linenos">355</span></a><span class="sd">**It is important that numerical functions refer to `autograd.numpy` instead of `numpy` for the automatic differentiation in iterative algorithms to work properly.**</span>
</span><span id="L-356"><a href="#L-356"><span class="linenos">356</span></a>
</span><span id="L-357"><a href="#L-357"><span class="linenos">357</span></a><span class="sd">Fits can then be performed via</span>
</span><span id="L-358"><a href="#L-358"><span class="linenos">358</span></a><span class="sd">```python</span>
</span><span id="L-359"><a href="#L-359"><span class="linenos">359</span></a><span class="sd">fit_result = pe.fits.least_squares(x, y, func)</span>
</span><span id="L-360"><a href="#L-360"><span class="linenos">360</span></a><span class="sd">print(&quot;\n&quot;, fit_result)</span>
</span><span id="L-361"><a href="#L-361"><span class="linenos">361</span></a><span class="sd">&gt; Fit with 2 parameters</span>
</span><span id="L-362"><a href="#L-362"><span class="linenos">362</span></a><span class="sd">&gt; Method: Levenberg-Marquardt</span>
</span><span id="L-363"><a href="#L-363"><span class="linenos">363</span></a><span class="sd">&gt; `ftol` termination condition is satisfied.</span>
</span><span id="L-364"><a href="#L-364"><span class="linenos">364</span></a><span class="sd">&gt; chisquare/d.o.f.: 0.9593035785160936</span>
</span><span id="L-365"><a href="#L-365"><span class="linenos">365</span></a>
</span><span id="L-366"><a href="#L-366"><span class="linenos">366</span></a><span class="sd">&gt; Goodness of fit:</span>
</span><span id="L-367"><a href="#L-367"><span class="linenos">367</span></a><span class="sd">&gt; χ²/d.o.f. = 0.959304</span>
</span><span id="L-368"><a href="#L-368"><span class="linenos">368</span></a><span class="sd">&gt; p-value = 0.5673</span>
</span><span id="L-369"><a href="#L-369"><span class="linenos">369</span></a><span class="sd">&gt; Fit parameters:</span>
</span><span id="L-370"><a href="#L-370"><span class="linenos">370</span></a><span class="sd">&gt; 0 0.0548(28)</span>
</span><span id="L-371"><a href="#L-371"><span class="linenos">371</span></a><span class="sd">&gt; 1 1.933(64)</span>
</span><span id="L-372"><a href="#L-372"><span class="linenos">372</span></a><span class="sd">```</span>
</span><span id="L-373"><a href="#L-373"><span class="linenos">373</span></a><span class="sd">where x is a `list` or `numpy.array` of `floats` and y is a `list` or `numpy.array` of `Obs`.</span>
</span><span id="L-374"><a href="#L-374"><span class="linenos">374</span></a>
</span><span id="L-375"><a href="#L-375"><span class="linenos">375</span></a><span class="sd">Data stored in `Corr` objects can be fitted directly using the `Corr.fit` method.</span>
</span><span id="L-376"><a href="#L-376"><span class="linenos">376</span></a><span class="sd">```python</span>
</span><span id="L-377"><a href="#L-377"><span class="linenos">377</span></a><span class="sd">my_corr = pe.Corr(y)</span>
</span><span id="L-378"><a href="#L-378"><span class="linenos">378</span></a><span class="sd">fit_result = my_corr.fit(func, fitrange=[12, 25])</span>
</span><span id="L-379"><a href="#L-379"><span class="linenos">379</span></a><span class="sd">```</span>
</span><span id="L-380"><a href="#L-380"><span class="linenos">380</span></a><span class="sd">this can simplify working with absolute fit ranges and takes care of gaps in the data automatically.</span>
</span><span id="L-381"><a href="#L-381"><span class="linenos">381</span></a>
</span><span id="L-382"><a href="#L-382"><span class="linenos">382</span></a><span class="sd">For fit functions with multiple independent variables the fit function can be of the form</span>
</span><span id="L-383"><a href="#L-383"><span class="linenos">383</span></a>
</span><span id="L-384"><a href="#L-384"><span class="linenos">384</span></a><span class="sd">```python</span>
</span><span id="L-385"><a href="#L-385"><span class="linenos">385</span></a><span class="sd">def func(a, x):</span>
</span><span id="L-386"><a href="#L-386"><span class="linenos">386</span></a><span class="sd"> (x1, x2) = x</span>
</span><span id="L-387"><a href="#L-387"><span class="linenos">387</span></a><span class="sd"> return a[0] * x1 ** 2 + a[1] * x2</span>
</span><span id="L-388"><a href="#L-388"><span class="linenos">388</span></a><span class="sd">```</span>
</span><span id="L-389"><a href="#L-389"><span class="linenos">389</span></a>
</span><span id="L-390"><a href="#L-390"><span class="linenos">390</span></a><span class="sd">`pyerrors` also supports correlated fits which can be triggered via the parameter `correlated_fit=True`.</span>
</span><span id="L-391"><a href="#L-391"><span class="linenos">391</span></a><span class="sd">Details about how the required covariance matrix is estimated can be found in `pyerrors.obs.covariance`.</span>
</span><span id="L-392"><a href="#L-392"><span class="linenos">392</span></a><span class="sd">Direct visualizations of the performed fits can be triggered via `resplot=True` or `qqplot=True`.</span>
</span><span id="L-393"><a href="#L-393"><span class="linenos">393</span></a>
</span><span id="L-394"><a href="#L-394"><span class="linenos">394</span></a><span class="sd">For all available options including combined fits to multiple datasets see `pyerrors.fits.least_squares`.</span>
</span><span id="L-395"><a href="#L-395"><span class="linenos">395</span></a>
</span><span id="L-396"><a href="#L-396"><span class="linenos">396</span></a><span class="sd">## Total least squares fits</span>
</span><span id="L-397"><a href="#L-397"><span class="linenos">397</span></a><span class="sd">`pyerrors` can also fit data with errors on both the dependent and independent variables using the total least squares method also referred to as orthogonal distance regression as implemented in [scipy](https://docs.scipy.org/doc/scipy/reference/odr.html), see `pyerrors.fits.least_squares`. The syntax is identical to the standard least squares case, the only difference being that `x` also has to be a `list` or `numpy.array` of `Obs`.</span>
</span><span id="L-398"><a href="#L-398"><span class="linenos">398</span></a>
</span><span id="L-399"><a href="#L-399"><span class="linenos">399</span></a><span class="sd">For the full API see `pyerrors.fits` for fits and `pyerrors.roots` for finding roots of functions.</span>
</span><span id="L-400"><a href="#L-400"><span class="linenos">400</span></a>
</span><span id="L-401"><a href="#L-401"><span class="linenos">401</span></a><span class="sd"># Matrix operations</span>
</span><span id="L-402"><a href="#L-402"><span class="linenos">402</span></a><span class="sd">`pyerrors` provides wrappers for `Obs`- and `CObs`-valued matrix operations based on `numpy.linalg`. The supported functions include:</span>
</span><span id="L-403"><a href="#L-403"><span class="linenos">403</span></a><span class="sd">- `inv` for the matrix inverse.</span>
</span><span id="L-404"><a href="#L-404"><span class="linenos">404</span></a><span class="sd">- `cholseky` for the Cholesky decomposition.</span>
</span><span id="L-405"><a href="#L-405"><span class="linenos">405</span></a><span class="sd">- `det` for the matrix determinant.</span>
</span><span id="L-406"><a href="#L-406"><span class="linenos">406</span></a><span class="sd">- `eigh` for eigenvalues and eigenvectors of hermitean matrices.</span>
</span><span id="L-407"><a href="#L-407"><span class="linenos">407</span></a><span class="sd">- `eig` for eigenvalues of general matrices.</span>
</span><span id="L-408"><a href="#L-408"><span class="linenos">408</span></a><span class="sd">- `pinv` for the Moore-Penrose pseudoinverse.</span>
</span><span id="L-409"><a href="#L-409"><span class="linenos">409</span></a><span class="sd">- `svd` for the singular-value-decomposition.</span>
</span><span id="L-410"><a href="#L-410"><span class="linenos">410</span></a>
</span><span id="L-411"><a href="#L-411"><span class="linenos">411</span></a><span class="sd">For the full API see `pyerrors.linalg`.</span>
</span><span id="L-412"><a href="#L-412"><span class="linenos">412</span></a>
</span><span id="L-413"><a href="#L-413"><span class="linenos">413</span></a><span class="sd"># Export data</span>
</span><span id="L-414"><a href="#L-414"><span class="linenos">414</span></a>
</span><span id="L-415"><a href="#L-415"><span class="linenos">415</span></a><span class="sd">[&lt;img src=&quot;https://imgs.xkcd.com/comics/standards_2x.png&quot; width=&quot;75%&quot; height=&quot;75%&quot;&gt;](https://xkcd.com/927/)</span>
</span><span id="L-416"><a href="#L-416"><span class="linenos">416</span></a>
</span><span id="L-417"><a href="#L-417"><span class="linenos">417</span></a><span class="sd">The preferred exported file format within `pyerrors` is json.gz. Files written to this format are valid JSON files that have been compressed using gzip. The structure of the content is inspired by the dobs format of the ALPHA collaboration. The aim of the format is to facilitate the storage of data in a self-contained way such that, even years after the creation of the file, it is possible to extract all necessary information:</span>
</span><span id="L-418"><a href="#L-418"><span class="linenos">418</span></a><span class="sd">- What observables are stored? Possibly: How exactly are they defined.</span>
</span><span id="L-419"><a href="#L-419"><span class="linenos">419</span></a><span class="sd">- How does each single ensemble or external quantity contribute to the error of the observable?</span>
</span><span id="L-420"><a href="#L-420"><span class="linenos">420</span></a><span class="sd">- Who did write the file when and on which machine?</span>
</span><span id="L-421"><a href="#L-421"><span class="linenos">421</span></a>
</span><span id="L-422"><a href="#L-422"><span class="linenos">422</span></a><span class="sd">This can be achieved by storing all information in one single file. The export routines of `pyerrors` are written such that as much information as possible is written automatically as described in the following example</span>
</span><span id="L-423"><a href="#L-423"><span class="linenos">423</span></a><span class="sd">```python</span>
</span><span id="L-424"><a href="#L-424"><span class="linenos">424</span></a><span class="sd">my_obs = pe.Obs([samples], [&quot;test_ensemble&quot;])</span>
</span><span id="L-425"><a href="#L-425"><span class="linenos">425</span></a><span class="sd">my_obs.tag = &quot;My observable&quot;</span>
</span><span id="L-426"><a href="#L-426"><span class="linenos">426</span></a>
</span><span id="L-427"><a href="#L-427"><span class="linenos">427</span></a><span class="sd">pe.input.json.dump_to_json(my_obs, &quot;test_output_file&quot;, description=&quot;This file contains a test observable&quot;)</span>
</span><span id="L-428"><a href="#L-428"><span class="linenos">428</span></a><span class="sd"># For a single observable one can equivalently use the class method dump</span>
</span><span id="L-429"><a href="#L-429"><span class="linenos">429</span></a><span class="sd">my_obs.dump(&quot;test_output_file&quot;, description=&quot;This file contains a test observable&quot;)</span>
</span><span id="L-430"><a href="#L-430"><span class="linenos">430</span></a>
</span><span id="L-431"><a href="#L-431"><span class="linenos">431</span></a><span class="sd">check = pe.input.json.load_json(&quot;test_output_file&quot;)</span>
</span><span id="L-432"><a href="#L-432"><span class="linenos">432</span></a>
</span><span id="L-433"><a href="#L-433"><span class="linenos">433</span></a><span class="sd">print(my_obs == check)</span>
</span><span id="L-434"><a href="#L-434"><span class="linenos">434</span></a><span class="sd">&gt; True</span>
</span><span id="L-435"><a href="#L-435"><span class="linenos">435</span></a><span class="sd">```</span>
</span><span id="L-436"><a href="#L-436"><span class="linenos">436</span></a><span class="sd">The format also allows to directly write out the content of `Corr` objects or lists and arrays of `Obs` objects by passing the desired data to `pyerrors.input.json.dump_to_json`.</span>
</span><span id="L-437"><a href="#L-437"><span class="linenos">437</span></a>
</span><span id="L-438"><a href="#L-438"><span class="linenos">438</span></a><span class="sd">## json.gz format specification</span>
</span><span id="L-439"><a href="#L-439"><span class="linenos">439</span></a><span class="sd">The first entries of the file provide optional auxiliary information:</span>
</span><span id="L-440"><a href="#L-440"><span class="linenos">440</span></a><span class="sd">- `program` is a string that indicates which program was used to write the file.</span>
</span><span id="L-441"><a href="#L-441"><span class="linenos">441</span></a><span class="sd">- `version` is a string that specifies the version of the format.</span>
</span><span id="L-442"><a href="#L-442"><span class="linenos">442</span></a><span class="sd">- `who` is a string that specifies the user name of the creator of the file.</span>
</span><span id="L-443"><a href="#L-443"><span class="linenos">443</span></a><span class="sd">- `date` is a string and contains the creation date of the file.</span>
</span><span id="L-444"><a href="#L-444"><span class="linenos">444</span></a><span class="sd">- `host` is a string and contains the hostname of the machine where the file has been written.</span>
</span><span id="L-445"><a href="#L-445"><span class="linenos">445</span></a><span class="sd">- `description` contains information on the content of the file. This field is not filled automatically in `pyerrors`. The user is advised to provide as detailed information as possible in this field. Examples are: Input files of measurements or simulations, LaTeX formulae or references to publications to specify how the observables have been computed, details on the analysis strategy, ... This field may be any valid JSON type. Strings, arrays or objects (equivalent to dicts in python) are well suited to provide information.</span>
</span><span id="L-446"><a href="#L-446"><span class="linenos">446</span></a>
</span><span id="L-447"><a href="#L-447"><span class="linenos">447</span></a><span class="sd">The only necessary entry of the file is the field</span>
</span><span id="L-448"><a href="#L-448"><span class="linenos">448</span></a><span class="sd">-`obsdata`, an array that contains the actual data.</span>
</span><span id="L-449"><a href="#L-449"><span class="linenos">449</span></a>
</span><span id="L-450"><a href="#L-450"><span class="linenos">450</span></a><span class="sd">Each entry of the array belongs to a single structure of observables. Currently, these structures can be either of `Obs`, `list`, `numpy.ndarray`, `Corr`. All `Obs` inside a structure (with dimension &gt; 0) have to be defined on the same set of configurations. Different structures, that are represented by entries of the array `obsdata`, are treated independently. Each entry of the array `obsdata` has the following required entries:</span>
</span><span id="L-451"><a href="#L-451"><span class="linenos">451</span></a><span class="sd">- `type` is a string that specifies the type of the structure. This allows to parse the content to the correct form after reading the file. It is always possible to interpret the content as list of Obs.</span>
</span><span id="L-452"><a href="#L-452"><span class="linenos">452</span></a><span class="sd">- `value` is an array that contains the mean values of the Obs inside the structure.</span>
</span><span id="L-453"><a href="#L-453"><span class="linenos">453</span></a><span class="sd">The following entries are optional:</span>
</span><span id="L-454"><a href="#L-454"><span class="linenos">454</span></a><span class="sd">- `layout` is a string that specifies the layout of multi-dimensional structures. Examples are &quot;2, 2&quot; for a 2x2 dimensional matrix or &quot;64, 4, 4&quot; for a Corr with $T=64$ and 4x4 matrices on each time slices. &quot;1&quot; denotes a single Obs. Multi-dimensional structures are stored in row-major format (see below).</span>
</span><span id="L-455"><a href="#L-455"><span class="linenos">455</span></a><span class="sd">- `tag` is any JSON type. It contains additional information concerning the structure. The `tag` of an `Obs` in `pyerrors` is written here.</span>
</span><span id="L-456"><a href="#L-456"><span class="linenos">456</span></a><span class="sd">- `reweighted` is a Bool that may be used to specify, whether the `Obs` in the structure have been reweighted.</span>
</span><span id="L-457"><a href="#L-457"><span class="linenos">457</span></a><span class="sd">- `data` is an array that contains the data from MC chains. We will define it below.</span>
</span><span id="L-458"><a href="#L-458"><span class="linenos">458</span></a><span class="sd">- `cdata` is an array that contains the data from external quantities with an error (`Covobs` in `pyerrors`). We will define it below.</span>
</span><span id="L-459"><a href="#L-459"><span class="linenos">459</span></a>
</span><span id="L-460"><a href="#L-460"><span class="linenos">460</span></a><span class="sd">The array `data` contains the data from MC chains. Each entry of the array corresponds to one ensemble and contains:</span>
</span><span id="L-461"><a href="#L-461"><span class="linenos">461</span></a><span class="sd">- `id`, a string that contains the name of the ensemble</span>
</span><span id="L-462"><a href="#L-462"><span class="linenos">462</span></a><span class="sd">- `replica`, an array that contains an entry per replica of the ensemble.</span>
</span><span id="L-463"><a href="#L-463"><span class="linenos">463</span></a>
</span><span id="L-464"><a href="#L-464"><span class="linenos">464</span></a><span class="sd">Each entry of `replica` contains</span>
</span><span id="L-465"><a href="#L-465"><span class="linenos">465</span></a><span class="sd">`name`, a string that contains the name of the replica</span>
</span><span id="L-466"><a href="#L-466"><span class="linenos">466</span></a><span class="sd">`deltas`, an array that contains the actual data.</span>
</span><span id="L-467"><a href="#L-467"><span class="linenos">467</span></a>
</span><span id="L-468"><a href="#L-468"><span class="linenos">468</span></a><span class="sd">Each entry in `deltas` corresponds to one configuration of the replica and has $1+N$ many entries. The first entry is an integer that specifies the configuration number that, together with ensemble and replica name, may be used to uniquely identify the configuration on which the data has been obtained. The following N entries specify the deltas, i.e., the deviation of the observable from the mean value on this configuration, of each `Obs` inside the structure. Multi-dimensional structures are stored in a row-major format. For primary observables, such as correlation functions, $value + delta_i$ matches the primary data obtained on the configuration.</span>
</span><span id="L-469"><a href="#L-469"><span class="linenos">469</span></a>
</span><span id="L-470"><a href="#L-470"><span class="linenos">470</span></a><span class="sd">The array `cdata` contains information about the contribution of auxiliary observables, represented by `Covobs` in `pyerrors`, to the total error of the observables. Each entry of the array belongs to one auxiliary covariance matrix and contains:</span>
</span><span id="L-471"><a href="#L-471"><span class="linenos">471</span></a><span class="sd">- `id`, a string that identifies the covariance matrix</span>
</span><span id="L-472"><a href="#L-472"><span class="linenos">472</span></a><span class="sd">- `layout`, a string that defines the dimensions of the $M\times M$ covariance matrix (has to be &quot;M, M&quot; or &quot;1&quot;).</span>
</span><span id="L-473"><a href="#L-473"><span class="linenos">473</span></a><span class="sd">- `cov`, an array that contains the $M\times M$ many entries of the covariance matrix, stored in row-major format.</span>
</span><span id="L-474"><a href="#L-474"><span class="linenos">474</span></a><span class="sd">- `grad`, an array that contains N entries, one for each `Obs` inside the structure. Each entry itself is an array, that contains the M gradients of the Nth observable with respect to the quantity that corresponds to the Mth diagonal entry of the covariance matrix.</span>
</span><span id="L-475"><a href="#L-475"><span class="linenos">475</span></a>
</span><span id="L-476"><a href="#L-476"><span class="linenos">476</span></a><span class="sd">A JSON schema that may be used to verify the correctness of a file with respect to the format definition is stored in ./examples/json_schema.json. The schema is a self-descriptive format definition and contains an exemplary file.</span>
</span><span id="L-477"><a href="#L-477"><span class="linenos">477</span></a>
</span><span id="L-478"><a href="#L-478"><span class="linenos">478</span></a><span class="sd">Julia I/O routines for the json.gz format, compatible with [ADerrors.jl](https://gitlab.ift.uam-csic.es/alberto/aderrors.jl), can be found [here](https://github.com/fjosw/ADjson.jl).</span>
</span><span id="L-479"><a href="#L-479"><span class="linenos">479</span></a><span class="sd">&#39;&#39;&#39;</span>
2025-01-06 09:47:33 +00:00
</span><span id="L-480"><a href="#L-480"><span class="linenos">480</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.obs</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>
</span><span id="L-481"><a href="#L-481"><span class="linenos">481</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.correlators</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>
</span><span id="L-482"><a href="#L-482"><span class="linenos">482</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.fits</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>
</span><span id="L-483"><a href="#L-483"><span class="linenos">483</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.misc</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>
</span><span id="L-484"><a href="#L-484"><span class="linenos">484</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="n">dirac</span> <span class="k">as</span> <span class="n">dirac</span>
</span><span id="L-485"><a href="#L-485"><span class="linenos">485</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="nb">input</span> <span class="k">as</span> <span class="nb">input</span>
</span><span id="L-486"><a href="#L-486"><span class="linenos">486</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="n">linalg</span> <span class="k">as</span> <span class="n">linalg</span>
</span><span id="L-487"><a href="#L-487"><span class="linenos">487</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="n">mpm</span> <span class="k">as</span> <span class="n">mpm</span>
</span><span id="L-488"><a href="#L-488"><span class="linenos">488</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="n">roots</span> <span class="k">as</span> <span class="n">roots</span>
</span><span id="L-489"><a href="#L-489"><span class="linenos">489</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="n">integrate</span> <span class="k">as</span> <span class="n">integrate</span>
</span><span id="L-490"><a href="#L-490"><span class="linenos">490</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.</span><span class="w"> </span><span class="kn">import</span> <span class="n">special</span> <span class="k">as</span> <span class="n">special</span>
2024-01-07 16:22:53 +00:00
</span><span id="L-491"><a href="#L-491"><span class="linenos">491</span></a>
2025-01-06 09:47:33 +00:00
</span><span id="L-492"><a href="#L-492"><span class="linenos">492</span></a><span class="kn">from</span><span class="w"> </span><span class="nn">.version</span><span class="w"> </span><span class="kn">import</span> <span class="n">__version__</span> <span class="k">as</span> <span class="n">__version__</span>
2022-04-29 09:14:53 +00:00
</span></pre></div>
2021-11-07 20:53:18 +00:00
</section>
</main>
<script>
function escapeHTML(html) {
return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML;
}
const originalContent = document.querySelector("main.pdoc");
let currentContent = originalContent;
function setContent(innerHTML) {
let elem;
if (innerHTML) {
elem = document.createElement("main");
elem.classList.add("pdoc");
elem.innerHTML = innerHTML;
} else {
elem = originalContent;
}
if (currentContent !== elem) {
currentContent.replaceWith(elem);
currentContent = elem;
}
}
function getSearchTerm() {
return (new URL(window.location)).searchParams.get("search");
}
const searchBox = document.querySelector(".pdoc input[type=search]");
searchBox.addEventListener("input", function () {
let url = new URL(window.location);
if (searchBox.value.trim()) {
url.hash = "";
url.searchParams.set("search", searchBox.value);
} else {
url.searchParams.delete("search");
}
history.replaceState("", "", url.toString());
onInput();
});
window.addEventListener("popstate", onInput);
let search, searchErr;
async function initialize() {
try {
search = await new Promise((resolve, reject) => {
const script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.onload = () => resolve(window.pdocSearch);
script.onerror = (e) => reject(e);
script.src = "search.js";
document.getElementsByTagName("head")[0].appendChild(script);
});
} catch (e) {
console.error("Cannot fetch pdoc search index");
searchErr = "Cannot fetch search index.";
}
onInput();
document.querySelector("nav.pdoc").addEventListener("click", e => {
if (e.target.hash) {
searchBox.value = "";
searchBox.dispatchEvent(new Event("input"));
}
});
}
function onInput() {
setContent((() => {
const term = getSearchTerm();
if (!term) {
return null
}
if (searchErr) {
return `<h3>Error: ${searchErr}</h3>`
}
if (!search) {
return "<h3>Searching...</h3>"
}
window.scrollTo({top: 0, left: 0, behavior: 'auto'});
const results = search(term);
let html;
if (results.length === 0) {
html = `No search results for '${escapeHTML(term)}'.`
} else {
html = `<h4>${results.length} search result${results.length > 1 ? "s" : ""} for '${escapeHTML(term)}'.</h4>`;
}
for (let result of results.slice(0, 10)) {
let doc = result.doc;
let url = `${doc.modulename.replaceAll(".", "/")}.html`;
if (doc.qualname) {
url += `#${doc.qualname}`;
}
let heading;
2022-11-13 20:04:54 +00:00
switch (result.doc.kind) {
2021-11-07 20:53:18 +00:00
case "function":
2022-08-12 10:05:33 +00:00
if (doc.fullname.endsWith(".__init__")) {
heading = `<span class="name">${doc.fullname.replace(/\.__init__$/, "")}</span>${doc.signature}`;
} else {
heading = `<span class="def">${doc.funcdef}</span> <span class="name">${doc.fullname}</span>${doc.signature}`;
}
2021-11-07 20:53:18 +00:00
break;
case "class":
heading = `<span class="def">class</span> <span class="name">${doc.fullname}</span>`;
2022-01-16 15:44:50 +00:00
if (doc.bases)
heading += `<wbr>(<span class="base">${doc.bases}</span>)`;
heading += `:`;
break;
case "variable":
heading = `<span class="name">${doc.fullname}</span>`;
if (doc.annotation)
heading += `<span class="annotation">${doc.annotation}</span>`;
if (doc.default_value)
2023-02-19 18:32:00 +00:00
heading += `<span class="default_value"> = ${doc.default_value}</span>`;
2021-11-07 20:53:18 +00:00
break;
default:
heading = `<span class="name">${doc.fullname}</span>`;
break;
}
html += `
<section class="search-result">
2022-11-13 20:04:54 +00:00
<a href="${url}" class="attr ${doc.kind}">${heading}</a>
2021-11-07 20:53:18 +00:00
<div class="docstring">${doc.doc}</div>
</section>
`;
}
return html;
})());
}
if (getSearchTerm()) {
initialize();
searchBox.value = getSearchTerm();
onInput();
} else {
searchBox.addEventListener("focus", initialize, {once: true});
}
searchBox.addEventListener("keydown", e => {
if (["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) {
let focused = currentContent.querySelector(".search-result.focused");
if (!focused) {
currentContent.querySelector(".search-result").classList.add("focused");
} else if (
e.key === "ArrowDown"
&& focused.nextElementSibling
&& focused.nextElementSibling.classList.contains("search-result")
) {
focused.classList.remove("focused");
focused.nextElementSibling.classList.add("focused");
focused.nextElementSibling.scrollIntoView({
behavior: "smooth",
block: "nearest",
inline: "nearest"
});
} else if (
e.key === "ArrowUp"
&& focused.previousElementSibling
&& focused.previousElementSibling.classList.contains("search-result")
) {
focused.classList.remove("focused");
focused.previousElementSibling.classList.add("focused");
focused.previousElementSibling.scrollIntoView({
behavior: "smooth",
block: "nearest",
inline: "nearest"
});
} else if (
e.key === "Enter"
) {
focused.querySelector("a").click();
}
}
});
</script></body>
</html>