예제 #1
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)
예제 #2
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
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
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)
예제 #11
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)
예제 #12
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)
예제 #13
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)
예제 #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
예제 #15
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)
예제 #16
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)
     )
예제 #17
0
#POD offline
snapshots = np.load('Snapshots/Snapshot75b.npy')
print(f'Total number of columns in snapshot matrix = {len(snapshots[0])}')
limit = int(0.8 * len(snapshots[0]))
snapshots = snapshots[:, 0:limit]
snapshots = np.transpose(snapshots)

param = np.load('Param/Param75b.npy')
param_snap = param[:, 0:limit]
param_snap = np.transpose(param_snap)

db = Database(param_snap, snapshots)
pod = POD('svd')
rbf = RBF()
rom = ROM(db, pod, rbf)
rom.fit()

#POD Online
param_train = np.transpose(param[:, limit:len(param[0])])
Error_array = np.zeros((len(param[0]) - limit, 1))
train_limit = len(param[0]) - limit

for i in range(0, train_limit):
    param_i = param_train[i, :]
    [A, b, TleftBC] = buildadvdefop(param_i[0], param_i[1], param_i[2])
    wcomp = np.linalg.solve(A, b).T.squeeze()
    pred_sol = rom.predict(param_i)
    MSE = np.square(np.subtract(wcomp, pred_sol)).mean()
    RMSE = math.sqrt(MSE)
    Error_array[i, :] = RMSE
예제 #18
0
 def test_constructor(self):
     pod = POD()
     rbf = RBF()
     db = Database(param, snapshots.T)
     rom = ROM(db, pod, rbf)
예제 #19
0
파일: tutorial-2.py 프로젝트: mathLab/EZyRB
                       sharey=True,
                       sharex=True)
ax = ax.flatten()
for i in range(9):
    ax[i].tricontourf(data.triang, data.snapshots['vx'][i], levels=16)
    ax[i].set_title('Original snapshot at inlet velocity = {}'.format(
        *data.params[i].round(2)))

# In this step, we perform the model order reduction to obtain a reduced space from the full order space. We refer to [Tutorial 1](https://github.com/mathLab/EZyRB/blob/master/tutorials/tutorial-1.ipynb) for the description of the basic workflow, here we just quickly describe the steps implemented in the next cell.
#
# We start by passing the matrices of the parameters and snapshots to the `Database()` class. It must be said that at this time we create the ROM for the `vx` field. We also instantiate the `POD` and `RBF` object to have a benchmark ROM.

# In[5]:

db = Database(data.params, data.snapshots['vx'])
rom = ROM(db, POD(), RBF())
rom.fit()

# Three lines for a data-driven reduced order model, not bad!
#
# Just to have a visual check that everything is going well, we plot the approximation for new parameters in the range $[1, 80]$.

# In[6]:

new_params = np.random.uniform(size=(2)) * 79. + 1.

fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(16, 3))
for i, param in enumerate(new_params):
    ax[i].tricontourf(data.triang, rom.predict([param]))
    ax[i].set_title('Predicted snapshots at inlet velocity = {}'.format(param))