Esempio n. 1
0
 def test_singlular_values(self):
     a = POD('svd')
     a.reduce(snapshots)
     np.testing.assert_allclose(
         a.singular_values,
         np.array([887.15704, 183.2508, 84.11757, 26.40448]),
         rtol=1e-6,
         atol=1e-8)
Esempio n. 2
0
 def test_test_error(self):
     pod = POD(method='svd', rank=-1)
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf).fit()
     error = rom.test_error(db)
     np.testing.assert_almost_equal(error, 0, decimal=6)
Esempio n. 3
0
 def test_predict_04(self):
     pod = POD(method='svd', rank=3)
     gpr = GPR()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, gpr).fit()
     pred_sol = rom.predict(db.parameters)
     assert pred_sol.shape == db.snapshots.shape
Esempio n. 4
0
 def test_predict_01(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf).fit()
     pred_sol = rom.predict([-0.293344, -0.23120537])
     np.testing.assert_allclose(pred_sol, pred_sol_tst, rtol=1e-4, atol=1e-5)
Esempio n. 5
0
 def test_correlation_matirix(self):
     A = POD('correlation_matrix').reduce(snapshots)
     assert np.allclose(A, poddb, rtol=1e-03, atol=1e-08) or np.allclose(
         A,
         -1 * poddb,
         rtol=1e-03,
         atol=1e-08,
     )
Esempio n. 6
0
 def test_optimal_mu(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf).fit()
     opt_mu = rom.optimal_mu()
     np.testing.assert_allclose(opt_mu, [[-0.17687147, -0.21820951]],
                                rtol=1e-4)
Esempio n. 7
0
 def test_numpysvd(self):
     A = POD('svd').reduce(snapshots)
     assert np.allclose(A, poddb, rtol=1e-03, atol=1e-08) or np.allclose(
         A,
         -1 * poddb,
         rtol=1e-03,
         atol=1e-08,
     )
Esempio n. 8
0
 def test_correlation_matirix_savemem(self):
     A = POD('correlation_matrix', save_memory=True).reduce(snapshots)
     assert np.allclose(A, poddb, rtol=1e-03, atol=1e-08) or np.allclose(
         A,
         -1 * poddb,
         rtol=1e-03,
         atol=1e-08,
     )
Esempio n. 9
0
 def test_predict_02(self):
     np.random.seed(117)
     pod = POD(method='svd', rank=4)
     gpr = GPR()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, gpr).fit()
     pred_sol = rom.predict([-.45, -.45])
     np.testing.assert_allclose(pred_sol, pred_sol_gpr, rtol=1e-4, atol=1e-5)
Esempio n. 10
0
 def test_loo_error_singular_values(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf).fit()
     valid_svalues = rom.reduction.singular_values
     rom.loo_error()
     np.testing.assert_allclose(valid_svalues, rom.reduction.singular_values)
Esempio n. 11
0
 def test_save(self):
     fname = 'ezyrb.tmp'
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
     rom.fit()
     rom.save(fname)
