def ibeta(prob, a, b, x1=0.0, x2=1.0, betaab=False): """ The beta distribution: f = x**(a-1) * (1-x)**(b-1) / beta(a, b) a, b >= 0; 0 <= x <= 1 F is the integral = the incomplete beta or the incomplete beta ratio function depending on how the incomplete beta function is defined. x2 >= x1 !!!! NB It is possible to provide the value of the complete beta function beta(a, b) as a pre-computed input (may be computed using numlib.specfunc.beta) instead of the default "False", a feature that will make ibeta 30 % faster! """ # Everything will be checked in cbeta if a == 1.0 and b == 1.0: return iunifab(prob, x1, x2) # ----------------------------------------------------------- def _fi(x): return cbeta(a, b, x1, x2, x, betaab) - prob # ----------------------------------------------------------- x = zbrent(_fi, x1, x2, 'ibeta', tolf=SQRTMACHEPS) x = kept_within(x1, x, x2) return x
def _dstable_sym_int(alpha, x, tolromb, mxsplromb): """ The integral formulation of the standard pdf (cf. for instance Matsui, M., and Takemura, A., "Some Improvements in Numerical Evaluation of Symmetric Stable Density and its Derivatives", University of Tokyo Report CIRJE-F-292, Aug. 2004. """ # Auxiliary functions for calculating the breakpoint # (the integration interval is broken up into two portions, # cf. Matusi & Takemura) and integral: am1 = alpha - 1.0 aoam1 = alpha / am1 # ------------- def _gm1(phi2): try: g = (x*cos(phi2)/sin(alpha*phi2))**(aoam1) * \ (cos(am1*phi2)/cos(phi2)) except ZeroDivisionError: g = 0.0 except OverflowError: g = 0.0 return g - 1.0 # -------------- def _func(phi1): try: g = (x*cos(phi1)/sin(alpha*phi1))**(aoam1) * \ (cos(am1*phi1)/cos(phi1)) except ZeroDivisionError: g = 0.0 except OverflowError: g = 0.0 y = exp(-g) if y == 0.0: z = g - log(g) y = exp(-z) else: y = g * y return y # -------------- # Integrate! # First find the break point: point2 = zbrent(_gm1, MACHEPS, PIHALF, 'dstable_sym/_dstable_sym_int') if point2 == ERRCODE: point2 = 0.5 * PIHALF # Then perform Romberg quadrature for the # two panels separated by the break point: pdf = qromberg(_func, 0.0, point2, 'dstable_sym/_dstable_sym_int', \ tolromb, mxsplromb) pdf += qromberg(_func, point2, PIHALF, 'dstable_sym/_dstable_sym_int', \ tolromb, mxsplromb) pdf *= alpha / (PI * abs(am1) * x) # Return: return pdf
def _dstable_sym_int(alpha, x, tolromb, mxsplromb): """ The integral formulation of the standard pdf (cf. for instance Matsui, M., and Takemura, A., "Some Improvements in Numerical Evaluation of Symmetric Stable Density and its Derivatives", University of Tokyo Report CIRJE-F-292, Aug. 2004. """ # Auxiliary functions for calculating the breakpoint # (the integration interval is broken up into two portions, # cf. Matusi & Takemura) and integral: am1 = alpha - 1.0 aoam1 = alpha/am1 # ------------- def _gm1(phi2): try: g = (x*cos(phi2)/sin(alpha*phi2))**(aoam1) * \ (cos(am1*phi2)/cos(phi2)) except ZeroDivisionError: g = 0.0 except OverflowError: g = 0.0 return g - 1.0 # -------------- def _func(phi1): try: g = (x*cos(phi1)/sin(alpha*phi1))**(aoam1) * \ (cos(am1*phi1)/cos(phi1)) except ZeroDivisionError: g = 0.0 except OverflowError: g = 0.0 y = exp(-g) if y == 0.0: z = g - log(g) y = exp(-z) else: y = g*y return y # -------------- # Integrate! # First find the break point: point2 = zbrent(_gm1, MACHEPS, PIHALF, 'dstable_sym/_dstable_sym_int') if point2 == ERRCODE: point2 = 0.5*PIHALF # Then perform Romberg quadrature for the # two panels separated by the break point: pdf = qromberg(_func, 0.0, point2, 'dstable_sym/_dstable_sym_int', \ tolromb, mxsplromb) pdf += qromberg(_func, point2, PIHALF, 'dstable_sym/_dstable_sym_int', \ tolromb, mxsplromb) pdf *= alpha/(PI*abs(am1)*x) # Return: return pdf