Consider making RandomVariable
multivariate size
under broadcasting more consistent
#412
Replies: 3 comments 4 replies
-
I think it's fair to say that My vote goes to consistency and have |
Beta Was this translation helpful? Give feedback.
-
This might provide some clues as to where scipy/ numpy might be going: numpy/numpy#17669 It seems there is an interest in extending the behavior over there |
Beta Was this translation helpful? Give feedback.
-
Don't forget, as a step toward simplification without deviating from NumPy/SciPy, we can always implement an alternative keyword option—call it |
Beta Was this translation helpful? Give feedback.
-
Aesara's multivariate
RandomVariable
s allow parameter broadcasting, while the NumPy equivalents do not. Use of thesize
parameter in this situation requires a choice in the way the parameter is interpreted. The current choice doesn't match the case of univariate broadcasting undersize
as well as it could, which can lead to confusion—or at least a less succinct rule for the resulting shape.To illustrate, the following fails in NumPy
while the equivalent expression is supported in Aesara:
Aesara interprets
size=(3,)
to mean "sample the distribution(s) with parametersnp.zeros((1, 2))
andnp.ones((1, 2, 2))
three times"; however, this clashes with NumPy's behavior for univariate distributions, which expects thesize
parameter to reflect both the additional dimensions (e.g. the3
we want added) and the extra "broadcasted" dimensions implied by the parameters.For instance, if we want three samples of two normal distributions with different mean parameters in NumPy, we use something like the following:
If we set
size=(3,)
it would fail with a shape mismatch.The same is true in Aesara for the univariate case, so, to make Aesara's additional multivariate broadcasting functionality more consistent with NumPy's univariate broadcasting, we could require that
size
be(3, 1)
in ourmultivariate_normal
example above. In other words, we can requiresize
to include the extra broadcasted dimension—but not the "support" dimensions (i.e.(2,)
and(2, 2)
for the mean and covariance, respectively).We could make such a change without breaking from NumPy's design, because this particular case isn't yet supported by NumPy.
This change would—however—make the use of multivariate distributions under broadcasting a little more cumbersome, because it would require one to unnecessarily specify an extra dimension. The alternative is to completely break with NumPy and change
size
to means something altogether different (e.g. the shape to which you want to duplicate the underlying broadcasted distribution, or append duplicates of the broadcasted distribution, etc.).NB: Just to be clear, it's the
multivariate_normal
operation that's being broadcasted across the parameters, and not that the parameters are necessarily broadcasted—although they will be when they don't already match across dimensions.Beta Was this translation helpful? Give feedback.
All reactions