Commit 3b9203ba authored by Philippe SWARTVAGHER's avatar Philippe SWARTVAGHER
Browse files

MultiCurveFit: add exclude_left option

parent f23b2412
......@@ -53,7 +53,7 @@ class CurveFit:
class MultiCurveFit:
def __init__(self, f, x, y, x_slices, y_std=None, bounds=(-np.inf, np.inf)):
def __init__(self, f, x, y, x_slices, y_std=None, bounds=(-np.inf, np.inf), exclude_left=False):
"""
f: the function to fit, for instance: lambda x, a, b, c: a*x**2+b*x+c,
can be a list of functions, ot use different function per slice
......@@ -63,9 +63,12 @@ class MultiCurveFit:
y_std: list of standard deviation for each y point (computed with np.std() for instance)
bounds: limit the space of parameters. For instance, if 0 <= a <= 3, 0 <= b <= 1 and 0 <= c <= 0.5,
then: bounds=(0, [3., 1., 0.5])
exclude_left: when True, exclude left bound of each slice, except first one
If x is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and x_slices is [3, 8], the slices will be:
[[0, 1, 2, 3], [3, 4, 5, 6, 7, 8], [8, 9, 10]]
With exclude_left=True, the slices will be:
[[0, 1, 2, 3], [4, 5, 6, 7, 8], [9, 10]]
"""
self.curves = []
self.x_slices = x_slices
......@@ -86,10 +89,18 @@ class MultiCurveFit:
_f = f[current_slice]
self.curves.append(CurveFit(_f, current_x, current_y, current_y_std, bounds))
current_x = current_x[-1:] # keep the last of the previous slice
current_y = current_y[-1:]
if current_y_std is not None:
current_y_std = current_y_std[-1:]
if exclude_left:
current_x = []
current_y = []
current_y_std = [] if y_std is not None else None
else:
# Next slice will start with the last x of the previous slice (to ensure continuity):
current_x = current_x[-1:]
current_y = current_y[-1:]
if current_y_std is not None:
current_y_std = current_y_std[-1:]
current_slice += 1
current_x.append(x[i])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment