mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
chore: Exception in least_squares specified.
This commit is contained in:
parent
e6051d7ba0
commit
80f4eef912
2 changed files with 7 additions and 7 deletions
|
@ -192,10 +192,10 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
|
||||||
key_ls = sorted(list(xd.keys()))
|
key_ls = sorted(list(xd.keys()))
|
||||||
|
|
||||||
if sorted(list(yd.keys())) != key_ls:
|
if sorted(list(yd.keys())) != key_ls:
|
||||||
raise Exception('x and y dictionaries do not contain the same keys.')
|
raise ValueError('x and y dictionaries do not contain the same keys.')
|
||||||
|
|
||||||
if sorted(list(funcd.keys())) != key_ls:
|
if sorted(list(funcd.keys())) != key_ls:
|
||||||
raise Exception('x and func dictionaries do not contain the same keys.')
|
raise ValueError('x and func dictionaries do not contain the same keys.')
|
||||||
|
|
||||||
x_all = np.concatenate([np.array(xd[key]) for key in key_ls])
|
x_all = np.concatenate([np.array(xd[key]) for key in key_ls])
|
||||||
y_all = np.concatenate([np.array(yd[key]) for key in key_ls])
|
y_all = np.concatenate([np.array(yd[key]) for key in key_ls])
|
||||||
|
@ -215,7 +215,7 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
|
||||||
if not callable(funcd[key]):
|
if not callable(funcd[key]):
|
||||||
raise TypeError('func (key=' + key + ') is not a function.')
|
raise TypeError('func (key=' + key + ') is not a function.')
|
||||||
if np.asarray(xd[key]).shape[-1] != len(yd[key]):
|
if np.asarray(xd[key]).shape[-1] != len(yd[key]):
|
||||||
raise Exception('x and y input (key=' + key + ') do not have the same length')
|
raise ValueError('x and y input (key=' + key + ') do not have the same length')
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
try:
|
try:
|
||||||
funcd[key](np.arange(i), x_all.T[0])
|
funcd[key](np.arange(i), x_all.T[0])
|
||||||
|
@ -680,7 +680,7 @@ def fit_lin(x, y, **kwargs):
|
||||||
out = least_squares(x, y, f, **kwargs)
|
out = least_squares(x, y, f, **kwargs)
|
||||||
return out.fit_parameters
|
return out.fit_parameters
|
||||||
else:
|
else:
|
||||||
raise Exception('Unsupported types for x')
|
raise TypeError('Unsupported types for x')
|
||||||
|
|
||||||
|
|
||||||
def qqplot(x, o_y, func, p, title=""):
|
def qqplot(x, o_y, func, p, title=""):
|
||||||
|
|
|
@ -713,15 +713,15 @@ def test_combined_fit_invalid_fit_functions():
|
||||||
|
|
||||||
|
|
||||||
def test_combined_fit_invalid_input():
|
def test_combined_fit_invalid_input():
|
||||||
xvals =[]
|
xvals = []
|
||||||
yvals =[]
|
yvals = []
|
||||||
err = 0.1
|
err = 0.1
|
||||||
def func_valid(a,x):
|
def func_valid(a,x):
|
||||||
return a[0] + a[1] * x
|
return a[0] + a[1] * x
|
||||||
for x in range(1, 8, 2):
|
for x in range(1, 8, 2):
|
||||||
xvals.append(x)
|
xvals.append(x)
|
||||||
yvals.append(pe.pseudo_Obs(x + np.random.normal(0.0, err), err, 'test1') + pe.pseudo_Obs(0, err / 100, 'test2', samples=87))
|
yvals.append(pe.pseudo_Obs(x + np.random.normal(0.0, err), err, 'test1') + pe.pseudo_Obs(0, err / 100, 'test2', samples=87))
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(ValueError):
|
||||||
pe.least_squares({'a':xvals}, {'b':yvals}, {'a':func_valid})
|
pe.least_squares({'a':xvals}, {'b':yvals}, {'a':func_valid})
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
pe.least_squares({'a':xvals}, {'a':yvals}, {'a':func_valid})
|
pe.least_squares({'a':xvals}, {'a':yvals}, {'a':func_valid})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue