Support random variables that use `rand`
Most existing Julia samplers that use rand(rng)
For instance
function X(rng)
a = rand(rng)
b = rand(rng)
a + b
end
This should be equivalent to something like
function X2(rng)
a = (1 ~ Uniform(0, 1))(rng)
b = (2 ~ Uniform(0, 1))(rng)
a + b
end
One issue is that this is not a transformation that can be done locally in rand using method dispatch, since a and b need different ids.
Before I was doing this using a counter, resetting the counter at the start of the random variable. The problem is the notion of the "start" of a random variable is somewhat unclear, especially since OmegaCore does not focus so much on the RandVar type.
For example, suppose we have
function X3(rng)
a = rand(rng)
b = rand(rng)
c = rand(rng)
d = rand(rng)
a + b + c + d
end
We could rewrite this as
function helper(rng)
x = rand(rng)
y = rand(rng)
x + y
end
function X4(rng)
helper(rng) + helper(rng)
end
So here helper doesn't reset but X4 does?
We need some way to distinguish between thees things: If I had control over the syntax then I can say X4 should be:
function X4b(rng)
~ helper(rng) + ~ helper(rng)
end
Perhaps the first thing is to figure out the correct syntax when I have control and translate rand into that.