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

fitting (linear): fix indexing #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions oitg/fitting/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from . import FitBase

def parameter_initialiser(x, y, p):
k = (y[-1] - y[1]) / (x[-1] - x[1])
p['a'] = y[1] - x[1] * k
k = (y[-1] - y[0]) / (x[-1] - x[0])
p['a'] = y[0] - x[0] * k
Comment on lines +7 to +8
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also accept np.max(y)- np.min(y) / (np.max(x) - np.min(x). The existing code assumes that the x & y arrays are sorted, not necessarily true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. None of the fitting routines should assume sorted data, so the max/min implementation is more appropriate.

Copy link
Member

@pathfinder49 pathfinder49 Jul 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thought:

p['b'] = (np.max(y) -np.min(y)) / (np.max(x) - np.min(x))
idx = np.argmin(x)
p['a'] = y[idx] - x[idx] * p['b']

IIRC this estimates the offset with the user specified gradient (if supplied). Not that it should matter much for fitting a line...

p['b'] = k

def fitting_function(x, p):
Expand Down