Esempio n. 1
0
def fix_Psi(fixture_path):
    """Call Psi for a range of possible inputs and save result as fixture."""
    function_name = 'Psi'
    output_file = fixture_path + function_name + '.npz'

    z_range = np.concatenate(
        [-np.logspace(2, -5, 4), [0],
         np.logspace(-5, 2, 4)])
    a, b = np.meshgrid(z_range, z_range)
    zs = a.flatten() + complex(0, 1) * b.flatten()
    xs = np.linspace(-10, 10, 8)

    zs, xs = np.meshgrid(zs, xs)
    zs = zs.flatten()
    xs = xs.flatten()

    pcfu_outputs = []
    for z, x in zip(zs, xs):
        result = mpmath.pcfu(z, -x)
        pcfu_outputs.append(complex(result.real, result.imag))

    outputs = []
    for z, x in zip(zs, xs):
        outputs.append(Psi(z, x))
    np.savez(output_file, zs=zs, xs=xs, pcfus=pcfu_outputs, outputs=outputs)
Esempio n. 2
0
def normal_cdf_moment_ratio(n, x):
    mpmath.mp.dps = 500
    xmpf = x._to_mpmath(500)
    nmpf = n._to_mpmath(500)
    if x < 0:
        return Float(mpmath.power(2, -0.5 - nmpf / 2) * mpmath.hyperu(nmpf / 2 + 0.5, 0.5, xmpf * xmpf / 2))
    return Float(mpmath.exp(xmpf * xmpf / 4) * mpmath.pcfu(0.5 + nmpf, -xmpf))
Esempio n. 3
0
def Phi_mpmath(z, x):
    """
    Calculates Phi(a,x) = exp(x**2/4)*U(a,x), where U(a,x) is the
    parabolic cylinder function. Implementation uses the mpmath
    functions. This is slower than the Fortran implementation `Phi`
    and not used in this package but added for completeness.
    """

    value = np.exp(0.25 * x**2) * complex(mpmath.pcfu(z, -x))
    return value
def Phi_mpmath(z, x):
    """
    Calculates Phi(a,x) = exp(x**2/4)*U(a,x), where U(a,x) is the
    parabolic cylinder function. Implementation uses the mpmath
    functions. This is slower than the Fortran implementation `Phi`
    and not used in this package but added for completeness.
    """

    value = np.exp(0.25*x**2) * complex(mpmath.pcfu(z, -x))
    return value
Esempio n. 5
0
def Phi1_mpmath_pcfu(z, x):
    '''mpmath implementation has revered sign in x'''
    try:
        value = np.exp(0.25 * x**2) * complex(mpmath.pcfu(z, -x))
        # value_mpc = U_Kummer_fortran(z,x)
        # value_mpc = U_Kummer_mpmath(z,x)
        # value = complex(value_mpc.real,value_mpc.imag)
        return value

    except mpmath.libmp.libhyper.NoConvergence:
        return np.NaN
Esempio n. 6
0
def Psi(z, x):
    """
    Calcs Psi(z,x)=exp(x**2/4)*U(z,x), with U(z,x) the parabolic cylinder func.
    """
    return np.exp(0.25 * x**2) * complex(mpmath.pcfu(z, -x))