예제 #1
0
    def min_moments(param):
        v = param[0]
        sigma = param[1]

        k = v**2 / (2 * sigma**2)
        a = np.sqrt(np.pi / 2)

        moments = np.zeros(6, dtype=float)

        moments[0] = sigma * a * eval_laguerre(1 / 2, -k)
        moments[1] = 2 * sigma**2 + v**2
        moments[2] = 3 * (sigma**3) * a * eval_laguerre(3 / 2, -k)
        moments[3] = 8 * (sigma**4) + 8 * (sigma**2) * (v**2) + (v**4)
        moments[4] = 15 * (sigma**5) * a * eval_laguerre(5 / 2, -k)
        moments[5] = 48 * (sigma**6) + 72 * (sigma**4) * (v**2) + 18 * (
            sigma**2) * (v**4) + (v**6)

        sample_moments = np.array(
            [raw_moment(data, moment=i + 1) for i in range(6)])

        weights = [6 - i for i in range(6)]
        moments = weights * moments
        sample_moments = weights * sample_moments

        cost = (np.sum(sample_moments) - np.sum(moments))**2
        return cost
예제 #2
0
 def evaluate_basis(self, x, i=0, output_array=None):
     x = np.atleast_1d(x)
     if output_array is None:
         output_array = np.zeros(x.shape)
     output_array[:] = eval_laguerre(i, x) - eval_laguerre(i+1, x)
     output_array *= np.exp(-x/2)
     return output_array
