コード例 #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
コード例 #2
0
ファイル: stats.py プロジェクト: gorlins/PyMVPA
    def ppf7(self,q,*args,**kwds):
        """
        Percent point function (inverse of cdf) at q of the given RV

        Parameters
        ----------
        q : array-like
            lower 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)

        Returns
        -------
        k : array-like
            quantile corresponding to the lower tail probability, q.

        """
        loc = kwds.get('loc')
        args, loc = self._rv_discrete__fix_loc(args, loc)
        q,loc  = map(arr,(q,loc))
        args = tuple(map(arr,args))
        cond0 = self._argcheck(*args) & (loc == loc)
        cond1 = (q > 0) & (q < 1)
        cond2 = (q==1) & cond0
        cond = cond0 & cond1
        output = valarray(shape(cond),value=self.badvalue,typecode='d')
        #output type 'd' to handle nin and inf
        place(output,(q==0)*(cond==cond), self.a-1)
        place(output,cond2,self.b)
        if any(cond):
            goodargs = argsreduce(cond, *((q,)+args+(loc,)))
            loc, goodargs = goodargs[-1], goodargs[:-1]
            place(output,cond,self._ppf(*goodargs) + loc)

        if output.ndim == 0:
            return output[()]
        return output