lundi 18 mars 2019

Why is this subclass of `scipy.stats.rv_continuous` not generating random variates in the correct range?

I have the following subclass of scipy.stats.rv_continuous:

from scipy.stats import rv_continuous
import math

class Distribution(rv_continuous):
    def _cdf(self, x, a, b, mu):
        return (
            math.erf(x/(math.sqrt(2)*a)) + \
            math.erf((x - mu)/(math.sqrt(2)*b)) \
            ) / 2 + math.erf(mu/(math.sqrt(2)*b)) / 2

distribution = Distribution(a = 0, b = float('inf'))

As far as I can tell, everything is setup correctly (I've checked the math and it is also correct). However, for some reason, it only wants to generate values between 0 and mu, rather than the expected 0 and inf as explicitly specified. For example, here are 50 points generated with distribution.rvs(3, 1.6, 10) (along with the PDF):

enter image description here

and here's an example with distribution.rvs(0.6, 0.4, 4.85):

enter image description here

Why is my distribution 'capped' at mu? Have I setup my rv_continuous subclass wrong?




Aucun commentaire:

Enregistrer un commentaire