Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philippe SWARTVAGHER
memory-contention
Commits
3b9203ba
Commit
3b9203ba
authored
Aug 26, 2021
by
Philippe SWARTVAGHER
Browse files
MultiCurveFit: add exclude_left option
parent
f23b2412
Changes
1
Hide whitespace changes
Inline
Side-by-side
plot/comm_comp_fit.py
View file @
3b9203ba
...
...
@@ -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
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment