def test_aca_func(): # check whether functional matrizitation is identical with original one N = 50 for obj in ["B1", "B2"]: C_list = [] ranks = np.array([N, N, N]) for mode in range(3): if mode == 0: if obj == "B1": functional_generator = aca_fun.mode_m_matricization_fun( aca_fun.b1, N, N, N) C, U, R = aca_fun.aca_partial_pivoting( functional_generator, N, N * N, N, 10e-4 / 3) tensor = np.asarray(utilis.get_B_one(N)) else: functional_generator = aca_fun.mode_m_matricization_fun( aca_fun.b2, N, N, N) C, U, R = aca_fun.aca_partial_pivoting( functional_generator, N, N * N, N, 10e-4 / 3) tensor = np.asarray(utilis.get_B_two(N)) else: Core_mat = tl.unfold(Core_ten, mode) C, U, R = aca_fun.aca_full_pivoting(Core_mat, 10e-4 / 3) ranks[mode] = U.shape[0] Core_ten = tl.fold(np.dot(U, R), mode, ranks) C_list.append(C) recon = utilis.reconstruct_tensor(C_list, Core_ten, tensor) error = utilis.frobenius_norm_tensor(recon - tensor) assert (error < 10e-4 * utilis.frobenius_norm_tensor(tensor))
def run_aca_part(): N = 200 C_list = [] ranks = np.array([N, N, N]) for mode in range(3): if mode == 0: functional_generator = aca_fun.mode_m_matricization_fun( aca_fun.b2, N, N, N) C, U, R = aca_fun.aca_partial_pivoting(functional_generator, N, N * N, N, 10e-5 / 3) else: Core_mat = tl.unfold(Core_ten, mode) C, U, R = aca_fun.aca_full_pivoting(Core_mat, 10e-5 / 3) ranks[mode] = U.shape[0] Core_ten = tl.fold(np.dot(U, R), mode, ranks) C_list.append(C)
def run_aca_full(): N = 200 C_list = [] ranks = np.array([N, N, N]) tensor = np.asarray(utilis.get_B_one(N)) for mode in range(3): if mode == 0: # Start with original matrix Core_mat = tl.unfold(tensor, mode) else: Core_mat = tl.unfold(Core_ten, mode) C, U, R = aca_fun.aca_full_pivoting(Core_mat, 10e-5) ranks[mode] = U.shape[0] print(f'Current ranks: {ranks}') Core_ten = tl.fold(np.dot(U, R), mode, ranks) C_list.append(C)