Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BEA data analysis utils
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philipp Niedermayer
BEA data analysis utils
Commits
c74493b3
Commit
c74493b3
authored
2 years ago
by
Philipp Niedermayer
Browse files
Options
Downloads
Patches
Plain Diff
Add linear fit
parent
67d24118
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fitting.py
+10
-5
10 additions, 5 deletions
fitting.py
with
10 additions
and
5 deletions
fitting.py
+
10
−
5
View file @
c74493b3
...
...
@@ -3,6 +3,11 @@ import numpy as np
# Fitting
def
fit_linear
(
S
,
V
,
**
kwargs
):
result
=
fit_function
(
lambda
s
,
v0
,
m
:
v0
+
m
*
s
,
S
,
V
,
p0
=
(
np
.
mean
(
V
),
np
.
mean
(
np
.
diff
(
V
)
/
np
.
diff
(
S
))),
**
kwargs
)
param
,
param_error
,
function
,
[
X
,
_
]
=
result
return
param
,
param_error
,
function
,
[
X
,
function
(
X
,
*
param
)]
def
fit_gaussian
(
S
,
V
,
**
kwargs
):
gauss
=
lambda
s
,
v0
,
vp
,
s0
,
sigma
:
v0
+
vp
*
np
.
exp
(
-
0.5
*
((
s
-
s0
)
/
sigma
)
**
2
)
v0
=
np
.
min
(
V
)
...
...
@@ -12,7 +17,7 @@ def fit_gaussian(S, V, **kwargs):
result
=
fit_function
(
gauss
,
S
,
V
,
p0
=
(
v0
,
vp
,
s0
,
sigma
),
**
kwargs
)
param
,
param_error
,
function
,
[
X
,
_
]
=
result
param
[
3
]
=
np
.
abs
(
param
[
3
])
# return the positive sigma (could use bounds instead, but that's more likely to fail)
return
param
,
param_error
,
function
,
[
X
,
lorenzia
n
(
X
,
*
param
)]
return
param
,
param_error
,
function
,
[
X
,
functio
n
(
X
,
*
param
)]
def
fit_lorenzian
(
S
,
V
,
log
=
False
,
**
kwargs
):
lorenzian
=
lambda
s
,
v0
,
vp
,
s0
,
gamma
:
v0
+
vp
/
(
1
+
((
s
-
s0
)
/
gamma
)
**
2
)
...
...
@@ -23,16 +28,17 @@ def fit_lorenzian(S, V, log=False, **kwargs):
result
=
fit_function
(
lorenzian
,
S
,
V
,
p0
=
(
v0
,
vp
,
s0
,
sigma
),
**
kwargs
)
param
,
param_error
,
function
,
[
X
,
_
]
=
result
param
[
3
]
=
np
.
abs
(
param
[
3
])
# return the positive sigma (could use bounds instead, but that's more likely to fail)
return
param
,
param_error
,
function
,
[
X
,
lorenzia
n
(
X
,
*
param
)]
return
param
,
param_error
,
function
,
[
X
,
functio
n
(
X
,
*
param
)]
def
fit_function
(
function
,
x
,
y
,
p0
=
None
,
**
kwargs
):
def
fit_function
(
function
,
x
,
y
,
p0
=
None
,
extend
=
0
,
**
kwargs
):
"""
:param log: if the y-data is log-scaled
"""
param
,
cov
=
scipy
.
optimize
.
curve_fit
(
function
,
x
,
y
,
p0
,
**
kwargs
)
param_error
=
np
.
sqrt
(
np
.
abs
(
cov
.
diagonal
()))
X
=
np
.
linspace
(
min
(
x
),
max
(
x
),
1000
)
mi
,
ma
=
min
(
x
),
max
(
x
)
X
=
np
.
linspace
(
mi
-
(
ma
-
mi
)
*
extend
,
ma
+
(
ma
-
mi
)
*
extend
,
1000
)
return
param
,
param_error
,
function
,
[
X
,
function
(
X
,
*
param
)]
def
fit_exponential
(
S
,
V
,
**
kwargs
):
...
...
@@ -42,4 +48,3 @@ def fit_exponential(S, V, **kwargs):
s0
=
1
return
fit_function
(
exponential
,
S
,
V
,
p0
=
(
v0
,
vp
,
s0
),
**
kwargs
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment