Example #1
0
    def isf(self, q, *args, **kwds):
        """
        Inverse survival function at q of the given RV.

        Parameters
        ----------
        q : array-like
            upper tail probability
        arg1, arg2, arg3,... : array-like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array-like, optional
            location parameter (default=0)
        scale : array-like, optional
            scale parameter (default=1)

        Returns
        -------
        x : array-like
            quantile corresponding to the upper tail probability q.

        """
        (loc, scale) = map(kwds.get, ['loc', 'scale'])
        (args, loc, scale) = self._fix_loc_scale(args, loc, scale)
        (q, loc, scale, shape) = map(arr, (q, loc, scale, args[0]))
        q = np.where(scale > 0, q, 1. - q)
        #
        isgamma = (shape > 0) & (scale != 0)
        isnorm = (shape == 0) & (scale > 0)
        ispe3 = (isgamma | isnorm)
        indom = (q > 0) & (q < 1)
        islarge = (q == 1) & ispe3
        valid = ispe3 & indom
        output = valarray(np.shape(valid), value=self.b)
        #place(output,(1-cond0)*(cond1==cond1), self.badvalue)
        np.place(output, (1 - ispe3) * (indom == indom) + (1 - indom) * (q != 0.0),
                 self.badvalue)
        np.place(output, islarge, self.a)
        if np.any(valid):  #call only if at least 1 entry
            goodargs = argsreduce(valid, *((q,) + args + (scale, loc)))  #PB replace 1-q by q
            (q, shape, scale, loc) = argsreduce(valid, *((q, shape, scale, loc)))
            np.place(output, (valid & isgamma), self._isf(q, shape) * scale + loc)
            np.place(output, (valid & isnorm), -dist._norm_ppf(q))
        if output.ndim == 0:
            return output[()]
        return output
Example #2
0
 def _ppf(self, q, k):
     u = dist._norm_ppf(q)
     return where(k == 0, u, (1. - exp(-k * u)) / k)