Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bayesian Statistical Learning 2
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
Alina Bazarova
Bayesian Statistical Learning 2
Commits
53904323
Commit
53904323
authored
1 year ago
by
Steve Schmerler
Browse files
Options
Downloads
Patches
Plain Diff
Add plot to compare noise-free and noisy sigma
parent
de105e6c
No related branches found
No related tags found
1 merge request
!1
BLcourse2.3Add GP part
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
BLcourse2.3/gp_intro.py
+22
-1
22 additions, 1 deletion
BLcourse2.3/gp_intro.py
with
22 additions
and
1 deletion
BLcourse2.3/gp_intro.py
+
22
−
1
View file @
53904323
...
@@ -324,7 +324,10 @@ with torch.no_grad():
...
@@ -324,7 +324,10 @@ with torch.no_grad():
post_pred_y
=
likelihood
(
model
(
X_pred
))
post_pred_y
=
likelihood
(
model
(
X_pred
))
fig
,
axs
=
plt
.
subplots
(
ncols
=
2
,
figsize
=
(
12
,
5
))
fig
,
axs
=
plt
.
subplots
(
ncols
=
2
,
figsize
=
(
12
,
5
))
for
ii
,
(
ax
,
post_pred
)
in
enumerate
(
zip
(
axs
,
[
post_pred_f
,
post_pred_y
])):
fig_sigmas
,
ax_sigmas
=
plt
.
subplots
()
for
ii
,
(
ax
,
post_pred
,
name
)
in
enumerate
(
zip
(
axs
,
[
post_pred_f
,
post_pred_y
],
[
"
f
"
,
"
y
"
])
):
yf_mean
=
post_pred
.
mean
yf_mean
=
post_pred
.
mean
yf_samples
=
post_pred
.
sample
(
sample_shape
=
torch
.
Size
((
10
,)))
yf_samples
=
post_pred
.
sample
(
sample_shape
=
torch
.
Size
((
10
,)))
...
@@ -354,6 +357,23 @@ with torch.no_grad():
...
@@ -354,6 +357,23 @@ with torch.no_grad():
color
=
"
tab:orange
"
,
color
=
"
tab:orange
"
,
alpha
=
0.3
,
alpha
=
0.3
,
)
)
if
name
==
"
f
"
:
sigma_label
=
r
"
$\pm 2\sqrt{\mathrm{diag}(\Sigma)}$
"
zorder
=
1
else
:
sigma_label
=
(
r
"
$\pm 2\sqrt{\mathrm{diag}(\Sigma + \sigma_n^2\,I)}$
"
)
zorder
=
0
ax_sigmas
.
fill_between
(
X_pred
.
numpy
(),
lower
.
numpy
(),
upper
.
numpy
(),
label
=
"
confidence
"
+
sigma_label
,
color
=
"
tab:orange
"
if
name
==
"
f
"
else
"
tab:blue
"
,
alpha
=
0.5
,
zorder
=
zorder
,
)
y_min
=
y_train
.
min
()
y_min
=
y_train
.
min
()
y_max
=
y_train
.
max
()
y_max
=
y_train
.
max
()
y_span
=
y_max
-
y_min
y_span
=
y_max
-
y_min
...
@@ -361,6 +381,7 @@ with torch.no_grad():
...
@@ -361,6 +381,7 @@ with torch.no_grad():
plot_samples
(
ax
,
X_pred
,
yf_samples
,
label
=
"
posterior pred. samples
"
)
plot_samples
(
ax
,
X_pred
,
yf_samples
,
label
=
"
posterior pred. samples
"
)
if
ii
==
1
:
if
ii
==
1
:
ax
.
legend
()
ax
.
legend
()
ax_sigmas
.
legend
()
# When running as script
# When running as script
if
not
is_interactive
():
if
not
is_interactive
():
...
...
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