def test_MLSVD_shape(self):
     """Given a tensor of dimension D compute multilinear_SVD and
     check the size of each part of the result.
     """
     D = (2,3,4)
     A = np.arange(np.prod(D)).reshape(*D)
     U_s_Vh_list = tensorial_kernel.multilinear_SVD(A)
     assert(len(U_s_Vh_list) == len(D)) # check number of unfoldings
     for i in range(len(D)):
         assert(len(U_s_Vh_list[i]) == 3) # check number of results of each SVD
         U, s, Vh = U_s_Vh_list[i]
         assert(U.shape == (D[i], D[i])) # check shape of U
         assert(s.shape == (D[i],)) # check shape of s
         assert(Vh.shape == (D[i], np.prod(D[:i]+D[i+1:]))) # check shape of Vh
Esempio n. 2
0
 def test_MLSVD_shape(self):
     """Given a tensor of dimension D compute multilinear_SVD and
     check the size of each part of the result.
     """
     D = (2, 3, 4)
     A = np.arange(np.prod(D)).reshape(*D)
     U_s_Vh_list = tensorial_kernel.multilinear_SVD(A)
     assert (len(U_s_Vh_list) == len(D))  # check number of unfoldings
     for i in range(len(D)):
         assert (len(U_s_Vh_list[i]) == 3
                 )  # check number of results of each SVD
         U, s, Vh = U_s_Vh_list[i]
         assert (U.shape == (D[i], D[i]))  # check shape of U
         assert (s.shape == (D[i], ))  # check shape of s
         assert (Vh.shape == (D[i], np.prod(D[:i] + D[i + 1:]))
                 )  # check shape of Vh
import tensorial_kernel

if __name__=='__main__':

    import numpy as np

    D = [64, 64, 34, 4]
    # D = [276,10,10]
    D_X = [5] + D
    X = np.arange(np.prod(D_X)).reshape(*D_X)
    D_Y = [6] + D
    Y = np.arange(np.prod(D_Y)).reshape(*D_Y) + 1

    mlSVD = tensorial_kernel.multilinear_SVD(X[0])
    print "Projection Frobenius norm of ||X[0] - X[0]|| =",
    print tensorial_kernel.compute_projection_frobenius_norm(mlSVD, mlSVD)
    print
    
    mlSVD1 = tensorial_kernel.multilinear_SVD(X[1])
    print "Projection Frobenius norm of ||X[0] - X[1]|| =",
    print tensorial_kernel.compute_projection_frobenius_norm(mlSVD1, mlSVD)
    print