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
2e3f6d06
Commit
2e3f6d06
authored
2 years ago
by
Danilo Ferreira de Lima
Browse files
Options
Downloads
Patches
Plain Diff
Added Nystroem with an insane kernel dimensionality to check if it improves something.
parent
44353618
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Added kernel approximation with the Nystroem sub-space projection method as an alternative
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pes_to_spec/model.py
+10
-4
10 additions, 4 deletions
pes_to_spec/model.py
with
10 additions
and
4 deletions
pes_to_spec/model.py
+
10
−
4
View file @
2e3f6d06
...
@@ -14,6 +14,7 @@ from sklearn.base import TransformerMixin, BaseEstimator
...
@@ -14,6 +14,7 @@ from sklearn.base import TransformerMixin, BaseEstimator
from
sklearn.base
import
RegressorMixin
from
sklearn.base
import
RegressorMixin
from
sklearn.kernel_approximation
import
Nystroem
from
sklearn.kernel_approximation
import
Nystroem
from
sklearn.linear_model
import
ARDRegression
from
sklearn.linear_model
import
ARDRegression
#from sklearn.svm import LinearSVR
#from sklearn.gaussian_process import GaussianProcessRegressor
#from sklearn.gaussian_process import GaussianProcessRegressor
#from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
#from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
from
itertools
import
product
from
itertools
import
product
...
@@ -470,6 +471,7 @@ class MultiOutputWithStd(MetaEstimatorMixin, BaseEstimator):
...
@@ -470,6 +471,7 @@ class MultiOutputWithStd(MetaEstimatorMixin, BaseEstimator):
"""
"""
y
=
Parallel
(
n_jobs
=
self
.
n_jobs
)(
y
=
Parallel
(
n_jobs
=
self
.
n_jobs
)(
delayed
(
e
.
predict
)(
X
,
return_std
)
for
e
in
self
.
estimators_
delayed
(
e
.
predict
)(
X
,
return_std
)
for
e
in
self
.
estimators_
#delayed(e.predict)(X) for e in self.estimators_
)
)
if
return_std
:
if
return_std
:
y
,
unc
=
zip
(
*
y
)
y
,
unc
=
zip
(
*
y
)
...
@@ -500,13 +502,13 @@ class Model(TransformerMixin, BaseEstimator):
...
@@ -500,13 +502,13 @@ class Model(TransformerMixin, BaseEstimator):
def
__init__
(
self
,
def
__init__
(
self
,
channels
:
List
[
str
]
=
[
f
"
channel_
{
j
}
_
{
k
}
"
channels
:
List
[
str
]
=
[
f
"
channel_
{
j
}
_
{
k
}
"
for
j
,
k
in
product
(
range
(
1
,
5
),
[
"
A
"
,
"
B
"
,
"
C
"
,
"
D
"
])],
for
j
,
k
in
product
(
range
(
1
,
5
),
[
"
A
"
,
"
B
"
,
"
C
"
,
"
D
"
])],
n_pca_lr
:
int
=
6
00
,
n_pca_lr
:
int
=
10
00
,
n_pca_hr
:
int
=
3
0
,
n_pca_hr
:
int
=
4
0
,
high_res_sigma
:
float
=
0.2
,
high_res_sigma
:
float
=
0.2
,
tof_start
:
Optional
[
int
]
=
None
,
tof_start
:
Optional
[
int
]
=
None
,
delta_tof
:
Optional
[
int
]
=
300
,
delta_tof
:
Optional
[
int
]
=
300
,
validation_size
:
float
=
0.05
,
validation_size
:
float
=
0.05
,
n_nonlinear_kernel
:
int
=
1000
):
n_nonlinear_kernel
:
int
=
1000
0
):
# models
# models
self
.
x_model
=
Pipeline
([
self
.
x_model
=
Pipeline
([
(
'
select
'
,
SelectRelevantLowResolution
(
channels
,
tof_start
,
delta_tof
)),
(
'
select
'
,
SelectRelevantLowResolution
(
channels
,
tof_start
,
delta_tof
)),
...
@@ -522,7 +524,8 @@ class Model(TransformerMixin, BaseEstimator):
...
@@ -522,7 +524,8 @@ class Model(TransformerMixin, BaseEstimator):
if
n_nonlinear_kernel
>
0
:
if
n_nonlinear_kernel
>
0
:
fit_steps
+=
[(
'
fex
'
,
Nystroem
(
n_components
=
n_nonlinear_kernel
,
kernel
=
'
rbf
'
,
gamma
=
None
,
n_jobs
=-
1
))]
fit_steps
+=
[(
'
fex
'
,
Nystroem
(
n_components
=
n_nonlinear_kernel
,
kernel
=
'
rbf
'
,
gamma
=
None
,
n_jobs
=-
1
))]
#fit_steps += [('regression', FitModel())]
#fit_steps += [('regression', FitModel())]
fit_steps
+=
[(
'
regression
'
,
MultiOutputWithStd
(
ARDRegression
(
n_iter
=
10
)))]
fit_steps
+=
[(
'
regression
'
,
MultiOutputWithStd
(
ARDRegression
(
n_iter
=
30
,
verbose
=
True
)))]
#fit_steps += [('regression', MultiOutputWithStd(LinearSVR(verbose=10, max_iter=2000, tol=1e-5)))]
self
.
fit_model
=
Pipeline
(
fit_steps
)
self
.
fit_model
=
Pipeline
(
fit_steps
)
# size of the test subset
# size of the test subset
...
@@ -567,6 +570,7 @@ class Model(TransformerMixin, BaseEstimator):
...
@@ -567,6 +570,7 @@ class Model(TransformerMixin, BaseEstimator):
"""
"""
x_t
=
self
.
x_model
.
fit_transform
(
low_res_data
)
x_t
=
self
.
x_model
.
fit_transform
(
low_res_data
)
y_t
=
self
.
y_model
.
fit_transform
(
high_res_data
,
smoothen__energy
=
high_res_photon_energy
)
y_t
=
self
.
y_model
.
fit_transform
(
high_res_data
,
smoothen__energy
=
high_res_photon_energy
)
#self.fit_model.set_params(fex__gamma=1.0/float(x_t.shape[0]))
self
.
fit_model
.
fit
(
x_t
,
y_t
)
self
.
fit_model
.
fit
(
x_t
,
y_t
)
# calculate the effect of the PCA
# calculate the effect of the PCA
...
@@ -640,6 +644,8 @@ class Model(TransformerMixin, BaseEstimator):
...
@@ -640,6 +644,8 @@ class Model(TransformerMixin, BaseEstimator):
"""
"""
low_pca
=
self
.
x_model
.
transform
(
low_res_data
)
low_pca
=
self
.
x_model
.
transform
(
low_res_data
)
high_pca
,
high_pca_unc
=
self
.
fit_model
.
predict
(
low_pca
,
return_std
=
True
)
high_pca
,
high_pca_unc
=
self
.
fit_model
.
predict
(
low_pca
,
return_std
=
True
)
#high_pca = self.fit_model.predict(low_pca)
#high_pca_unc = 0
n_trains
=
high_pca
.
shape
[
0
]
n_trains
=
high_pca
.
shape
[
0
]
pca_y
=
np
.
concatenate
((
high_pca
,
pca_y
=
np
.
concatenate
((
high_pca
,
high_pca
+
high_pca_unc
),
high_pca
+
high_pca_unc
),
...
...
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