Adding Methods To Scipy.stats.rv_continuous, Problems With Rv_frozen
Solution 1:
The immediate issue you're seeing is that rv2.cntsCumul(xx, 3)
creates a so-called frozen distribution, which has shapes and loc/scale fixed --- this way, e.g. norm(loc=0, scale=2).pdf(x)
is equivalent to norm.pdf(x, loc=0, scale=2)
etc. In the source code, see rv_continuous.__call__
etc.
Now, a frozen distribution (an rv_frozen
instance) creates a fresh instance of the underlying rv_continuous
subclass (which is stored as a self.dist
attribute of an rv_frozen
instance), and that one does not know about your monkey-patching.
Note also that what you are doing does not account for the shape parameters: e.g. gamma
has shape a
, so that the signature is scipy.stats.gamma.pdf(x, a, loc, scale)
. loc and scale have default values, but shapes do not.
On a side note, like I said in the comments, what you're doing is, to put it mildly, somewhat non-standard.
And certainly very error-prone.
If you need several distributions, just subclass their _gen
classes or monkey-patch the instances if you really must.
Post a Comment for "Adding Methods To Scipy.stats.rv_continuous, Problems With Rv_frozen"