from d3s.tools import printVector, printMatrix #%% load variables from mat file into main scope data = sp.io.loadmat('data/lorenz.mat', squeeze_me=True) for s in data.keys(): if s[:2] == '__' and s[-2:] == '__': continue exec('%s = data["%s"]' % (s, s)) #%% apply SINDy d = X.shape[0] p = 2 # maximum order of monomials psi = observables.monomials(p) Xi1 = algorithms.sindy(X, Y, psi, iterations=1) c = observables.allMonomialPowers(d, p) n = c.shape[1] # number of functions #%% output results printMatrix(c) printMatrix(Xi1) #%% apply gEDMD K, _, _ = algorithms.gedmd(X, Y, None, psi) # construct projection onto full-state observable B = np.zeros((10, d)) for i in range(3): B[i+1, i] = 1 Xi2 = (K@B).T printMatrix(Xi2)
# apply generator EDMD evs = 3 # number of eigenvalues/eigenfunctions to be computed K, d, V = algorithms.gedmd(X, Y, Z, psi, evs=evs, operator='K') printVector(np.real(d), 'd') # plot eigenfunctions c = Omega.midpointGrid() Psi_c = psi(c) for i in range(evs): plt.figure(i + 1) plt.clf() Omega.plot(np.real(V[:, i].T @ Psi_c), mode='3D') #%% system identification order = 4 # reduce order of monomials p = observables.allMonomialPowers(2, order) n = p.shape[1] # number of monomials up to order 4 printMatrix(p, 'p') printMatrix(K[:n, :n], 'K') # compute entries of a evaluated in c b_c = K[:, 1:3].T @ Psi_c a_11 = K[:, 3].T @ Psi_c - 2 * b_c[0, :] * c[0, :] a_12 = K[:, 4].T @ Psi_c - b_c[0, :] * c[1, :] - b_c[1, :] * c[0, :] a_22 = K[:, 5].T @ Psi_c - 2 * b_c[1, :] * c[1, :] plt.figure(evs + 1) Omega.plot(a_11, mode='3D') plt.figure(evs + 2)