Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pes_to_spec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Machine Learning projects.
pes_to_spec
Commits
5d6975c3
Commit
5d6975c3
authored
2 years ago
by
Danilo Ferreira de Lima
Browse files
Options
Downloads
Patches
Plain Diff
Switched to scipy's kde, which is smart enough to factorize the mean.
parent
106c3f5c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pes_to_spec/__init__.py
+1
-1
1 addition, 1 deletion
pes_to_spec/__init__.py
pes_to_spec/model.py
+6
-8
6 additions, 8 deletions
pes_to_spec/model.py
with
7 additions
and
9 deletions
pes_to_spec/__init__.py
+
1
−
1
View file @
5d6975c3
...
...
@@ -2,4 +2,4 @@
Estimate high-resolution photon spectrometer data from low-resolution non-invasive measurements.
"""
VERSION
=
"
0.1.
2
"
VERSION
=
"
0.1.
3
"
This diff is collapsed.
Click to expand it.
pes_to_spec/model.py
+
6
−
8
View file @
5d6975c3
...
...
@@ -13,7 +13,7 @@ from sklearn.pipeline import Pipeline
from
sklearn.kernel_approximation
import
Nystroem
#from sklearn.linear_model import ARDRegression
from
sklearn.linear_model
import
BayesianRidge
from
s
klearn.neighbors
import
KernelDensity
from
s
cipy.stats
import
gaussian_kde
from
sklearn.ensemble
import
IsolationForest
from
functools
import
reduce
from
itertools
import
product
...
...
@@ -765,14 +765,13 @@ class Model(TransformerMixin, BaseEstimator):
Return: weights.
"""
self
.
kde_xgm
=
KernelDensity
(
bandwidth
=
"
scott
"
,
kernel
=
"
gaussian
"
)
self
.
kde_xgm
.
fit
(
intensity
.
reshape
(
-
1
,
1
))
self
.
kde_xgm
=
gaussian_kde
(
intensity
.
reshape
(
-
1
),
bw_method
=
"
scott
"
)
self
.
mu_xgm
=
np
.
mean
(
intensity
.
reshape
(
-
1
),
axis
=
0
)
self
.
sigma_xgm
=
np
.
std
(
intensity
.
reshape
(
-
1
),
axis
=
0
)
q
=
np
.
quantile
(
intensity
,
[
0.10
,
0.90
])
l
,
h
=
q
[
0
],
q
[
1
]
x
=
intensity
*
((
intensity
>
l
)
&
(
intensity
<
h
))
+
l
*
(
intensity
<=
l
)
+
h
*
(
intensity
>=
h
)
log_prob
=
self
.
kde_xgm
.
score_samples
(
x
.
reshape
(
-
1
,
1
))
log_prob
=
self
.
kde_xgm
.
logpdf
(
x
.
reshape
(
-
1
))
w
=
np
.
exp
(
-
log_prob
)
w
=
w
/
np
.
median
(
w
)
return
w
...
...
@@ -920,8 +919,7 @@ class Model(TransformerMixin, BaseEstimator):
# get intensity effect
intensity
=
np
.
sum
(
z
,
axis
=
1
)
self
.
kde_intensity
=
KernelDensity
(
bandwidth
=
"
scott
"
,
kernel
=
"
gaussian
"
)
self
.
kde_intensity
.
fit
(
intensity
.
reshape
(
-
1
,
1
))
self
.
kde_intensity
=
gaussian_kde
(
intensity
.
reshape
(
-
1
),
bw_method
=
"
scott
"
)
self
.
mu_intensity
=
np
.
mean
(
intensity
.
reshape
(
-
1
),
axis
=
0
)
self
.
sigma_intensity
=
np
.
std
(
intensity
.
reshape
(
-
1
),
axis
=
0
)
...
...
@@ -970,11 +968,11 @@ class Model(TransformerMixin, BaseEstimator):
low_pca
=
pca_model
.
transform
(
low_res
)
return
self
.
ood
[
'
full
'
].
predict
(
low_pca
)
def
xgm_profile
(
self
)
->
KernelDensity
:
def
xgm_profile
(
self
)
->
gaussian_kde
:
"""
Get KDE for the XGM intensity.
"""
return
self
.
kde_xgm
def
intensity_profile
(
self
)
->
KernelDensity
:
def
intensity_profile
(
self
)
->
gaussian_kde
:
"""
Get KDE for the predicted intensity.
"""
return
self
.
kde_intensity
...
...
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