Open ali-ramadhan opened 4 years ago
With this patch
diff --git a/src/inference/elliptical_slice.jl b/src/inference/elliptical_slice.jl
index 3dc2b72..1c330ad 100644
--- a/src/inference/elliptical_slice.jl
+++ b/src/inference/elliptical_slice.jl
@@ -16,7 +16,11 @@ function elliptical_slice(
argdiffs = map((_) -> NoChange(), args)
# sample nu
- nu = mvnormal(zeros(length(mu)), cov)
+ if length(mu) == 1
+ nu = normal(mu, cov)
+ else
+ nu = mvnormal(zeros(length(mu)), cov)
+ end
# sample u
u = uniform(0, 1)
this modified minimal working example work
using LinearAlgebra, Gen
@gen function foo()
x ~ normal(0, 1)
y ~ gamma(1, 1)
end
trace, _ = generate(foo, (), choicemap((:y, 0.5)))
elliptical_slice(trace, :x, 0.0, 0.1)
@ali-ramadhan Thanks for proposing this, but I don't think that elliptical slice sampling is particularly useful for a univariate normal draw. Using mh(trace, select(:x))
should be just as effective in this case. Perhaps we can change the docstring to clarify this.
Thanks for the advice. I'll try changing my model to sample from a mvnormal
.
But surely elliptical_slice
shouldn't error with a conversion error when drawing from a univariate normal?
If it's not meant to be used in such cases then maybe an ArgumentError
should be thrown if length(mu) == 1
(and mentioned in the docstring)?
Yes, we should throw a more informative error, thanks!
It looks like docstring does mention its for use with multivariate normal prior; we can add (mvnormal
) to make this more explicit.
Please let me know if I'm misusing Gen but the
elliptical_slice
docstring and elliptical slice smoke test suggest thatmu
should be a vector andcov
should be a matrix but it errors when applied to a scalar parameter wheremu
is a 1-element array andcov
is a 1x1 array.I suspect this is because https://github.com/probcomp/Gen/blob/a24877a703b9944e1a115a67270716b35fe7e8b7/src/inference/elliptical_slice.jl#L19 returns a 1-element array instead of a scalar as expected. Maybe it should be changed to something like
and accept scalar μ, Σ or could have
normal
also work for multivariate normal but this might be a big breaking change.Minimal working example:
produces