Exemplo n.º 1
0
def _gwr_no_memo(fn: Callable[[float], Any], time: float, M: int = 32, precin: int = 0) -> float:
    """
    GWR alorithm without memoization. This is a near 1:1 translation from
    Mathematica.
    """
    tau = mp.log(2.0) / mp.mpf(time)

    fni: List[float] = [0.0] * M
    for i, n in enumerate(fni):
        if i == 0:
            continue
        fni[i] = fn(n * tau)

    G0: List[float] = [0.0] * M
    Gp: List[float] = [0.0] * M

    M1 = M
    for n in range(1, M + 1):
        try:
            n_fac = mp.fac(n - 1)
            G0[n - 1] = tau * mp.fac(2 * n) / (n * n_fac * n_fac)

            s = 0.0
            for i in range(n + 1):
                s += mp.binomial(n, i) * (-1) ** i * fni[n + i]

            G0[n - 1] *= s

        except:
            M1 = n - 1
            break

    best = G0[M1 - 1]
    Gm: List[float] = [0.0] * M1

    broken = False
    for k in range(M1 - 1):
        for n in range(M1 - 1 - k)[::-1]:
            try:
                expr = G0[n + 1] - G0[n]
            except:
                expr = 0.0
                broken = True
                break

            expr = Gm[n + 1] + (k + 1) / expr
            Gp[n] = expr
            if k % 2 == 1 and n == M1 - 2 - k:
                best = expr

        if broken:
            break

        for n in range(M1 - k):
            Gm[n] = G0[n]
            G0[n] = Gp[n]

    return best
Exemplo n.º 2
0
def radial_indefinite(a, n, m):
    # Evaluates the radial indefinite integral at a for n, m
    m = abs(m)

    # Checks if it is a valid point to evaluate at, or if a == 0
    if (n - m) % 2 > 0 or m > n or a == 0:
        return 0

    # Due to some weird issues with mpmath, if simultaneously n and m
    # are zero, the value of hyp3f2 is wrong.  Good news is that both
    # n and m are zero, then the solution is trivial.

    hyp = 1
    if m != 0 or n != 0:
        hyp = mp.hyp3f2(-1 - n / 2, -m / 2 - n / 2, m / 2 - n / 2, -n, -n / 2,
                        a**(-2))

    binom = mp.binomial(n, 1 / 2 * (-m + n))

    return float(a**(2 + n) / (2 + n) * binom * hyp)
Exemplo n.º 3
0
def binomial(n, i):
    return int(mp.binomial(n, i))
Exemplo n.º 4
0
def binomial(n: int, i: int, precin: int) -> float:
    return mp.binomial(n, i)
Exemplo n.º 5
0
def binompdf(n, p, k):
    return mp.binomial(n, k) * p**k * (1 - p)**(n - k)