Beispiel #1
0
 def test_cdmd_matrix_custom(self):
     matrix = np.random.permutation(
         (sample_data.shape[1] - 3) * sample_data.shape[0]).reshape(
             sample_data.shape[1] - 3, sample_data.shape[0]).astype(float)
     matrix /= float(np.sum(matrix))
     dmd = CDMD(compression_matrix=matrix)
     dmd.fit(X=sample_data)
     error_norm = np.linalg.norm(dmd.reconstructed_data - sample_data, 1)
     assert error_norm < 1e-10
Beispiel #2
0
 def test_dmd_time_2(self):
     dmd = CDMD()
     dmd.fit(X=sample_data)
     dmd.dmd_time['t0'] = 10
     dmd.dmd_time['tend'] = 14
     expected_data = sample_data[:, -5:]
     np.testing.assert_allclose(dmd.reconstructed_data, expected_data)
Beispiel #3
0
 def test_eigs_3(self):
     dmd = CDMD(svd_rank=2)
     dmd.fit(X=sample_data)
     expected_eigs = np.array(
         [-0.47386866 + 0.88059553j, -0.80901699 + 0.58778525j])
     np.testing.assert_almost_equal(dmd.eigs, expected_eigs, decimal=6)
Beispiel #4
0
 def test_dynamics_1(self):
     dmd = CDMD(svd_rank=5)
     dmd.fit(X=sample_data)
     assert dmd.dynamics.shape == (5, sample_data.shape[1])
Beispiel #5
0
 def test_Atilde_shape(self):
     dmd = CDMD(svd_rank=3)
     dmd.fit(X=sample_data)
     assert dmd.atilde.shape == (dmd.svd_rank, dmd.svd_rank)
Beispiel #6
0
 def test_eigs_2(self):
     dmd = CDMD(svd_rank=5)
     dmd.fit(X=sample_data)
     assert len(dmd.eigs) == 5
Beispiel #7
0
 def test_shape(self):
     dmd = CDMD(svd_rank=-1)
     dmd.fit(X=[d for d in sample_data.T])
     assert dmd.modes.shape[1] == sample_data.shape[1] - 1
Beispiel #8
0
 def test_truncation_shape(self):
     dmd = CDMD(svd_rank=3)
     dmd.fit(X=sample_data)
     assert dmd.modes.shape[1] == 3
Beispiel #9
0
 def test_dmd_time_1(self):
     dmd = CDMD(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)
Beispiel #10
0
 def test_plot_modes_3(self):
     dmd = CDMD()
     snapshots = [snap.reshape(20, 20) for snap in sample_data.T]
     dmd.fit(X=snapshots)
     dmd.plot_modes_2D()
     plt.close()
Beispiel #11
0
 def test_cdmd_matrix_sparse(self):
     dmd = CDMD(compression_matrix='sparse')
     dmd.fit(X=sample_data)
     error_norm = np.linalg.norm(dmd.reconstructed_data - sample_data, 1)
     assert error_norm < 1e-10
Beispiel #12
0
 def test_reconstructed_data(self):
     dmd = CDMD()
     dmd.fit(X=sample_data)
     dmd_data = dmd.reconstructed_data
     np.testing.assert_allclose(dmd_data, sample_data)
Beispiel #13
0
 def test_tdmd_plot(self):
     dmd = CDMD(tlsq_rank=3)
     dmd.fit(X=sample_data)
     dmd.plot_eigs(show_axes=False, show_unit_circle=False)
     plt.close()
Beispiel #14
0
 def test_plot_snapshots_5(self):
     dmd = CDMD()
     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')
Beispiel #15
0
 def test_plot_snapshots_4(self):
     dmd = CDMD()
     snapshots = [snap.reshape(20, 20) for snap in sample_data.T]
     dmd.fit(X=snapshots)
     dmd.plot_snapshots_2D(index_snap=2)
     plt.close()
Beispiel #16
0
 def test_plot_snapshots_2(self):
     dmd = CDMD(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()
Beispiel #17
0
 def test_plot_snapshots_1(self):
     dmd = CDMD()
     dmd.fit(X=sample_data)
     with self.assertRaises(ValueError):
         dmd.plot_snapshots_2D()
Beispiel #18
0
 def test_original_timesteps(self):
     dmd = CDMD()
     dmd.fit(X=sample_data)
     np.testing.assert_allclose(dmd.original_timesteps,
                                np.arange(sample_data.shape[1]))
Beispiel #19
0
 def test_sorted_eigs_default(self):
     dmd = CDMD(compression_matrix='sparse')
     assert dmd.operator._sorted_eigs == False
Beispiel #20
0
 def test_sorted_eigs_param(self):
     dmd = CDMD(compression_matrix='sparse', sorted_eigs='real')
     assert dmd.operator._sorted_eigs == 'real'
Beispiel #21
0
 def test_plot_eigs_2(self):
     dmd = CDMD()
     dmd.fit(X=sample_data)
     dmd.plot_eigs(show_axes=False, show_unit_circle=False)
     plt.close()