Esempio n. 1
0
def derivatives_of_kernel(nodes, x, ompParallel=parallel):
    #given x_i and x_j the K = Kernel( x_ij) and derivatives with x_ij = x_i - x_j.
    #The code is written such that we evaluate at the nodes, and entry (i,j) is the contribution at node i due to particle j.
    delta = np.identity(DIM)
    G, DG, D2G, D3G, D4G, D5G, D6G = gaussian.derivatives_of_Gaussians(
        nodes.reshape([-1, DIM]), x.reshape([N, DIM]), ompParallel)
    K = np.einsum('ij,ab->ijab', G, delta)
    DK = np.einsum('ijc,ab->ijabc', DG, delta)
    D2K = np.einsum('ijcd,ab->ijabcd', D2G, delta)
    #D3K = np.einsum('ijcde,ab->ijabcde',D3G,delta)
    #EXAMPLE OF INDEX CONVENTION 'ijabc' refers to the c^th derivative of the ab^th entry of K(q_i - q_j)
    return K, DK, D2K
Esempio n. 2
0
def derivatives_of_kernel( nodes , q, ompParallel=False ):
    #given x_i and x_j the K = Kernel( x_ij) and derivatives with x_ij = x_i - x_j.
    #The code is written such that we evaluate at the nodes, and entry (i,j) is the contribution at node i due to particle j.
    delta = np.identity( DIM )
    G,DG,D2G,D3G,D4G,D5G,D6G = gaussian.derivatives_of_Gaussians( nodes , q, ompParallel )
    K = np.einsum('ij,ab->ijab',G,delta)
    DK = np.einsum('ijc,ab->ijabc',DG,delta)
    D2K = np.einsum('ijcd,ab->ijabcd',D2G,delta)
    D3K = np.einsum('ijcde,ab->ijabcde',D3G,delta)
    D4K = np.einsum('ijcdef,ab->ijabcdef',D4G,delta)
    D5K = np.einsum('ijcdefg,ab->ijabcdefg',D5G,delta)
    D6K = np.einsum('ijcdefgh,ab->ijabcdefgh',D6G,delta)
    #EXAMPLE OF INDEX CONVENTION 'ijabc' refers to the c^th derivative of the ab^th entry of K(q_i - q_j)
    return K, DK, D2K, D3K , D4K , D5K , D6K
def test_Gaussians( q ):
    h = 1e-9
    G,DG,D2G,D3G,D4G,D5G,D6G = gaussian.derivatives_of_Gaussians(q,q)
    q_a = np.copy(q)
    q_b = np.copy(q)
    q_c = np.copy(q)
    q_d = np.copy(q)
    q_e = np.copy(q)
    q_f = np.copy(q)
    for i in range(0,N):
        for a in range(0,DIM):
            error_max = 0.
            q_a[i,a] = q[i,a]+h
            G_a , DG_a , D2G_a , D3G_a, D4G_a , D5G_a ,D6G_a = gaussian.derivatives_of_Gaussians(q_a, q) 
            for j in range(0,N):
                error = (G_a[i,j] - G[i,j])/h - DG[i,j,a]
                error_max = np.maximum( np.absolute( error ) , error_max )
            print 'max error for DG was ' + str( error_max )
            error_max = 0.
            for b in range(0,DIM):
                q_b[i,b] = q[i,b] + h
                G_b , DG_b , D2G_b , D3G_b , D4G_b , D5G_b , D6G_b = gaussian.derivatives_of_Gaussians( q_b , q ) 
                for j in range(0,N):
                    error = (DG_b[i,j,a] - DG[i,j,a])/h - D2G[i,j,a,b]
                    error_max = np.maximum( np.absolute( error ) , error_max )
                print 'max error for D2G was ' + str( error_max )
                error_max = 0.
                for c in range(0,DIM):
                    q_c[i,c] = q_c[i,c] + h
                    G_c , DG_c , D2G_c , D3G_c , D4G_c , D5G_c , D6G_c = gaussian.derivatives_of_Gaussians( q_c , q ) 
                    for j in range(0,N):
                        error = (D2G_c[i,j,a,b] - D2G[i,j,a,b])/h - D3G[i,j,a,b,c]
                        error_max = np.maximum( np.absolute(error) , error_max )
                    print 'max error for D3G was ' + str( error_max )
                    error_max = 0.
                    for d in range(0,DIM):
                        q_d[i,d] = q[i,d] + h
                        G_d, DG_d , D2G_d , D3G_d, D4G_d , D5G_d , D6G_d = gaussian.derivatives_of_Gaussians( q_d , q )
                        for j in range(0,N):
                            error = (D3G_d[i,j,a,b,c] - D3G[i,j,a,b,c])/h - D4G[i,j,a,b,c,d]
                            error_max = np.maximum( np.absolute(error) , error_max )
                        print 'max error for D4G was '+ str(error_max)
                        error_max = 0.
                        for e in range(0,DIM):
                            q_e[i,e] = q[i,e] + h
                            G_e, DG_e , D2G_e , D3G_e, D4G_e, D5G_e , D6G_e = gaussian.derivatives_of_Gaussians( q_e , q )
                            for j in range(0,N):
                                error = (D4G_e[i,j,a,b,c,d] - D4G[i,j,a,b,c,d])/h - D5G[i,j,a,b,c,d,e]
                                error_max = np.maximum( np.absolute(error) , error_max )
                            print 'max error for D5G was '+ str(error_max)
                            for f in range(0,DIM):
                                q_f[i,f] = q[i,f] + h
                                G_f, DG_f , D2G_f , D3G_f, D4G_f, D5G_f,D6G_f = gaussian.derivatives_of_Gaussians( q_f , q )
                                for j in range(0,N):
                                    error = (D5G_f[i,j,a,b,c,d,e] - D5G[i,j,a,b,c,d,e])/h - D6G[i,j,a,b,c,d,e,f]
                                    error_max = np.maximum( np.absolute(error) , error_max )
                                    print 'max error for D6G was '+ str(error_max)
                                    error_max = 0.
                                q_f[i,f] = q_f[i,f] - h
                            q_e[i,e] = q_e[i,e] - h
                        q_d[i,d] = q_d[i,d] - h
                    q_c[i,c] = q_c[i,c] - h
                q_b[i,b] = q_b[i,b] - h
            q_a[i,a] = q_a[i,a] - h
    return 1
