subclassing scipy.stats.rv_continuous

137 views Asked by At

I've spent considerable effort and searches trying to subclass scipy.stats.rv_continuous to generate a new parameterization of the Weibull probability distribution (weibull_max), but do not understand how this should be done. I'm trying to set up the distribution to be able to use the pdf, cdf, random variates, and fit methods.

I am able to generate the desired pdf using the following independent function:

def weibull3P_pdf(x, shape, thres=0, loc=0, scale=1):
    return np.flip(scistats.weibull_max
                   .pdf(-x - thres, shape,
                        loc=loc, scale=scale))

One would guess the following should work then:

class weibull3P_gen(scistats.rv_continuous):

    def _argcheck(self, c, k):
        return (c > 0) & (k < 0)

    def _get_support(self, c, k):
        return k, -k

    def _pdf(self, x, c, k):
        # Adjusted accordingly from weibull_max._pdf
        return c * pow(-x - k, c - 1) * np.exp(-pow(-x - k, c))


weibull3P = weibull3P_gen(name="weibull3P")

but the pdf method doesn't produce the same results. Any pointers welcome.

0

There are 0 answers