예제 #3
0
def test_laguerre():
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_laguerre(order, x)
        valueCpp = NumCpp.laguerre_Scaler1(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(valueCpp, DECIMALS_ROUND):
            allTrue = False

    assert allTrue

    allTrue = True
    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [2, ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_laguerre(order, x)
        valueCpp = NumCpp.laguerre_Array1(order, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    assert allTrue

    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(0, 10, [1, ]).item()
        x = np.random.rand(1).item()
        valuePy = sp.eval_genlaguerre(degree, order, x)
        valueCpp = NumCpp.laguerre_Scaler2(order, degree, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(valueCpp, DECIMALS_ROUND):
            allTrue = False

    assert allTrue

    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(0, 10, [1, ]).item()
        shapeInput = np.random.randint(10, 100, [2, ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_genlaguerre(degree, order, x)
        valueCpp = NumCpp.laguerre_Array2(order, degree, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    assert allTrue
예제 #4
0
def test_laguerre():
    if NumCpp.NO_USE_BOOST and not NumCpp.STL_SPECIAL_FUNCTIONS:
        return

    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_laguerre(order, x)
        valueCpp = NumCpp.laguerre_Scaler1(order, x)
        assert np.round(valuePy,
                        DECIMALS_ROUND) == np.round(valueCpp, DECIMALS_ROUND)

    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_laguerre(order, x)
        valueCpp = NumCpp.laguerre_Array1(order, cArray)
        assert np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND))

    for order in range(ORDER_MAX):
        degree = np.random.randint(0, 10, [
            1,
        ]).item()
        x = np.random.rand(1).item()
        valuePy = sp.eval_genlaguerre(degree, order, x)
        valueCpp = NumCpp.laguerre_Scaler2(order, degree, x)
        assert np.round(valuePy,
                        DECIMALS_ROUND) == np.round(valueCpp, DECIMALS_ROUND)

    for order in range(ORDER_MAX):
        degree = np.random.randint(0, 10, [
            1,
        ]).item()
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_genlaguerre(degree, order, x)
        valueCpp = NumCpp.laguerre_Array2(order, degree, cArray)
        assert np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND))
예제 #5
0
    def omega_ij(self,ni,nj):
        ki, li, mi = self.basis_numbers(ni)
        kj, lj, mj = self.basis_numbers(nj)
        vi = self.nu(ni)
        vj = self.nu(nj)

        z_int = lambda z: np.exp(-1*z)*sp.eval_laguerre(ki,z)*sp.eval_laguerre(kj,z)/z**2
        t_int = lambda t: 1/np.sin(t)**3*(-1*vi*(vi*np.cos(t)**2+vi+1)*sp.lpmv(mi,vi,np.cos(t))+vi*(vi+mi)*np.cos(t)*sp.lpmv(mi,vi-1,np.cos(t))+vi*(vi-mi+1)*np.cos(t)*sp.lpmv(mi,vi+1,np.cos(t)))*(-1*vj*(vj*np.cos(t)**2+vj+1)*sp.lpmv(mj,vj,np.cos(t))+vj*(vj+mj)*np.cos(t)*sp.lpmv(mj,vj-1,np.cos(t))+vj*(vj-mj+1)*np.cos(t)*sp.lpmv(mj,vj+1,np.cos(t)))
        p_int = lambda p: self.Az(vi,mi,p)*self.Az(vj,mj,p)

        Iz = scipy.integrate.quad(z_int, 0., self.max_z_int)
        It = scipy.integrate.quad(t_int, 0., self.cap_lim)
        Ip = scipy.integrate.quad(p_int, 0., 2*np.pi)
        O = Iz[0]*It[0]*Ip[0]
        return O
예제 #6
0
def ham_parity(dim, params):
    a, x = params
    H = np.zeros((dim,dim))
    for i in range(dim):
        H[i,i] += i
        H[i,i] -= a*np.exp(-0.5*x**2)*special.eval_laguerre(int(0.25*x**2),x**2)*np.cos(np.pi*i)
    return H
예제 #7
0
    def psi_ij(self, ni, nj):
        ki, li, mi = self.basis_numbers(ni)
        kj, lj, mj = self.basis_numbers(nj)
        vi = self.nu(ni)
        vj = self.nu(nj)

        z_int = lambda z: np.exp(-1*z)*sp.eval_laguerre(ki,z)*sp.eval_laguerre(kj,z)*z**2
        t_int = lambda t: sp.lpmv(mi,vi,np.cos(t))*sp.lpmv(mj,vj,np.cos(t))*np.sin(t)
        p_int = lambda p: self.Az(vi,mi,p)*self.Az(vj,mj,p)

        Iz = scipy.integrate.quad(z_int, 0., self.max_z_int)
        It = scipy.integrate.quad(t_int, 0., self.cap_lim)
        Ip = scipy.integrate.quad(p_int, 0., 2*np.pi)

        P = Iz[0]*It[0]*Ip[0]
        return P
예제 #8
0
    def basis(self, gdlat, gdlon, gdalt):
        """
        Calculates a matrix of the basis functions evaluated at all input points

        Parameters:
            R: [ndarray(3,npoints)]
                array of input coordinates
                R = [[z coordinates (m)],[theta coordinates (rad)],[phi coordinates (rad)]]
                if input points are expressed as a list of r,t,p points, eg. points = [[r1,t1,p1],[r2,t2,p2],...], R = np.array(points).T
        Returns:
            A: [ndarray(npoints,nbasis)]
                array of basis functions evaluated at all input points
        Notes:
            - Something clever could probably be done to not recalculate the full expression when incrimenting n does not result in a change in k, or similar.
                All the evaluations of special functions here make it one of the slowest parts of the code.
        """

        z, theta, phi = self.transform_coord(gdlat.flatten(), gdlon.flatten(), gdalt.flatten())

        A = []
        for n in range(self.nbasis):
            k, l, m = self.basis_numbers(n)
            v = self.nu(n)
            A.append(np.exp(-0.5*z)*sp.eval_laguerre(k,z)*self.Az(v,m,phi)*sp.lpmv(m,v,np.cos(theta)))
        nax = list(np.arange(gdlat.ndim)+1)
        nax.append(0)
        A0 = np.transpose(np.array(A).reshape((-1,)+gdlat.shape), axes=nax)
        return A0
예제 #9
0
    def evaluate_basis_derivative(self, x=None, i=0, k=0, output_array=None):
        if x is None:
            x = self.mesh(False, False)
        x = np.atleast_1d(x)
        v = eval_laguerre(i, x, out=output_array)
        X = x[:, np.newaxis]
        if k == 1:
            D = np.zeros((self.N, self.N))
            D[:-1, :] = lag.lagder(np.eye(self.N), 1)
            V = np.dot(v, D)
            V -= 0.5 * v
            V *= np.exp(-X / 2)
            v[:] = V

        elif k == 2:
            D = np.zeros((self.N, self.N))
            D[:-2, :] = lag.lagder(np.eye(self.N), 2)
            D[:-1, :] -= lag.lagder(np.eye(self.N), 1)
            V = np.dot(v, D)
            V += 0.25 * v
            V *= np.exp(-X / 2)
            v[:] = V

        elif k == 0:
            v *= np.exp(-X / 2)

        else:
            raise NotImplementedError

        return v
예제 #10
0
    def tau_i(self, n, reg_func):
        k, l, m = self.basis_numbers(n)
        v = self.nu(n)

        z_int = lambda z: np.exp(-0.5*z)*sp.eval_laguerre(k,z)*reg_func(z)*z**2
        t_int = lambda t: sp.lpmv(m,v,np.cos(t))*np.sin(t)
        p_int = lambda p: self.Az(v,m,p)

        Iz = scipy.integrate.quad(z_int, 0., self.max_z_int)
        It = scipy.integrate.quad(t_int, 0., self.cap_lim)
        Ip = scipy.integrate.quad(p_int, 0., 2*np.pi)
        T = Iz[0]*It[0]*Ip[0]
        return T
예제 #11
0
        def min_first_two_moments(param):
            v = param[0]
            sigma = param[1]

            k = v**2 / (2 * sigma**2)
            a = np.sqrt(np.pi / 2)

            moments = np.zeros(2, dtype=float)
            moments[0] = sigma * a * eval_laguerre(1 / 2, -k)
            moments[1] = 2 * sigma**2 + v**2

            sample_moments = [raw_moment(data, moment=i + 1) for i in range(2)]
            cost = (np.sum(moments) - np.sum(sample_moments))**2
            return cost
예제 #12
0
def sphprod_gauss(n):
    '''
    Spherical product Gauss rule:
    
    A rule of order 2*n-1 making use of the separation of variables in
    polar coordinates. If n is even, it uses n**2 points, lying on n/2
    regular 2n-gons; if n is odd, it uses n**2 - n + 1 points, with
    n*(n-1) of them lying on (n-1)/2 regular 2n-gons and one lying at
    the origin. 
    '''
    theta = np.linspace(-(1 - 1 / (2 * n)) * pi, (1 - 1 / (2 * n)) * pi, 2 * n)
    theta_weights = np.full(2 * n, pi / n)

    if n % 2 == 1:
        rsquared = ray.gauss_genlaguerre(n // 2, 1)[0]
        r = sqrt(rsquared)
        even_orders = np.arange(0, (n + 1) // 2)
        rsquared = np.concatenate((np.zeros(1), rsquared))
        rsquared = rsquared[:, np.newaxis]
        evens = special.eval_laguerre(even_orders, rsquared)**2
        evens = np.sum(evens, axis=1)
        odd_orders = np.arange(0, (n - 1) // 2)
        odds = special.eval_genlaguerre(odd_orders, 1, rsquared)**2
        odds = np.sum(rsquared / (odd_orders + 1) * odds, axis=1)
        r_weights = 1 / (evens + odds)
        x_nodes = np.tile(r, 2 * n) * np.repeat(cos(theta), n // 2)
        x_nodes = np.concatenate((np.zeros(1), x_nodes))
        y_nodes = np.tile(r, 2 * n) * np.repeat(sin(theta), n // 2)
        y_nodes = np.concatenate((np.zeros(1), y_nodes))
        weights = np.tile(r_weights[1:], 2 * n) * np.repeat(
            theta_weights, n // 2)
        weights = np.concatenate((pi * r_weights[0:1], weights))
    else:
        rsquared, rsquared_weights = ray.gauss_laguerre(n // 2)
        r = sqrt(rsquared)
        r_weights = rsquared_weights / 2
        x_nodes = np.tile(r, 2 * n) * np.repeat(cos(theta), n // 2)
        y_nodes = np.tile(r, 2 * n) * np.repeat(sin(theta), n // 2)
        weights = np.tile(r_weights, 2 * n) * np.repeat(theta_weights, n // 2)

    return (x_nodes, y_nodes), weights
예제 #13
0
    def grad_basis(self, gdlat, gdlon, gdalt):
        """
        Calculates a matrix of the gradient of basis functions evaluated at all input points

        Parameters:
            R: [ndarray(3,npoints)]
                array of input coordinates
                R = [[z coordinates (m)],[theta coordinates (rad)],[phi coordinates (rad)]]
                if input points are expressed as a list of r,t,p points, eg. points = [[r1,t1,p1],[r2,t2,p2],...], R = np.array(points).T
        Returns:
            A: [ndarray(npoints,nbasis,3)]
                array of gradient of basis functions evaluated at all input points
        Notes:
            - Something clever could probably be done to not recalculate the full expression when incrimenting n does not result in a change in k, or similar.
                All the evaluations of special functions here make it one of the slowest parts of the code.
        """

        z, theta, phi = self.transform_coord(gdlat, gdlon, gdalt)

        Ag = []
        x = np.cos(theta)
        y = np.sin(theta)
        e = np.exp(-0.5*z)
        for n in range(self.nbasis):
            k, l, m = self.basis_numbers(n)
            v = self.nu(n)
            L0 = sp.eval_laguerre(k,z)
            L1 = sp.eval_genlaguerre(k-1,1,z)
            Pmv = sp.lpmv(m,v,x)
            Pmv1 = sp.lpmv(m,v+1,x)
            A = self.Az(v,m,phi)
            zhat = -0.5*e*(L0+2*L1)*Pmv*A*100./RE
            that = e*L0*(-(v+1)*x*Pmv+(v-m+1)*Pmv1)*A/(y*(z/100.+1)*RE)
            phat = e*L0*Pmv*self.dAz(v,m,phi)/(y*(z/100.+1)*RE)
            Ag.append([zhat,that,phat])
        # print np.shape(np.array(Ag).T)
        return np.array(Ag).T
예제 #14
0
def eval_laguerre_dd(n, x):
    return eval_laguerre(n.astype('d'), x)
예제 #15
0
def eval_laguerre_ld(n, x):
    return eval_laguerre(n.astype('l'), x)
예제 #16
0
 def mesanalag(x, y):
     return spec.eval_laguerre(p1, x + 200) * spec.eval_laguerre(
         p2, y + 200)
예제 #17
0
 def lag(x):
     return spec.eval_laguerre(p, x + 200)
예제 #18
0
파일: spectrum.py 프로젝트: JonCYeh/GKP_DD
def H_approx_Par(phi):
    H = -np.exp(-phi**2 / 2) * sum(
        eval_laguerre(n, phi**2) * qt.fock_dm(NFock, n) for n in range(NFock))

    return H
예제 #19
0
def fit(x, M, test=False):
    """
    Find corrected parameters for flow distribution `x` with multiplicity `M`.

    Returns various parameters depending on the test option.


    The likelihood function of a Rice distribution often has two local maxima
    with different signal-to-noise ratios (SNR):

        -- high-SNR: (A, s) both finite
        -- low-SNR: (epsilon, s1) with epsilon nearly zero and s1 > s

    In the context of flow distributions, the high-SNR case corresponds to
    systematically driven flow (e.g. peripheral v_2) and the low-SNR case means
    fluctuation-only (e.g. central v_2).

    Finite multiplicity smearing reduces the SNR and makes it difficult to
    distinguish the two cases.

    The following prescription seems to work in nearly all cases:

        -- perform the high-SNR fit
        -- if the distribution is "noisy", also do the low-SNR fit
        -- compare the likelihoods of the two fits
        -- if they are very close, choose low-SNR

    When the likelihoods are similar, the low-SNR option tends to provide more
    sensible results after finite-multiplicity correction.

    The "noisy" criterion is based on the following observations

        -- The signal (Rice `A` parameter) cannot be reliably measured below
            the multiplicity flutuation 1/sqrt(M).
        -- SNR cannot be reliably determined below ~1.

    A distribution is "noisy" if the signal and SNR are small.

    Even in the noisy case, the multiplicity fluctuation can still be as large
    as the observed distribution.  This means effectively zero flow was
    observed within statistical error.  In this case, flow is reverted to a
    reasonable minimum.

    """

    # estimate parameters using sample moments
    # sigma ~ standard deviation
    # mu_2 = A^2 + 2*sigma^2
    s0 = x.std()
    A0 = max(np.square(x).mean()-2.*s0*s0, 0.)**.5
    x0 = np.array((A0, s0))

    # high-SNR fit
    res = _fit(x, x0)
    A, s = res.x

    # check if this is a "noisy" distribution
    if A < M**(-.5) and A/s < 1.2:
        # low-SNR fit
        s1 = (s**2. + .5*A**2.)**.5
        res1 = _fit(x, (1e-3, s1))

        ll = res.fun
        ll1 = res1.fun

        # choose low-SNR if the two likelihoods are very close
        if abs((ll-ll1)/ll) < 5.e-3:
            res = res1

    # extract flow dist. params
    vnrp, dvnobs = res.x

    # correct for finite multiplicity
    # revert to a sensible minimum in the zero-flow scenario
    dvn2 = dvnobs*dvnobs - .5/M
    if dvn2 < 0:
        dvn2 = 1.e-5
        vnrp = 0.

    dvn = dvn2**.5
    vnrp2 = vnrp * vnrp

    # calculate mean and width
    mean = (.5*np.pi)**.5 * dvn * spc.eval_laguerre(.5, -.5*vnrp2/dvn2)
    if np.isnan(mean):
        mean = vnrp + .5*dvn2/vnrp
    width = np.sqrt(2.*dvn2 + vnrp2 - mean*mean)

    if test:
        return vnrp, dvnobs, dvn, mean, width
    else:
        return mean, width
예제 #20
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 25 21:59:55 2019

@author: gustavo
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy.special import eval_laguerre

x = np.linspace(0, 5, 200)

for i in range(6):
    plt.plot(x, eval_laguerre(i, x), color='k')

plt.title('Polinomios de Laguerre $L_{n}(x)$')
plt.text(1, 1.2, '$L_{0}$')
plt.text(3, -1.8, '$L_{1}$')
plt.text(3.2, -0.8, '$L_{2}$')
plt.text(4, 2.7, '$L_{3}$')
plt.text(4.5, 0.4, '$L_{4}$')
plt.text(4.2, -1.2, '$L_{5}$')
plt.axhline(y=0, lw=0.8, ls='dashed', color='k')
plt.xlim(0, 5)
#plt.ylim(-5, 5)
plt.show()
 
 
예제 #21
0
def eval_laguerre_ld(n, x):
    return eval_laguerre(n.astype('l'), x)
예제 #22
0
def testFunctions():
    print(colored('Testing Polynomial functions', 'magenta'))
    ORDER_MAX = 5
    DECIMALS_ROUND = 7

    print(colored('Testing chebyshev_t_Scaler', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_chebyt(order, x)
        valueCpp = NumCpp.chebyshev_t_Scaler(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing chebyshev_t_Array', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_chebyt(order, x)
        valueCpp = NumCpp.chebyshev_t_Array(order, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing chebyshev_u_Scaler', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_chebyu(order, x)
        valueCpp = NumCpp.chebyshev_u_Scaler(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing chebyshev_u_Array', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_chebyu(order, x)
        valueCpp = NumCpp.chebyshev_u_Array(order, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing hermite_Scaler', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_hermite(order, x)
        valueCpp = NumCpp.hermite_Scaler(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing hermite_Array', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_hermite(order, x)
        valueCpp = NumCpp.hermite_Array(order, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing laguerre_Scaler1', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_laguerre(order, x)
        valueCpp = NumCpp.laguerre_Scaler1(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing laguerre_Array1', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_laguerre(order, x)
        valueCpp = NumCpp.laguerre_Array1(order, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing laguerre_Scaler2', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(0, 10, [
            1,
        ]).item()
        x = np.random.rand(1).item()
        valuePy = sp.eval_genlaguerre(degree, order, x)
        valueCpp = NumCpp.laguerre_Scaler2(order, degree, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing laguerre_Array2', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(0, 10, [
            1,
        ]).item()
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_genlaguerre(degree, order, x)
        valueCpp = NumCpp.laguerre_Array2(order, degree, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing legendre_p_Scaler1', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.eval_legendre(order, x)
        valueCpp = NumCpp.legendre_p_Scaler1(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing legendre_p_Array1', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        shapeInput = np.random.randint(10, 100, [
            2,
        ], dtype=np.uint32)
        shape = NumCpp.Shape(*shapeInput)
        cArray = NumCpp.NdArray(shape)
        x = np.random.rand(*shapeInput)
        cArray.setArray(x)
        valuePy = sp.eval_legendre(order, x)
        valueCpp = NumCpp.legendre_p_Array1(order, cArray)
        if not np.array_equal(np.round(valuePy, DECIMALS_ROUND),
                              np.round(valueCpp, DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))

    print(colored('Testing legendre_p_Scaler2', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        degree = np.random.randint(order, ORDER_MAX)
        valuePy = sp.lpmn(order, degree, x)[0][order, degree]
        valueCpp = NumCpp.legendre_p_Scaler2(order, degree, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing legendre_q_Scaler', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        x = np.random.rand(1).item()
        valuePy = sp.lqn(order, x)[0][order]
        valueCpp = NumCpp.legendre_q_Scaler(order, x)
        if np.round(valuePy, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing spherical_harmonic', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(order, ORDER_MAX)
        theta = np.random.rand(1).item() * np.pi * 2
        phi = np.random.rand(1).item() * np.pi
        valuePy = sp.sph_harm(order, degree, theta, phi)
        valueCpp = NumCpp.spherical_harmonic(order, degree, theta, phi)
        if (np.round(valuePy.real, DECIMALS_ROUND) != np.round(
                valueCpp[0], DECIMALS_ROUND)
                or np.round(valuePy.imag, DECIMALS_ROUND) != np.round(
                    valueCpp[1], DECIMALS_ROUND)):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing spherical_harmonic_r', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(order, ORDER_MAX)
        theta = np.random.rand(1).item() * np.pi * 2
        phi = np.random.rand(1).item() * np.pi
        valuePy = sp.sph_harm(order, degree, theta, phi)
        valueCpp = NumCpp.spherical_harmonic_r(order, degree, theta, phi)
        if np.round(valuePy.real, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')

    print(colored('Testing spherical_harmonic_i', 'cyan'))
    allTrue = True
    for order in range(ORDER_MAX):
        degree = np.random.randint(order, ORDER_MAX)
        theta = np.random.rand(1).item() * np.pi * 2
        phi = np.random.rand(1).item() * np.pi
        valuePy = sp.sph_harm(order, degree, theta, phi)
        valueCpp = NumCpp.spherical_harmonic_i(order, degree, theta, phi)
        if np.round(valuePy.imag, DECIMALS_ROUND) != np.round(
                valueCpp, DECIMALS_ROUND):
            allTrue = False

    if allTrue:
        print(colored('\tPASS', 'green'))
    else:
        print(colored('\tFAIL', 'red'))
        print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')
예제 #23
0
def R3(r):
    #return( 0.5*((2*z*r/(n*a0))**2 - 4*(2*z*r/(n*a0)) + 2) )
    return (eval_laguerre(n + l, 2 * z * r / (n * a0)))
예제 #24
0
def eval_laguerre_dd(n, x):
    return eval_laguerre(n.astype('d'), x)
예제 #25
0
def L(N, x):  #eval laguerre function
    a = eval_laguerre(N, x)
    return a