Esempio n. 12
0
 def test_loo_error(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
     err = rom.loo_error()
     np.testing.assert_allclose(
         err,
         np.array([421.299091, 344.571787, 48.711501, 300.490491]),
         rtol=1e-4)
Esempio n. 13
0
 def test_kfold_cv_error_02(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
     err = rom.kfold_cv_error(n_splits=3)
     np.testing.assert_allclose(
         err,
         np.array([0.468199, 0.271776, 0.919509]),
         rtol=1e-4)
Esempio n. 14
0
 def test_predict_03(self):
     pod = POD(method='svd', rank=3)
     gpr = GPR()
     db = Database(param, snapshots.T)
     #rom = ROM(db, pod, RBF()).fit()
     #pred_sol = rom.predict([-.45, -.45])
     #print(pred_sol)
     rom = ROM(db, pod, gpr).fit()
     pred_sol = rom.predict(db.parameters[2])
     assert pred_sol.shape == db.snapshots[0].shape
Esempio n. 15
0
 def test_kfold_cv_error_03(self):
     pod = POD()
     gpr = GPR()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, gpr)
     err = rom.kfold_cv_error(n_splits=3, normalizer=False)
     np.testing.assert_allclose(
         err,
         np.array([0.664149, 1.355502, 0.379874]),
         rtol=1e-3)
Esempio n. 16
0
 def test_kfold_cv_error_01(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
     err = rom.kfold_cv_error(n_splits=4)
     np.testing.assert_allclose(
         err,
         np.array([0.54002856, 1.21174449, 0.27177608, 0.91950896]),
         rtol=1e-4)
Esempio n. 17
0
 def test_loo_error_02(self):
     pod = POD()
     gpr = GPR()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, gpr)
     err = rom.loo_error(normalizer=False)
     np.testing.assert_allclose(
         err[0],
         np.array(0.639247),
         rtol=1e-3)
Esempio n. 18
0
 def test_loo_error_01(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
     err = rom.loo_error()
     np.testing.assert_allclose(
         err,
         np.array([0.540029, 1.211744, 0.271776, 0.919509]),
         rtol=1e-4)
Esempio n. 19
0
 def test_reconstruction(self):
     f = torch.nn.Softplus
     ae = AE([20, 20, 2], [2, 20, 20], f(), f(), 1e-9)
     pod = POD(rank=4)
     podae = PODAE(pod, ae)
     podae.fit(snapshots)
     snapshots_ = podae.inverse_transform(podae.transform(snapshots))
     rerr = np.linalg.norm(snapshots_ -
                           snapshots) / np.linalg.norm(snapshots)
     assert rerr < 5e-3
Esempio n. 20
0
    def test_with_db_predict(self):
        reg = Linear()
        pod = POD()
        db = Database(np.array([1, 2, 3])[:,None], np.array([1, 5, 3])[:,None])
        rom = ReducedOrderModel(db, pod, reg)

        rom.fit()
        assert rom.predict([1]) == 1
        assert rom.predict([2]) == 5
        assert rom.predict([3]) == 3
Esempio n. 21
0
 def test_predict_scaler_01(self):
     from sklearn.preprocessing import StandardScaler
     scaler = StandardScaler()
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T, scaler_snapshots=scaler)
     rom = ROM(db, pod, rbf).fit()
     pred_sol = rom.predict(db.parameters[0])
     np.testing.assert_allclose(pred_sol, db._snapshots[0], rtol=1e-4, atol=1e-5)
     pred_sol = rom.predict(db.parameters[0:2])
     np.testing.assert_allclose(pred_sol, db._snapshots[0:2], rtol=1e-4, atol=1e-5)
Esempio n. 22
0
    def test_with_db_predict(self):
        reg = RadiusNeighborsRegressor(radius=0.5)
        pod = POD()
        db = Database(
            np.array([1, 2, 3])[:, None],
            np.array([1, 5, 3])[:, None])
        rom = ReducedOrderModel(db, pod, reg)

        rom.fit()
        assert rom.predict([1]) == 1
        assert rom.predict([2]) == 5
        assert rom.predict([3]) == 3
Esempio n. 23
0
 def test_load2(self):
     fname = 'ezyrb2.tmp'
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
     rom.fit()
     rom.save(fname, save_db=False)
     new_rom = ROM.load(fname)
     new_param = [-0.293344, -0.23120537]
     np.testing.assert_array_almost_equal(
         rom.predict(new_param),
         new_rom.predict(new_param)
     )
Esempio n. 24
0
 def test_modes(self):
     a = POD('svd')
     a.reduce(snapshots)
     np.testing.assert_allclose(a.modes, modes)
Esempio n. 25
0
 def test_randomized_svd(self):
     A = POD('randomized_svd').reduce(snapshots)
     assert np.allclose(np.absolute(A),
                        np.absolute(poddb),
                        rtol=1e-03,
                        atol=1e-08)
Esempio n. 26
0
 def test_randomized_svd_old(self):
     pod = POD('randomized_svd', save_memory=False).fit(snapshots)
     snapshots_ = pod.expand(pod.reduce(snapshots))
     np.testing.assert_array_almost_equal(snapshots, snapshots_, decimal=4)
Esempio n. 27
0
 def test_truncation_05(self):
     a = POD(method='randomized_svd', rank=3)
     a.fit(snapshots)
     assert a.singular_values.shape[0] == 3
Esempio n. 28
0
 def test_constructor_empty(self):
     a = POD()
Esempio n. 29
0
 def test_truncation_07(self):
     a = POD(method='svd', rank=0.8)
     a.fit(snapshots)
     assert a.singular_values.shape[0] == 1
Esempio n. 30
0
 def test_truncation_06(self):
     a = POD(method='correlation_matrix', rank=4)
     a.fit(snapshots)
     assert a.singular_values.shape[0] == 4