Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line fitting fails for two data points #36

Open
mgely opened this issue Mar 31, 2021 · 0 comments
Open

Line fitting fails for two data points #36

mgely opened this issue Mar 31, 2021 · 0 comments

Comments

@mgely
Copy link

mgely commented Mar 31, 2021

The following code fails

from oitg.fitting import line
line.fit([0,1],[0,1])

with error

Traceback (most recent call last):
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\oitg-0.1-py3.9.egg\oitg\fitting\FitBase.py", line 249, in fit
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\scipy\optimize\minpack.py", line 795, in curve_fit
    res = least_squares(func, p0, jac=jac, bounds=bounds, method=method,
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\scipy\optimize\_lsq\least_squares.py", line 805, in least_squares
    raise ValueError("`x0` is infeasible.")
ValueError: `x0` is infeasible.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "y:/testing/scratch_mfg/line_fit.py", line 2, in <module>
    line.fit([0,1],[0,1])
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\oitg-0.1-py3.9.egg\oitg\fitting\FitBase.py", line 255, in fit
oitg.fitting.FitBase.FitError: `x0` is infeasible.

One obvious thing that would fail is the parameter_initialiser in line.py

def parameter_initialiser(x, y, p):
k = (y[-1] - y[1]) / (x[-1] - x[1])
p['a'] = y[1] - x[1] * k
p['b'] = k

which would give division by 0 errors for a size two array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant