Пример #1
0
 def test_eigs_3(self):
     dmd = HODMD(svd_rank=2)
     dmd.fit(X=sample_data)
     expected_eigs = np.array([
         -8.09016994e-01 + 5.87785252e-01j, -4.73868662e-01 + 8.80595532e-01j
     ])
     np.testing.assert_almost_equal(dmd.eigs, expected_eigs, decimal=6)
Пример #2
0
 def test_dmd_time_3(self):
     dmd = HODMD()
     dmd.fit(X=sample_data)
     dmd.dmd_time['t0'] = 8
     dmd.dmd_time['tend'] = 11
     expected_data = sample_data[:, 8:12]
     np.testing.assert_allclose(dmd.reconstructed_data, expected_data)
Пример #3
0
    def test_nonan_nomask(self):
        dmd = HODMD(d=3)
        dmd.fit(X=sample_data)
        rec = dmd.reconstructed_data

        assert not isinstance(rec, np.ma.MaskedArray)
        assert not np.nan in rec
Пример #4
0
 def test_Atilde_values(self):
     dmd = HODMD(svd_rank=2)
     dmd.fit(X=sample_data)
     exact_atilde = np.array(
         [[-0.70558526 + 0.67815084j, 0.22914898 + 0.20020143j],
          [0.10459069 + 0.09137814j, -0.57730040 + 0.79022994j]])
     np.testing.assert_allclose(exact_atilde, dmd.atilde)
Пример #5
0
 def test_nonan_nomask(self):
     dmd = HODMD(d=3)
     dmd.fit(X=sample_data)
     for timeindex in range(sample_data.shape[1]):
         ds = dmd.reconstructions_of_timeindex(timeindex)
         for mx in ds:
             assert not np.ma.is_masked(mx)
             assert np.nan not in mx
Пример #6
0
 def test_dmd_time_4(self):
     dmd = HODMD(svd_rank=3)
     dmd.fit(X=sample_data)
     dmd.dmd_time['t0'] = 20
     dmd.dmd_time['tend'] = 20
     expected_data = np.array([[-7.29383297e+00 - 4.90248179e-14j],
                               [-5.69109796e+00 - 2.74068833e+00j],
                               [3.38410649e-83 + 3.75677740e-83j]])
     np.testing.assert_almost_equal(dmd.dynamics, expected_data, decimal=6)
Пример #7
0
 def test_dynamics_opt_2(self):
     dmd = HODMD(svd_rank=1, opt=True)
     dmd.fit(X=sample_data)
     expected_dynamics = np.array([[
         -4.56004133 - 6.48054238j, 7.61228319 + 1.4801793j,
         -6.37489962 + 4.11788355j, 1.70548899 - 7.22866146j,
         3.69875496 + 6.25701574j, -6.85298745 - 1.90654427j,
         6.12829151 - 3.30212967j, -2.08469012 + 6.48584004j,
         -2.92745126 - 5.99004747j, 6.12772217 + 2.24123565j,
         -5.84352626 + 2.57413711j, 2.37745273 - 5.77906544j,
         2.24158249 + 5.68989493j, -5.44023459 - 2.49457492j,
         5.53024740 - 1.92916437j
     ]])
     np.testing.assert_allclose(dmd.dynamics, expected_dynamics)
Пример #8
0
 def test_dynamics_2(self):
     dmd = HODMD(svd_rank=1)
     dmd.fit(X=sample_data)
     expected_dynamics = np.array([[
         -2.20639502 - 9.10168802e-16j, 1.55679980 - 1.49626864e+00j,
         -0.08375915 + 2.11149018e+00j, -1.37280962 - 1.54663768e+00j,
         2.01748787 + 1.60312745e-01j, -1.53222592 + 1.25504678e+00j,
         0.23000498 - 1.92462280e+00j, 1.14289644 + 1.51396355e+00j,
         -1.83310653 - 2.93174173e-01j, 1.49222925 - 1.03626336e+00j,
         -0.35015209 + 1.74312867e+00j, -0.93504202 - 1.46738182e+00j,
         1.65485808 + 4.01263449e-01j, -1.43976061 + 8.39117825e-01j,
         0.44682540 - 1.56844403e+00j
     ]])
     np.testing.assert_allclose(dmd.dynamics, expected_dynamics)
Пример #9
0
 def test_truncation_shape(self):
     dmd = HODMD(svd_rank=3)
     dmd.fit(X=sample_data)
     assert dmd.modes.shape[1] == 3
Пример #10
0
 def test_rank(self):
     dmd = HODMD(svd_rank=0.9)
     dmd.fit(X=sample_data)
     assert len(dmd.eigs) == 2
