NHT changes plots combined fit (#166)

* NHT changes plots combined fit

* feat: Exception for illegal combination added and test fixed.

---------

Co-authored-by: Fabian Joswig <fabian.joswig@ed.ac.uk>
This commit is contained in:
nils-ht 2023-03-17 13:52:07 +00:00 committed by GitHub
parent 83204ce794
commit 2363b755dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 4 deletions

View file

@ -681,6 +681,42 @@ def test_combined_fit_no_autograd():
pe.least_squares(xs, ys, funcs, num_grad=True)
def test_plot_combined_fit_function():
def func_exp1(x):
return 0.3*anp.exp(0.5*x)
def func_exp2(x):
return 0.3*anp.exp(0.8*x)
xvals_b = np.arange(0,6)
xvals_a = np.arange(0,8)
def func_a(a,x):
return a[0]*anp.exp(a[1]*x)
def func_b(a,x):
return a[0]*anp.exp(a[2]*x)
corr_a = pe.Corr([pe.Obs([np.random.normal(item, item*1.5, 1000)],['ensemble1']) for item in func_exp1(xvals_a)])
corr_b = pe.Corr([pe.Obs([np.random.normal(item, item*1.4, 1000)],['ensemble1']) for item in func_exp2(xvals_b)])
funcs = {'a':func_a, 'b':func_b}
xs = {'a':xvals_a, 'b':xvals_b}
ys = {'a': [o[0] for o in corr_a.content],
'b': [o[0] for o in corr_b.content]}
corr_a.gm()
corr_b.gm()
comb_fit = pe.least_squares(xs, ys, funcs)
with pytest.raises(ValueError):
corr_a.show(x_range=[xs["a"][0], xs["a"][-1]], fit_res=comb_fit)
corr_a.show(x_range=[xs["a"][0], xs["a"][-1]], fit_res=comb_fit, fit_key="a")
corr_b.show(x_range=[xs["b"][0], xs["b"][-1]], fit_res=comb_fit, fit_key="b")
def test_combined_fit_invalid_fit_functions():
def func1(a, x):