Esempio n. 4
0
def test_Gaussians( q ):
    h = 1e-9
    G,DG,D2G,D3G,D4G,D5G,D6G = gaussian.derivatives_of_Gaussians(q,q)
    q_a = np.copy(q)
    q_b = np.copy(q)
    q_c = np.copy(q)
    q_d = np.copy(q)
    q_e = np.copy(q)
    q_f = np.copy(q)
    for i in range(0,N):
        for a in range(0,DIM):
            error_max = 0.
            q_a[i,a] = q[i,a]+h
            G_a , DG_a , D2G_a , D3G_a, D4G_a , D5G_a ,D6G_a = gaussian.derivatives_of_Gaussians(q_a, q) 
            for j in range(0,N):
                error = (G_a[i,j] - G[i,j])/h - DG[i,j,a]
                error_max = np.maximum( np.absolute( error ) , error_max )
            print 'max error for DG was ' + str( error_max )
            error_max = 0.
            for b in range(0,DIM):
                q_b[i,b] = q[i,b] + h
                G_b , DG_b , D2G_b , D3G_b , D4G_b , D5G_b , D6G_b = gaussian.derivatives_of_Gaussians( q_b , q ) 
                for j in range(0,N):
                    error = (DG_b[i,j,a] - DG[i,j,a])/h - D2G[i,j,a,b]
                    error_max = np.maximum( np.absolute( error ) , error_max )
                print 'max error for D2G was ' + str( error_max )
                error_max = 0.
                for c in range(0,DIM):
                    q_c[i,c] = q_c[i,c] + h
                    G_c , DG_c , D2G_c , D3G_c , D4G_c , D5G_c , D6G_c = gaussian.derivatives_of_Gaussians( q_c , q ) 
                    for j in range(0,N):
                        error = (D2G_c[i,j,a,b] - D2G[i,j,a,b])/h - D3G[i,j,a,b,c]
                        error_max = np.maximum( np.absolute(error) , error_max )
                    print 'max error for D3G was ' + str( error_max )
                    error_max = 0.
                    for d in range(0,DIM):
                        q_d[i,d] = q[i,d] + h
                        G_d, DG_d , D2G_d , D3G_d, D4G_d , D5G_d , D6G_d = gaussian.derivatives_of_Gaussians( q_d , q )
                        for j in range(0,N):
                            error = (D3G_d[i,j,a,b,c] - D3G[i,j,a,b,c])/h - D4G[i,j,a,b,c,d]
                            error_max = np.maximum( np.absolute(error) , error_max )
                        print 'max error for D4G was '+ str(error_max)
                        error_max = 0.
                        for e in range(0,DIM):
                            q_e[i,e] = q[i,e] + h
                            G_e, DG_e , D2G_e , D3G_e, D4G_e, D5G_e , D6G_e = gaussian.derivatives_of_Gaussians( q_e , q )
                            for j in range(0,N):
                                error = (D4G_e[i,j,a,b,c,d] - D4G[i,j,a,b,c,d])/h - D5G[i,j,a,b,c,d,e]
                                error_max = np.maximum( np.absolute(error) , error_max )
                            print 'max error for D5G was '+ str(error_max)
                            for f in range(0,DIM):
                                q_f[i,f] = q[i,f] + h
                                G_f, DG_f , D2G_f , D3G_f, D4G_f, D5G_f,D6G_f = gaussian.derivatives_of_Gaussians( q_f , q )
                                for j in range(0,N):
                                    error = (D5G_f[i,j,a,b,c,d,e] - D5G[i,j,a,b,c,d,e])/h - D6G[i,j,a,b,c,d,e,f]
                                    error_max = np.maximum( np.absolute(error) , error_max )
                                    print 'max error for D6G was '+ str(error_max)
                                    error_max = 0.
                                q_f[i,f] = q_f[i,f] - h
                            q_e[i,e] = q_e[i,e] - h
                        q_d[i,d] = q_d[i,d] - h
                    q_c[i,c] = q_c[i,c] - h
                q_b[i,b] = q_b[i,b] - h
            q_a[i,a] = q_a[i,a] - h
    return 1