Dave
Dave

Reputation: 8091

Requirements for implementing _rvs in subclass of scipy.stats.rv_continuous?

I'd like to implement a particular distribution in terms of the scipy.stats.rv_continuous class, and I'd like to provide my own implementation of _rvs but I don't understand what arguments come into it (it's just *args in the function declaration).

In particular, I don't see how the size parameter feeds into the call to _rvs via the rv_generic.rvs function call (line 665 in online source).

My distribution does not have any parameters (other than loc and scale), so if _rvs just needs to return 1 random value, I could do that with an empty argument list, but it seems like it needs to return a (flat) array of random values, how do I obtain the number of elements to return?

Upvotes: 0

Views: 403

Answers (1)

user197030
user197030

Reputation:

The scipy.stats.rv_continuous class is a subclass of rv_generic. The latter defines a rv_generic.rvs function that calls self._rvs after having set its self._size variable to either None, or a specific number. This is done by reading the keyword arguments stored in **kwds and checking for a size parameter.

Usually, when self._size is None, distributions return a scalar and otherwise return an array of length self._size.

Upvotes: 1

Related Questions