Пример #11
0
 def test_rec_method_weighted(self):
     dmd = HODMD(d=2, reconstruction_method=[10, 20])
     dmd.fit(X=sample_data)
     assert (dmd.reconstructed_data.T[4] == np.average(
         dmd.reconstructions_of_timeindex(4), axis=0,
         weights=[10, 20]).T).all()
Пример #12
0
 def test_shape(self):
     dmd = HODMD(svd_rank=-1)
     dmd.fit(X=sample_data)
     assert dmd.modes.shape[1] == sample_data.shape[1] - 1
Пример #13
0
 def test_dynamics_1(self):
     dmd = HODMD(svd_rank=5)
     dmd.fit(X=sample_data)
     assert dmd.dynamics.shape == (5, sample_data.shape[1])
Пример #14
0
 def test_plot_modes_3(self):
     dmd = HODMD()
     snapshots = [snap.reshape(20, 20) for snap in sample_data.T]
     dmd.fit(X=snapshots)
     dmd.plot_modes_2D()
     plt.close()
Пример #15
0
 def test_original_timesteps(self):
     dmd = HODMD()
     dmd.fit(X=sample_data)
     np.testing.assert_allclose(dmd.original_timesteps,
                                np.arange(sample_data.shape[1]))
Пример #16
0
 def test_reconstructed_data(self):
     dmd = HODMD()
     dmd.fit(X=sample_data)
     dmd_data = dmd.reconstructed_data
     np.testing.assert_allclose(dmd_data, sample_data)
Пример #17
0
 def test_plot_snapshots_5(self):
     dmd = HODMD()
     snapshots = [snap.reshape(20, 20) for snap in sample_data.T]
     dmd.fit(X=snapshots)
     dmd.plot_snapshots_2D(index_snap=2, filename='tmp.png')
     self.addCleanup(os.remove, 'tmp.2.png')
Пример #18
0
 def test_dmd_time_1(self):
     dmd = HODMD(svd_rank=2)
     dmd.fit(X=sample_data)
     expected_dict = {'dt': 1, 't0': 0, 'tend': 14}
     np.testing.assert_equal(dmd.dmd_time, expected_dict)
Пример #19
0
 def test_plot_snapshots_4(self):
     dmd = HODMD()
     snapshots = [snap.reshape(20, 20) for snap in sample_data.T]
     dmd.fit(X=snapshots)
     dmd.plot_snapshots_2D(index_snap=2)
     plt.close()
Пример #20
0
 def test_plot_snapshots_2(self):
     dmd = HODMD(svd_rank=-1)
     dmd.fit(X=sample_data)
     dmd.plot_snapshots_2D((1, 2, 5), x=np.arange(20), y=np.arange(20))
     plt.close()
Пример #21
0
 def test_plot_snapshots_1(self):
     dmd = HODMD()
     dmd.fit(X=sample_data)
     with self.assertRaises(ValueError):
         dmd.plot_snapshots_2D()
Пример #22
0
 def test_Atilde_shape(self):
     dmd = HODMD(svd_rank=3)
     dmd.fit(X=sample_data)
     assert dmd.atilde.shape == (dmd.svd_rank, dmd.svd_rank)
Пример #23
0
 def test_extract_versions_nonan(self):
     dmd = HODMD(d=3)
     dmd.fit(X=sample_data)
     for timeindex in range(sample_data.shape[1]):
         assert not np.nan in dmd.reconstructions_of_timeindex(timeindex)
Пример #24
0
 def test_d(self):
     single_data = np.sin(np.linspace(0, 10, 100))
     dmd = HODMD(svd_rank=-1, d=50, opt=True)
     dmd.fit(single_data)
     assert np.allclose(dmd.reconstructed_data.flatten(), single_data)
Пример #25
0
 def test_rec_method_first(self):
     dmd = HODMD(d=3, reconstruction_method='first')
     dmd.fit(X=sample_data)
     assert (dmd.reconstructed_data == dmd.reconstructions_of_timeindex()
             [:, 0].T).all()
Пример #26
0
 def test_eigs_2(self):
     dmd = HODMD(svd_rank=5)
     dmd.fit(X=sample_data)
     assert len(dmd.eigs) == 5
Пример #27
0
 def test_rec_method_mean(self):
     dmd = HODMD(d=3, reconstruction_method='mean')
     dmd.fit(X=sample_data)
     assert (dmd.reconstructed_data.T[2] == np.mean(
         dmd.reconstructions_of_timeindex(2), axis=0).T).all()
Пример #28
0
 def test_tdmd_plot(self):
     dmd = HODMD(tlsq_rank=3)
     dmd.fit(X=sample_data)
     dmd.plot_eigs(show_axes=False, show_unit_circle=False)
     plt.close()
Пример #29
0
 def test_plot_eigs_2(self):
     dmd = HODMD()
     dmd.fit(X=sample_data)
     dmd.plot_eigs(show_axes=False, show_unit_circle=False)
     plt.close()