[ENH] numpy
and outer product functionality for distribution methods
#341
Labels
API design
API design & software architecture
enhancement
module:probability&simulation
probability distributions and simulators
Design issue related to adding outer product evaluation mode to distribution methods.
Related to comments of @FelixWick in #327 (comment).
Currently,
BaseDistribution
descendants support up-broadcasting of arguments, but not up-broadcasting of results, if arguments with additional dimensions are given. Mathematically, this is related to taking outer products instead of element-wise products, in scalar or vector casesThis is a natural feature to offer, for instance
tensorflow.probability
functions in this way, andcyclic-boosting
also has the feature.There are a few obstacles for adding this:
pd.DataFrame
numpy.ndarray
-s - where are not a supported input typecyclic-boosting
has an extra argument that controls elementwise vs outer product, which I find cumbersome and somewhat unintuitive.Imo the most elegant way to allow this is as follows:
numpy.ndarray
and coercibles as input to all distribution methods. These must have shape of the distribution or 1, for dimensions present in the distribution. Inputs that are currently valid - up to 2D coercibles for array distributions, and flots for scalar distributions - are not coerced and treated as presently.numpy.ndarray
is passed, dimensions that are not present in the distribution will lead to output upcasting, special case is outer product mode for scalar distributions.Examples:
n = Normal(0, 1)
, passingn.pdf([1, 2, 3, 4, 5])
will lead to evaluation at 5 points, and return anp.ndarray
of shape(5,)
.n = Normal([[0, 1], [2, 3]], 1)
, callingn.pdf([[[1, 2, 3, 4, 5]]])
leads to a returnnp.ndarray
of shape(2, 2, 3)
- upcasting happens along the 3rd dimension of length 5 that the argument introduces.Thoughts, @setoguchi-naoki, @FelixWick, @VascoSch92, @ShreeshaM07 ?
The text was updated successfully, but these errors were encountered: