def test_uniform(self): """test uniform tensor train""" # construct uniform tensor train norm = 10 * np.random.rand() t_uni = tt.uniform(self.row_dims, ranks=self.ranks[1], norm=norm) # compute norms norm_tt = t_uni.norm() # compute relative error rel_err = (norm_tt - norm) / norm # check if relative error is smaller than tolerance self.assertLess(rel_err, self.tol)
utl.progress('Load data', 0, dots=39) transitions = io.loadmat("data/QuadrupleWell3D_25x25x25_100.mat")["indices"] # load data utl.progress('Load data', 100, dots=39) # construct TT operator # --------------------- utl.progress('Construct operator', 0, dots=30) operator = pf.perron_frobenius_3d(transitions, [n_states] * 3, simulations) utl.progress('Construct operator', 100, dots=30) # approximate leading eigenfunctions # ---------------------------------- utl.progress('Approximate eigenfunctions in the TT format', 0, dots=5) initial = tt.uniform(operator.row_dims, ranks=[1, 20, 10, 1]) eigenvalues, eigenfunctions = evp.als(operator, initial, number_ev, 2) utl.progress('Approximate eigenfunctions in the TT format', 100, dots=5) # compute exact eigenvectors # -------------------------- utl.progress('Compute exact eigenfunctions in matrix format', 0) eigenvalues_exact, eigenfunctions_exact = splin.eigs(operator.matricize(), k=number_ev) idx = eigenvalues_exact.argsort()[::-1] eigenvalues_exact = eigenvalues_exact[idx] eigenfunctions_exact = eigenfunctions_exact[:, idx] utl.progress('Compute exact eigenfunctions in matrix format', 100) # convert results to matrices # ----------------------------------
# ----------------------------------------------------------- initial_distribution = tt.zeros([2**m, 2**(m + 1), 2**m, 2**m], [1] * 4) initial_distribution.cores[0][0, -1, 0, 0] = 1 initial_distribution.cores[1][0, -2, 0, 0] = 1 initial_distribution.cores[2][0, 0, 0, 0] = 1 initial_distribution.cores[3][0, 0, 0, 0] = 1 initial_distribution = TT.tt2qtt( initial_distribution, [[2] * m] + [[2] * (m + 1)] + [[2] * m] + [[2] * m], [[1] * m] + [[1] * (m + 1)] + [[1] * m] + [[1] * m], threshold=0) # initial guess in QTT format # --------------------------- initial_guess = tt.uniform([2] * (4 * m + 1), ranks=qtt_rank).ortho_right() # solve Markovian master equation in QTT format # --------------------------------------------- solution = ode.implicit_euler(operator, initial_distribution, initial_guess, step_sizes, tt_solver='mals', threshold=1e-10, max_rank=max_rank) # compute approximation errors errors = ode.errors_impl_euler(operator, solution, step_sizes) print('Maximum error: ' + str("%.2e" % np.amax(errors)) + '\n')