def nbpmf_slow(c, p, r): return float( mp_fprod([ mp.gammaprod([c + r], [c + 1, r]), mp_power(p, c), mp_power((1 - p), r) ]))
def premul(self, n, m, mode="TM"): if mode != "TM": raise NotImplementedError("Only TM mode available yet.") if not (n - m) % 2: if m == self.l + 1: pow2 = self.l + 2 pown1 = (n + self.l + 1) / 2 gammatop = [(n - self.l + 1) / 2] gammabtm = [(n + self.l) / 2 + 1] elif m == self.l - 1: pow2 = self.l pown1 = (n + self.l - 1) / 2 gammatop = [(n - self.l + 3) / 2] gammabtm = [(n + self.l) / 2] else: return 0 else: if m == self.l + 1: pow2 = self.l + 3 pown1 = (n + self.l) / 2 gammatop = [(n - self.l) / 2] gammabtm = [(n + self.l + 3) / 2] elif m == self.l - 1: pow2 = self.l + 1 pown1 = (n + self.l) / 2 - 1 gammatop = [(n - self.l) / 2 + 1] gammabtm = [(n + self.l + 1) / 2] else: return 0 return ( 1j ** n * mpmath.sqrt(mpmath.pi) / mpmath.power(2, pow2) \ * (-1) ** pown1 * mpmath.gammaprod(gammatop, gammabtm))
def cs_sca(self, max_it=None): if max_it is None: max_it = MAX_IT pre = 4 * np.pi / self.wave_number res = 0 for n in range(1, max_it): for m in self.degrees: inc = (2 * n + 1) / n / (n + 1) \ * mp.gammaprod([n + np.abs(m)], [n - np.abs(m)])
def var(nu, loc=0, scale=1): """ Variance of the Nakagami distribution. """ _validate_params(nu, loc, scale) with mpmath.extradps(5): nu = mpmath.mpf(nu) scale = mpmath.mpf(scale) gratio = mpmath.gammaprod([nu + 0.5], [nu]) var0 = 1 - gratio**2/nu return scale**2 * var0
def mean(nu, loc=0, scale=1): """ Mean of the Nakagami distribution. """ _validate_params(nu, loc, scale) with mpmath.extradps(5): nu = mpmath.mpf(nu) loc = mpmath.mpf(loc) scale = mpmath.mpf(scale) gratio = mpmath.gammaprod([nu + 0.5], [nu]) mean0 = gratio / mpmath.sqrt(nu) return loc + scale*mean0
def hyper1(As, Bs, N, M): with mpmath.extraprec(mpmath.mp.prec): s = t = 1 for j in range(1, N): t *= fprod(a + j - 1 for a in As) / fprod(b + j - 1 for b in Bs) s += t if M > 0: s2 = 0 g = sum(As) - sum(Bs) for (j, c) in enumerate(gammaprod_series(As, Bs, M)): s2 += c * mpmath.zeta(-(g - j), N) s += s2 * mpmath.gammaprod(Bs, As) return s
def bsc(self, n, m, mode="TM"): g = 0 q = 0 if n < m: return 0 if m not in [self.l + 1, self.l - 1]: return 0 while q <= n / 2: inc = mpmath.power(2, (.5 + n - 2 * q)) \ * mpmath.gammaprod([.5 + n - q], [q + 1]) \ * self.maclaurin(n - 2 * q, self.p, m) g += inc q += 1 return self.premul(n, m, mode=mode) * g
def hyper1_auto(As, Bs, N, M): with mpmath.extraprec(mpmath.mp.prec): s = t = 1 good_ratio_hits = 0 for j in range(1, N): s_old = s t *= fprod(a + j - 1 for a in As) / fprod(b + j - 1 for b in Bs) s += t ratio = (s - s_old) / s if ratio < mpf(10**-18): good_ratio_hits += 1 if good_ratio_hits > 3: break print float(s) if M > 0: s2 = 0 g = sum(As) - sum(Bs) for (j, c) in enumerate(gammaprod_series(As, Bs, M)): s2 += c * mpmath.zeta(-(g - j), N) s += s2 * mpmath.gammaprod(Bs, As) return s
def hyper1_auto(As, Bs, N, M): with mpmath.extraprec(mpmath.mp.prec): s = t = 1 good_ratio_hits = 0 for j in range(1, N): s_old = s t *= fprod(a + j - 1 for a in As) / fprod(b + j - 1 for b in Bs) s += t ratio = (s - s_old) / s if ratio < mpf(10 ** -18): good_ratio_hits += 1 if good_ratio_hits > 3: break print float(s) if M > 0: s2 = 0 g = sum(As) - sum(Bs) for (j, c) in enumerate(gammaprod_series(As, Bs, M)): s2 += c * mpmath.zeta(-(g - j), N) s += s2 * mpmath.gammaprod(Bs, As) return s
def longRange(m, magneticLength): alpha = 2 return ((2 * magneticLength)**(-alpha)) * mpmath.gammaprod( (m + 1 - (alpha / 2), ), (m + 1, ))
def F(self, n, u): return ( (-1) ** ((n - u) / 2) \ * mpmath.gammaprod([], [(n - u) / 2 + 1, (n + u) / 2 + 1]))