Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KI-WaVo
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Landesamt für Umwelt
KI-WaVo
Commits
e3bf0ac3
Commit
e3bf0ac3
authored
5 months ago
by
Michel Spils
Browse files
Options
Downloads
Patches
Plain Diff
conformal prediction callback
parent
b47e4d15
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/callbacks.py
+1
-1
1 addition, 1 deletion
src/utils/callbacks.py
src/utils/metrics.py
+29
-1
29 additions, 1 deletion
src/utils/metrics.py
with
30 additions
and
2 deletions
src/utils/callbacks.py
+
1
−
1
View file @
e3bf0ac3
...
...
@@ -33,7 +33,7 @@ class WaVoCallback(Callback):
"""
# pylint: disable-next=dangerous-default-value
def
__init__
(
self
,
chosen_metrics
=
[
'
mse
'
,
'
mae
'
,
'
kge
'
,
'
rmse
'
,
'
r2
'
,
'
nse
'
,
'
p10
'
,
'
p20
'
,
'
wape
'
],
ensemble
=
False
):
def
__init__
(
self
,
chosen_metrics
=
[
'
mse
'
,
'
mae
'
,
'
kge
'
,
'
rmse
'
,
'
r2
'
,
'
nse
'
,
'
p10
'
,
'
p20
'
,
'
wape
'
,
'
conf50
'
,
'
conf10
'
,
'
conf05
'
],
ensemble
=
False
):
super
().
__init__
()
self
.
chosen_metrics
=
mt
.
get_metric_dict
(
chosen_metrics
)
...
...
This diff is collapsed.
Click to expand it.
src/utils/metrics.py
+
29
−
1
View file @
e3bf0ac3
...
...
@@ -6,6 +6,30 @@ import torch
from
torch
import
Tensor
def
conformal_series
(
y_true
:
Tensor
,
y_pred
:
Tensor
,
alpha
:
float
=
0.95
)
->
Tensor
:
"""
Calculate conformal prediction scores for multiple sets of predictions.
Parameters:
-----------
y_true : torch.Tensor
True target values
y_pred : torch.Tensor
Predicted values
alpha : float, optional (default=0.05)
1 - Desired confidence level (between 0 and 1)
Returns:
--------
conformity_scores : torch.Tensor
The calculated conformity scores for each of the 48 sets
"""
confidence
=
1
-
alpha
residuals
=
torch
.
abs
(
y_true
-
y_pred
)
conformity_scores
=
torch
.
quantile
(
residuals
,
confidence
,
dim
=
0
)
return
conformity_scores
def
nse_series
(
y_true
:
Tensor
,
y_pred
:
Tensor
)
->
Tensor
:
"""
Calculates NSE for all prediction steps,
...
...
@@ -187,7 +211,11 @@ def get_metric_dict(metric_name_list) -> dict:
'
p20
'
:
p20_series
,
'
rmse
'
:
rmse_series
,
'
r2
'
:
r_squared_series
,
'
wape
'
:
wape_series
}
'
wape
'
:
wape_series
,
'
conf50
'
:
lambda
x
,
y
:
conformal_series
(
x
,
y
,
0.5
),
'
conf10
'
:
lambda
x
,
y
:
conformal_series
(
x
,
y
,
0.1
),
'
conf05
'
:
lambda
x
,
y
:
conformal_series
(
x
,
y
,
0.05
)
}
metrics
=
{}
for
el
in
metric_name_list
:
...
...
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