-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where plots for multi-key fits where not rendered corr…
…ectly This addresses one comment in #10
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Example script for fit with multiple keys. | ||
See also https://github.com/ckoerber/lsqfit-gui/issues/10 | ||
""" | ||
import lsqfit | ||
import gvar as gv | ||
import numpy as np | ||
|
||
from lsqfitgui import run_server | ||
|
||
XX = dict( | ||
d1=np.array([1, 2, 3, 4]), | ||
d2=np.array([1, 2, 3, 4]), | ||
d3=np.array([1, 2, 3, 4]), | ||
d4=np.array([1, 2, 3, 4]), | ||
d5=np.array([5, 6, 7, 8]), | ||
) | ||
|
||
YY = dict( | ||
d1=["1.154(10)", "2.107(16)", "3.042(22)", "3.978(29)"], | ||
d2=["0.692(10)", "1.196(16)", "1.657(22)", "2.189(29)"], | ||
d3=["0.107(10)", "0.030(16)", "-0.027(22)", "-0.149(29)"], | ||
d4=["0.002(10)", "-0.197(16)", "-0.382(22)", "-0.627(29)"], | ||
d5=["1.869(10)", "2.198(16)", "2.502(22)", "2.791(29)"], | ||
) | ||
PRIOR = gv.gvar(dict(a="0(1)", s1="0(1)", s2="0(1)", s3="0(1)", s4="0(1)", s5="0(1)")) | ||
|
||
|
||
def fitfcn(x, p): | ||
"""Return linear fit function. | ||
$$f(x; a, s_n) = a + s_n * x$$ | ||
""" | ||
return {key: p["a"] + p[f"s{key[1:]}"] * x[key] for key in x} | ||
|
||
|
||
def main(): | ||
"""Run lsqfitgui server for multi-linear fit.""" | ||
run_server(lsqfit.nonlinear_fit(data=(XX, YY), fcn=fitfcn, prior=PRIOR)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters