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
753dec56
Commit
753dec56
authored
2 years ago
by
Danilo Ferreira de Lima
Browse files
Options
Downloads
Patches
Plain Diff
Fix and parallelize inference of the compatibility per channel.
parent
0c23a584
No related branches found
No related tags found
1 merge request
!5
Check consistency per channel
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pes_to_spec/model.py
+23
-7
23 additions, 7 deletions
pes_to_spec/model.py
with
23 additions
and
7 deletions
pes_to_spec/model.py
+
23
−
7
View file @
753dec56
...
@@ -20,6 +20,7 @@ from sklearn.model_selection import train_test_split
...
@@ -20,6 +20,7 @@ from sklearn.model_selection import train_test_split
from
sklearn.base
import
clone
,
MetaEstimatorMixin
from
sklearn.base
import
clone
,
MetaEstimatorMixin
from
joblib
import
Parallel
,
delayed
from
joblib
import
Parallel
,
delayed
from
functools
import
partial
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Union
,
Tuple
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Union
,
Tuple
...
@@ -640,6 +641,24 @@ class Model(TransformerMixin, BaseEstimator):
...
@@ -640,6 +641,24 @@ class Model(TransformerMixin, BaseEstimator):
return
high_res
return
high_res
def
get_channel_quality
(
self
,
channel
:
str
,
low_res
:
Dict
[
str
,
np
.
ndarray
],
channel_pca_model
:
Pipeline
)
->
float
:
"""
Get the compatibility for a single channel.
Args:
channel: The channel.
low_res: The data in a dictionary.
pca_model: The PCA model.
Returns: the compatibility factor.
"""
pca_model
=
channel_pca_model
[
channel
].
named_steps
[
'
pca
'
]
low_pca
=
pca_model
.
transform
(
low_res
[
channel
])
low_pca_rec
=
pca_model
.
inverse_transform
(
low_pca
)
low_pca_unc
=
channel_pca_model
.
named_steps
[
'
unc
'
].
uncertainty
()
low_pca_dev
=
np
.
sqrt
(
np
.
mean
((
low_res
[
channel
]
-
low_pca_rec
)
**
2
,
axis
=
1
,
keepdims
=
True
))
return
low_pca_dev
/
low_pca_unc
def
check_compatibility_per_channel
(
self
,
low_res_data
:
Dict
[
str
,
np
.
ndarray
])
->
Dict
[
str
,
np
.
ndarray
]:
def
check_compatibility_per_channel
(
self
,
low_res_data
:
Dict
[
str
,
np
.
ndarray
])
->
Dict
[
str
,
np
.
ndarray
]:
"""
"""
Check if a new low-resolution data source is compatible with the one used in training, by
Check if a new low-resolution data source is compatible with the one used in training, by
...
@@ -653,13 +672,10 @@ class Model(TransformerMixin, BaseEstimator):
...
@@ -653,13 +672,10 @@ class Model(TransformerMixin, BaseEstimator):
selection_model
=
self
.
x_model
[
'
select
'
]
selection_model
=
self
.
x_model
[
'
select
'
]
low_res
=
selection_model
.
transform
(
low_res_data
,
keep_dictionary_structure
=
True
)
low_res
=
selection_model
.
transform
(
low_res_data
,
keep_dictionary_structure
=
True
)
quality
=
{
channel
:
0.0
for
channel
in
low_res
.
keys
()}
quality
=
{
channel
:
0.0
for
channel
in
low_res
.
keys
()}
for
channel
in
low_res
.
keys
():
channels
=
list
(
low_res
.
keys
())
pca_model
=
self
.
channel_pca_model
[
channel
].
named_steps
[
'
pca
'
]
with
mp
.
Pool
(
len
(
low_res
.
keys
()))
as
p
:
low_pca
=
pca_model
.
transform
(
low_res
[
channel
])
values
=
p
.
map
(
partial
(
self
.
get_channel_quality
,
low_res
=
low_res
,
channel_pca_model
=
self
.
channel_pca_model
),
channels
)
low_pca_rec
=
pca_model
.
inverse_transform
(
low_pca
)
quality
=
dict
(
zip
(
channels
,
values
))
low_pca_unc
=
self
.
channel_pca_model
.
named_steps
[
'
unc
'
].
uncertainty
()
low_pca_dev
=
np
.
sqrt
(
np
.
mean
((
low_res
[
channel
]
-
low_pca_rec
)
**
2
,
axis
=
1
,
keepdims
=
True
))
quality
[
channel
]
=
low_pca_dev
/
low_pca_unc
return
quality
return
quality
def
check_compatibility
(
self
,
low_res_data
:
Dict
[
str
,
np
.
ndarray
])
->
np
.
ndarray
:
def
check_compatibility
(
self
,
low_res_data
:
Dict
[
str
,
np
.
ndarray
])
->
np
.
ndarray
:
...
...
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