def dNexpo(means, x): """ The pdf of the distribution of a sum of exponentially distributed random variables. NB Means are allowed to be equal (but the function is slow)!!! """ assert x >= 0.0, "variate must not be negative in dNexpo!" number = len(means) if number == 1: return dexpo(means[0], x) if x == 0.0: if number == 1: return 1.0 / means[0] else: return 0.0 lam = [] for k in range(0, number): assert means[k] > 0.0, "All means must be positive floats in dNexpo!" lam.append(1.0 / means[k]) # ---------------------------------------------------- def _ftilde(z): zprod = complex(1.0) for k in range(0, number): zprod = zprod * complex(lam[k]) / (z + lam[k]) return zprod # ---------------------------------------------------- rpole = -min(lam) sigma = (1.0 - TWOMACHEPS) * rpole pdf = talbot(_ftilde, x, sigma) pdf = kept_within(0.0, pdf) return pdf
def cNexpo(means, x): """ cdf of a distribution of a sum of exponentially distributed random variables. NB Means are allowed to be equal (but the function is slow)!!! """ assert x >= 0.0, "variate must not be negative in cNexpo!" if x == 0.0: return 0.0 number = len(means) if number == 1: return cexpo(means[0], x) lam = [] for k in range(0, number): assert means[k] > 0.0, "All means must be positive floats in cNexpo!" lam.append(1.0 / means[k]) # ---------------------------- def ftilde(z): zprod = complex(1.0) for k in range(0, number): zprod = zprod * complex(lam[k]) / (z + lam[k]) zprod = zprod / z return zprod # ----------------------------- sigma = TWOMACHEPS * min(lam) cdf = talbot(ftilde, x, sigma) cdf = kept_within(0.0, cdf, 1.0) return cdf
def dNexpo(means, x): """ The pdf of the distribution of a sum of exponentially distributed random variables. NB Means are allowed to be equal (but the function is slow)!!! """ assert x >= 0.0, "variate must not be negative in dNexpo!" number = len(means) if number == 1: return dexpo(means[0], x) if x == 0.0: if number == 1: return 1.0/means[0] else: return 0.0 lam = [] for k in range(0, number): assert means[k] > 0.0, "All means must be positive floats in dNexpo!" lam.append(1.0/means[k]) # ---------------------------------------------------- def _ftilde(z): zprod = complex(1.0) for k in range(0, number): zprod = zprod * complex(lam[k]) / (z+lam[k]) return zprod # ---------------------------------------------------- rpole = - min(lam) sigma = (1.0-TWOMACHEPS) * rpole pdf = talbot(_ftilde, x, sigma) pdf = kept_within(0.0, pdf) return pdf
def cNexpo(means, x): """ cdf of a distribution of a sum of exponentially distributed random variables. NB Means are allowed to be equal (but the function is slow)!!! """ assert x >= 0.0, "variate must not be negative in cNexpo!" if x == 0.0: return 0.0 number = len(means) if number == 1: return cexpo(means[0], x) lam = [] for k in range(0, number): assert means[k] > 0.0, "All means must be positive floats in cNexpo!" lam.append(1.0 / means[k]) # ---------------------------- def ftilde(z): zprod = complex(1.0) for k in range(0, number): zprod = zprod * complex(lam[k]) / (z + lam[k]) zprod = zprod / z return zprod #----------------------------- sigma = TWOMACHEPS * min(lam) cdf = talbot(ftilde, x, sigma) cdf = kept_within(0.0, cdf, 1.0) return cdf