Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
journal_eiv
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jörg Martin
journal_eiv
Commits
77b46e57
Commit
77b46e57
authored
3 years ago
by
Jörg Martin
Browse files
Options
Downloads
Patches
Plain Diff
Averaging in coverage computation
parent
0a001305
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
EIVPackage/EIVGeneral/coverage_metrics.py
+7
-1
7 additions, 1 deletion
EIVPackage/EIVGeneral/coverage_metrics.py
Experiments/evaluate_metrics.py
+5
-3
5 additions, 3 deletions
Experiments/evaluate_metrics.py
with
12 additions
and
4 deletions
EIVPackage/EIVGeneral/coverage_metrics.py
+
7
−
1
View file @
77b46e57
...
...
@@ -34,6 +34,7 @@ def multivariate_interval_length(dim, q=0.95):
def
epistemic_coverage
(
not_averaged_predictions
,
y
,
q
=
0.95
,
normalize_errors
=
False
,
average_predictions
=
True
,
noisy_y
=
True
):
"""
Returns the average coverage of `y` by the interval
...
...
@@ -41,7 +42,7 @@ def epistemic_coverage(not_averaged_predictions, y, q=0.95,
-
"
q-Interval
"
is the interval of measure `q` under the standard normal,
where
-
"
predictions
"
are the entries of the first component of the tuple
`not_averaged_predictions`,
`not_averaged_predictions`,
averaged if `average_predictions` is True.
-
"
prefactor either equals the epistemic uncertainty, computed from the
first component of `not_averaged_predictions`,if
`normalize_errors` is set to False, or 1 if it is true.
...
...
@@ -62,12 +63,15 @@ def epistemic_coverage(not_averaged_predictions, y, q=0.95,
:param normalize_errors: If True, the deviations between predictions and
`y` are normalized by the total uncertainty, computed from the aleatoric
and epistemic uncertainty and the coverage w.r.t. q-interval is computed.
:param average_predictions: If True, average the predictions before
computing the coverage. Defaults to False.
:param noisy_y: Boolean. If True (the default), `y` is treated as noisy and
the total uncertainty is considered. If False, `y` is treated as the
unnoisy ground truth.
:returns: numerical_coverage, theoretical_coverage
"""
out
,
sigmas
=
not_averaged_predictions
# add repetition axis
y
=
y
[:,
None
,...]
sigmas
=
sigmas
[:,
None
,...]
# add an output axis if necessary
...
...
@@ -85,6 +89,8 @@ def epistemic_coverage(not_averaged_predictions, y, q=0.95,
assert
y
.
shape
[
2
]
==
out
.
shape
[
2
]
# compute epistemic uncertainty
epis_unc
=
torch
.
std
(
out
,
dim
=
1
,
keepdim
=
True
)
if
average_predictions
:
out
=
torch
.
mean
(
out
,
dim
=
1
,
keepdim
=
True
)
assert
epis_unc
.
shape
==
sigmas
.
shape
# compute total uncertainty
if
noisy_y
:
...
...
This diff is collapsed.
Click to expand it.
Experiments/evaluate_metrics.py
+
5
−
3
View file @
77b46e57
...
...
@@ -19,7 +19,7 @@ from EIVGeneral.coverage_metrics import epistemic_coverage, normalized_std
# read in data via --data option
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
--data
"
,
help
=
"
Loads data
"
,
default
=
'
linear
'
)
parser
.
add_argument
(
"
--data
"
,
help
=
"
Loads data
"
,
default
=
'
quadratic
'
)
parser
.
add_argument
(
"
--no-autoindent
"
,
help
=
""
,
action
=
"
store_true
"
)
# to avoid conflics in IPython
args
=
parser
.
parse_args
()
...
...
@@ -127,7 +127,7 @@ def collect_metrics(x_y_pairs, seed=0,
noneiv_metrics
[
'
rmse
'
]
=
np
.
sqrt
(
np
.
mean
(
scaled_res
**
2
))
noneiv_metrics
[
'
bias
'
]
=
np
.
mean
(
scaled_res
)
noneiv_metrics
[
'
coverage_numerical
'
],
noneiv_metrics
[
'
coverage_theory
'
]
=
\
epistemic_coverage
(
not_averaged_predictions
,
y
,
normalize_errors
=
False
)
epistemic_coverage
(
not_averaged_predictions
,
y
,
normalize_errors
=
False
,
average_predictions
=
True
)
noneiv_metrics
[
'
coverage_normalized
'
],
_
=
\
epistemic_coverage
(
not_averaged_predictions
,
y
,
normalize_errors
=
True
)
noneiv_metrics
[
'
res_std
'
]
=
normalized_std
(
not_averaged_predictions
,
y
)
...
...
@@ -137,6 +137,7 @@ def collect_metrics(x_y_pairs, seed=0,
noneiv_metrics
[
'
true_coverage_numerical
'
],
\
noneiv_metrics
[
'
true_coverage_theory
'
]
=
\
epistemic_coverage
(
not_averaged_predictions
,
true_y
,
average_predictions
=
True
,
normalize_errors
=
False
,
noisy_y
=
False
)
...
...
@@ -194,7 +195,7 @@ def collect_metrics(x_y_pairs, seed=0,
eiv_metrics
[
'
rmse
'
]
=
np
.
sqrt
(
np
.
mean
(
scaled_res
**
2
))
eiv_metrics
[
'
bias
'
]
=
np
.
mean
(
scaled_res
)
eiv_metrics
[
'
coverage_numerical
'
],
eiv_metrics
[
'
coverage_theory
'
]
=
\
epistemic_coverage
(
not_averaged_predictions
,
y
,
normalize_errors
=
False
)
epistemic_coverage
(
not_averaged_predictions
,
y
,
normalize_errors
=
False
,
average_predictions
=
True
)
eiv_metrics
[
'
coverage_normalized
'
],
_
=
\
epistemic_coverage
(
not_averaged_predictions
,
y
,
normalize_errors
=
True
)
eiv_metrics
[
'
res_std
'
]
=
normalized_std
(
not_averaged_predictions
,
y
)
...
...
@@ -204,6 +205,7 @@ def collect_metrics(x_y_pairs, seed=0,
eiv_metrics
[
'
true_coverage_numerical
'
],
\
eiv_metrics
[
'
true_coverage_theory
'
]
=
\
epistemic_coverage
(
not_averaged_predictions
,
true_y
,
average_predictions
=
True
,
normalize_errors
=
False
,
noisy_y
=
False
)
...
...
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