-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Currently, we support a variable number of random variables but only when the random variables are elements of an array that's always at least partially sampled. That is each "symbol" in the model is assumed to be visited every time you run the model. This is enough most of the time and indeed one can group together all optional parameters in a vector and use this method, however it fails to address models of the form:
@model demo(x) = begin
a ~ Uniform()
if a > 0.5
b ~ Normal(a)
x ~ Normal(b)
else
c ~ Uniform()
x ~ Normal(c)
end
endNote that b and c will not always be "visited". The current VarInfo setup will therefore fail in those cases. One way to address this is to have an UntypedVarInfo stored inside the TypedVarInfo for previously unseen variable symbols. Then during the sampling, we can check at every iteration if there are new symbols sampled. If so, we create a new spl::Sampler whose spl.state.vi is an instance of the expanded TypedVarInfo. If we do this right, I think we will not be paying any penalty in the case where all the symbols are always visited, and we may need to pay only a small dynamic dispatch price per new symbol seen, keeping the remaining of the code type stable.