Skip to content

Commit 27a60b9

Browse files
committed
inline rand(::Distributions.Uniform)
Note that, apart from being simpler code, Distributions.Uniform also doesn't allow the lower and upper bounds to be exactly equal (but we might like to keep that option open in DynamicPPL, e.g. if the user wants to initialise all values to the same value in linked space).
1 parent 7b72071 commit 27a60b9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/contexts/init.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ to unconstrained space, and then sampling a value uniformly between `lower` and
3838
If unspecified, defaults to `(lower, upper) = (-2, 2)`, which mimics Stan's
3939
default initialisation strategy.
4040
41+
Requires that `lower <= upper`.
42+
4143
# References
4244
4345
[Stan reference manual page on initialization](https://mc-stan.org/docs/reference-manual/execution.html#initialization)
@@ -55,7 +57,7 @@ end
5557
function init(rng::Random.AbstractRNG, ::VarName, dist::Distribution, u::UniformInit)
5658
b = Bijectors.bijector(dist)
5759
sz = Bijectors.output_size(b, size(dist))
58-
y = rand(rng, Uniform(u.lower, u.upper), sz)
60+
y = u.lower + ((u.upper - u.lower) * rand(rng, sz))
5961
b_inv = Bijectors.inverse(b)
6062
x = b_inv(y)
6163
# 0-dim arrays: https://github.com/TuringLang/Bijectors.jl/issues/398

0 commit comments

Comments
 (0)