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
eed28bdc
Commit
eed28bdc
authored
2 years ago
by
Danilo Ferreira de Lima
Browse files
Options
Downloads
Patches
Plain Diff
Allow for no smoothing.
parent
c4fa650d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Add Kernel PCA as an alternative preprocessing step
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pes_to_spec/model.py
+13
-4
13 additions, 4 deletions
pes_to_spec/model.py
with
13 additions
and
4 deletions
pes_to_spec/model.py
+
13
−
4
View file @
eed28bdc
...
...
@@ -8,7 +8,6 @@ from autograd import grad
from
scipy.signal
import
fftconvolve
from
scipy.signal
import
find_peaks_cwt
from
scipy.optimize
import
fmin_l_bfgs_b
from
sklearn.preprocessing
import
StandardScaler
from
sklearn.decomposition
import
KernelPCA
,
PCA
from
sklearn.pipeline
import
Pipeline
,
FeatureUnion
from
sklearn.base
import
TransformerMixin
,
BaseEstimator
...
...
@@ -34,6 +33,7 @@ class PromptNotFoundError(Exception):
def
__str__
(
self
)
->
str
:
return
"
No prompt peak has been detected.
"
class
HighResolutionSmoother
(
TransformerMixin
,
BaseEstimator
):
"""
Smoothens out the high resolution data.
...
...
@@ -72,6 +72,8 @@ class HighResolutionSmoother(TransformerMixin, BaseEstimator):
Returns: Smoothened out spectrum.
"""
if
self
.
high_res_sigma
<=
0
:
return
X
# use a default energy axis is none is given
# assume only the energy step
energy
=
np
.
broadcast_to
(
self
.
energy
,
X
.
shape
)
...
...
@@ -449,6 +451,8 @@ class Model(TransformerMixin, BaseEstimator):
Set to None to perform no selection.
validation_size: Fraction (number between 0 and 1) of the data to take for
validation and systematic uncertainty estimate.
n_pca_nonlinear: Number of nonlinear PCA components added at the preprocessing stage
to obtain nonlinearities as an input and improve the prediction.
"""
def
__init__
(
self
,
...
...
@@ -465,9 +469,13 @@ class Model(TransformerMixin, BaseEstimator):
if
n_pca_nonlinear
<=
0
:
x_pca_model
=
PCA
(
n_pca_lr
,
whiten
=
True
)
else
:
x_pca_model
=
FeatureUnion
([(
'
linear
'
,
PCA
(
n_pca_lr
,
whiten
=
True
)),
x_pca_model
=
FeatureUnion
([
(
'
linear
'
,
PCA
(
n_pca_lr
,
whiten
=
True
)),
(
'
nonlinear
'
,
Pipeline
([(
'
prep
'
,
PCA
(
n_pca_lr
,
whiten
=
True
)),
(
'
kpca
'
,
KernelPCA
(
n_pca_nonlinear
,
kernel
=
'
rbf
'
,
n_jobs
=-
1
)),
(
'
kpca
'
,
KernelPCA
(
n_pca_nonlinear
,
kernel
=
'
rbf
'
,
gamma
=
0.1
,
n_jobs
=-
1
)),
])),
])
self
.
x_model
=
Pipeline
([
...
...
@@ -475,7 +483,8 @@ class Model(TransformerMixin, BaseEstimator):
(
'
pca
'
,
x_pca_model
),
(
'
unc
'
,
UncertaintyHolder
()),
])
self
.
y_model
=
Pipeline
([(
'
smoothen
'
,
HighResolutionSmoother
(
high_res_sigma
)),
self
.
y_model
=
Pipeline
([
(
'
smoothen
'
,
HighResolutionSmoother
(
high_res_sigma
)),
(
'
pca
'
,
PCA
(
n_pca_hr
,
whiten
=
False
)),
(
'
unc
'
,
UncertaintyHolder
()),
])
...
...
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