def predicition(dmddataset, days): hodmd = HODMD(svd_rank=0, exact=True, opt=True, d=len(dmddataset) / days).fit(dmddataset) hodmd.reconstructed_data.shape hodmd.plot_eigs() hodmd.dmd_time['tend'] = len(dmddataset) / days * ( days + 1) - 1 # since it starts from zero dmd_output = hodmd.reconstructed_data[0].real dmd_prediction = dmd_output[-len(dmddataset) / days:] return dmd_prediction, dmd_output
print('Computing DMD...') # ---------------------------------------------------------------------------------------------------------------------- # Compute DMD on displacement d = 5 dmd = HODMD(svd_rank=rank, opt=True, d=d) # dmd = MrDMD(svd_rank=rank, max_level = 3, max_cycles = 1) dmd.fit(dataGrid.T) # Show eigenvalues for eig in dmd.eigs: print('Eigenvalue {}: distance from unit circle {}'.format(eig, np.abs(eig.imag**2+eig.real**2 - 1))) dmd.plot_eigs(show_axes=True, show_unit_circle=True) # Show modes fig = plt.figure(figsize=(8,3)) fig.subplots_adjust(top=0.8, bottom=0.2) plt.subplot(121) for mode in dmd.modes.T: plt.plot(xVector, mode.real) plt.title('Modes') plt.xlabel('$x$') # fig.savefig('DMDResults/DMDModes_'+fileName+'_Rank-%i_d-%i.png'%(rank,d)) # plt.show() # Show dynamics # fig = plt.figure(figsize=(10,6)) plt.subplot(122)
from pydmd import HODMD x = int(input("predicted timestep-\n")) z = int(input("data cutoff-\n")) b = slice(0, z) A = np.loadtxt('dmd.txt', delimiter=",") B = A.T C = B[:, b] original = C print(C.shape) hodmd = HODMD(svd_rank=0, exact=True, opt=True, d=30).fit(C) print(hodmd.reconstructed_data.shape) hodmd.plot_eigs() hodmd.original_time['dt'] = hodmd.dmd_time['dt'] hodmd.original_time['t0'] = hodmd.dmd_time['t0'] hodmd.original_time['tend'] = hodmd.dmd_time['tend'] plt.plot(hodmd.original_timesteps, C[0, :], '.', label='snapshots') plt.plot(hodmd.original_timesteps, original[0, :], '-', label='original function') plt.plot(hodmd.dmd_timesteps, hodmd.reconstructed_data[0].real, '--', label='DMD output') plt.legend() plt.show()