-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
**BREAKING** change of sampleplot
behaviour and defaults
#213
Changes from 11 commits
54355de
8fccaaf
2f1204b
3f47368
98ec20b
0aff474
71eeb10
cbeb5a8
e4ddf18
58a8e71
c75de4f
aeab678
f5a7772
477e416
707ef25
528124e
830249b
d0c1f5b
bd3b3ed
c4fa4d7
2c47712
add2dec
a750d15
3d25778
36f91b3
ab37628
3c6a2ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,19 +212,18 @@ mean(logpdf(gp_posterior(x_train, y_train, p)(x_test), y_test) for p in samples) | |
# We sample 5 functions from each posterior GP given by the final 100 samples of kernel | ||
# parameters. | ||
|
||
plt = scatter( | ||
x_train, | ||
y_train; | ||
xlim=(0, 1), | ||
xlabel="x", | ||
ylabel="y", | ||
title="posterior (AdvancedHMC)", | ||
label="Train Data", | ||
) | ||
for p in samples[(end - 100):end] | ||
sampleplot!(plt, 0:0.02:1, gp_posterior(x_train, y_train, p); samples=5) | ||
plt = plot(; xlim=(0, 1), xlabel="x", ylabel="y", title="posterior (AdvancedHMC)") | ||
for (i, p) in enumerate(samples[(end - 100):end]) | ||
sampleplot!( | ||
plt, | ||
0:0.02:1, | ||
gp_posterior(x_train, y_train, p); | ||
samples=5, | ||
label=(i == 1 ? "samples" : nothing), | ||
) | ||
end | ||
scatter!(plt, x_test, y_test; label="Test Data") | ||
scatter!(plt, x_train, y_train; label="Train Data", markercolor=1) | ||
devmotion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
scatter!(plt, x_test, y_test; label="Test Data", markercolor=2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the only way of getting the scatter markers of train/test data on top of the lines for the samples is by having the call later. That then also affects the order of legend entries. I wish there was something straightforward like the z-order in matplotlib! If any of you has any ideas for how to get that behaviour, I'd love to find out (google didn't really help me here).. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think you just have to plot in whatever order you want them to appear and then you have to live with the legend. At least I don't know of any other way. |
||
plt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NB- is the explicit passing around of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure 🤷 I know that I had to use it sometimes since the plot was not returned from |
||
|
||
# #### DynamicHMC | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
length(x) == length(gp.x) || | ||
throw(DimensionMismatch("length of `x` and `gp.x` has to be equal")) | ||
scale::Float64 = pop!(plotattributes, :ribbon_scale, 1.0) | ||
scale > 0.0 || error("`bandwidth` keyword argument must be non-negative") | ||
scale >= 0.0 || error("`ribbon_scale` keyword argument must be non-negative") | ||
|
||
# compute marginals | ||
μ, σ2 = mean_and_var(gp) | ||
|
@@ -82,16 +82,19 @@ Plot samples from the projection `f` of a Gaussian process versus `x`. | |
Make sure to load [Plots.jl](https://github.com/JuliaPlots/Plots.jl) before you use | ||
this function. | ||
|
||
When plotting multiple samples, these are treated as a _single_ series (i.e., | ||
only a single entry will be added to the legend when providing a `label`). | ||
|
||
# Example | ||
|
||
```julia | ||
using Plots | ||
|
||
gp = GP(SqExponentialKernel()) | ||
sampleplot(gp(rand(5)); samples=10, markersize=5) | ||
sampleplot(gp(rand(5)); samples=10, linealpha=1.0) | ||
``` | ||
The given example plots 10 samples from the projection of the GP `gp`. The `markersize` is modified | ||
from default of 0.5 to 5. | ||
The given example plots 10 samples from the projection of the GP `gp`. | ||
The `linealpha` is modified from default of 0.2 to 1. | ||
|
||
--- | ||
sampleplot(x::AbstractVector, gp::AbstractGP; samples=1, kwargs...) | ||
|
@@ -115,18 +118,17 @@ SamplePlot((f,)::Tuple{<:FiniteGP}) = SamplePlot((f.x, f)) | |
SamplePlot((x, gp)::Tuple{<:AbstractVector,<:AbstractGP}) = SamplePlot((gp(x, 1e-9),)) | ||
|
||
@recipe function f(sp::SamplePlot) | ||
nsamples::Int = get(plotattributes, :samples, 1) | ||
nsamples::Int = pop!(plotattributes, :samples, 1) | ||
samples = rand(sp.f, nsamples) | ||
|
||
flat_x = repeat(vcat(sp.x, NaN), nsamples) | ||
flat_f = vcat(samples, fill(NaN, 1, nsamples)) |> vec | ||
st-- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Set default attributes | ||
seriestype --> :line | ||
#seriestype --> :line | ||
linealpha --> 0.2 | ||
markershape --> :circle | ||
markerstrokewidth --> 0.0 | ||
markersize --> 0.5 | ||
markeralpha --> 0.3 | ||
seriescolor --> "red" | ||
label --> "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need/want these defaults? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I really like this default for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the default labels aren't great. Maybe let's just remove the series color? I don't think red is a particularly great choice and we could just let Plots pick one, according to whatever theme is used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, done. anything else before you're willing to hit approve?:) |
||
|
||
return sp.x, samples | ||
return flat_x, flat_f | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just
? I did not know that
label=nothing
is a thing 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, one of the complaints about Plots.jl is that there are plenty of different ways of saying the same thing!
I find
label = nothing
to be a bit more self-explanatory, but feel free to add&commit your suggestion if you feel moderately strongly about it:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't feel strongly about it. The main reason would be to avoid having two different types here but I'm fine with
nothing
as well.