Open marvinpfoertner opened 4 years ago
Any thoughts? @JonathanWenger @pnkraemer @nathanaelbosch
Thanks for the initiative, I think that something like this is a good idea (even though it is not needed as of now, at least not in the parts I am working with) .
I am not sure how self-explanatory rv.exp
would be, but that is, of course, just a technicality...
Offering rv.sum()
would follow the numpy API, so I figured rv.exp()
is maybe a good analogy. We could of course also offer the function probnum.exp(rv)
, but it should call rv.exp()
internally or otherwise we would have a gigantic conditional switching between different random variables. @pnkraemer Do you agree with this?
Fair enough, at least internal the implementation should be in the random variable (but I am still not sure about a "public" rv.exp()). No need to discuss this in all detail now, though (IMO).
In my opinion any function in NumPy we can support for random variables should share the exact same usage and interface. This would mean that both ~some_rv.exp()
~ some_rv.sum()
and ~pn.exp(some_rv)
~ pn.sum(some_rv)
are implemented.
But exp()
is not an ndarray
method, just a numpy function (https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html). Wouldnt the most numpy-similar solution then be to not have it as a method but just as a function? (I understand that the actual implementation would make sense as method, but potentially as a private one?)
Good point. Yes i would be in favor of the implementation being in, e.g. Normal._exp()
. For some_rv.sum()
, some_rv.max()
the above still goes.
We should implement numpy-style functions on random variables. For instance, if
rv1
is aNormal
, thenrv2 = probnum.exp(rv1)
should be aLogNormal
. These functions could reside inprobnum.random_variables._functions
and could be implemented in methods of the random variable subclasses, e.g.Normal.exp
. Furthermore, we should provide generic fallback implementations of these methods which at least allow sampling from the random variable, e.g. assample = lambda: np.exp(norm_rv.sample())
.