def test_dmdc_for_highdim_system(data_drss): Y, U, A, B, C = data_drss DMDc = regression.DMDc(svd_rank=7, svd_output_rank=5) model = Koopman(regressor=DMDc) model.fit(Y, U) # Check spectrum Aest = model.state_transition_matrix W, V = np.linalg.eig(A) West, Vest = np.linalg.eig(Aest) idxTrue = np.argsort(W) idxEst = np.argsort(West) assert_allclose(W[idxTrue], West[idxEst], 1e-07, 1e-12) # Check eigenvector reconstruction r = 5 Uc, sc, Vch = np.linalg.svd(C, full_matrices=False) Sc = np.diag(sc[:r]) Cinv = np.dot(Vch[:, :r].T, np.dot(np.linalg.inv(Sc), Uc[:, :r].T)) P = model.projection_matrix_output Atilde = np.dot(Cinv, np.dot(np.dot(P, np.dot(Aest, P.T)), C)) Wtilde, Vtilde = np.linalg.eig(Atilde) idxTilde = np.argsort(Wtilde) assert_allclose(W[idxTrue], Wtilde[idxTilde], 1e-07, 1e-12) # Evecs may be accurate up to a sign; ensured by seeding random generator # when producing the data set assert_allclose(V[:, idxTrue], Vtilde[:, idxTilde], 1e-07, 1e-12)
def test_simulate_accuracy_dmdc(data_2D_linear_control_system): X, C, _, _ = data_2D_linear_control_system DMDc = regression.DMDc(svd_rank=3) model = Koopman(regressor=DMDc).fit(X, C) n_steps = len(C) x_pred = model.simulate(X[0, :], C, n_steps=n_steps - 1) assert_allclose(X[1:n_steps, :], x_pred, 1e-07, 1e-12)
def test_if_dmdc_model_is_accurate_with_known_controlmatrix( data_2D_linear_control_system, ): X, C, A, B = data_2D_linear_control_system model = Koopman() DMDc = regression.DMDc(svd_rank=3, control_matrix=B) model = Koopman(regressor=DMDc).fit(X, C) Aest = model.state_transition_matrix assert_allclose(Aest, A, 1e-07, 1e-12)