def test_predict_03(self): np.random.seed(1) x, y = get_xy() gpr = GPR() gpr.fit(x, y, optimization_restart=50) test_y = gpr.predict(x) np.testing.assert_array_almost_equal(y, test_y, decimal=6)
def test_optimal_mu(self): x, y = get_xy() gpr = GPR() gpr.fit(x, y, optimization_restart=10) new_mu = gpr.optimal_mu(np.array([[-1, 1], [-1, 1], [-1, 1], [-1, 1]])) np.testing.assert_array_almost_equal(np.abs(new_mu), np.ones(4).reshape(1, -1))
def test_predict_02(self): np.random.seed(42) x, y = get_xy() gpr = GPR() gpr.fit(x, y, optimization_restart=50) test_y, variance = gpr.predict(x[:4], return_variance=True) true_var = np.array([[0.0242762038, 0.0029760019], [0.0244903294, 0.0030022514], [0.0247701249, 0.0030365513], [0.0232064664, 0.0028448636]]) np.testing.assert_array_almost_equal(true_var, variance, decimal=6)
def test_predict_02(self): np.random.seed(42) x, y = get_xy() gpr = GPR() gpr.fit(x, y, optimization_restart=50) test_y, variance = gpr.predict(x[:4], return_variance=True) true_var = np.array([[5.761689e-06, 2.017326e-06], [5.761686e-06, 2.017325e-06], [5.761692e-06, 2.017327e-06], [5.761695e-06, 2.017328e-06]]) np.testing.assert_array_almost_equal(true_var, variance, decimal=6)
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
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)
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
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)
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)
def test_predict_01(self): x, y = get_xy() gpr = GPR() gpr.fit(x, y, optimization_restart=50) test_y, variance = gpr.predict(x, return_variance=True) np.testing.assert_array_almost_equal(y, test_y, decimal=6)
def test_types(self): x, y = get_xy() gpr = GPR() gpr.fit(x[:, 0], y[:, 0]) assert isinstance(gpr.model, sklearn.gaussian_process.GaussianProcessRegressor)
def test_constructor_empty(self): gpr = GPR()
def test_fit(self): x, y = get_xy() gpr = GPR() gpr.fit(x, y) assert isinstance(gpr.model, GPy.models.GPRegression)
def test_fit_mono(self): x, y = get_xy() gpr = GPR() gpr.fit(x[:, 0], y[:, 0]) assert isinstance(gpr.model, GPy.models.GPRegression)
# # Moreover, new state-of-the-art methods will arrive, so we invite you to read the [documentation](https://mathlab.github.io/EZyRB/) for the complete list of all the possibilities! # # In the next cell, we create two dictionaries with the objects, such that we can easily test everything with simple `for` cycles. **WARNING** since several methods require the solution of an optimization problem (eg. GPR, ANN, AE), the cell may require some minutes to be run. # In[9]: reductions = { 'POD': POD('svd', rank=10), 'AE': AE([200, 100, 10], [10, 100, 200], nn.Tanh(), nn.Tanh(), 10), } approximations = { # 'Linear': Linear(), 'RBF': RBF(), 'GPR': GPR(), 'KNeighbors': KNeighborsRegressor(), 'RadiusNeighbors': RadiusNeighborsRegressor(), 'ANN': ANN([20, 20], nn.Tanh(), 10), } header = '{:10s}'.format('') for name in approximations: header += ' {:>15s}'.format(name) print(header) for redname, redclass in reductions.items(): row = '{:10s}'.format(redname) for approxname, approxclass in approximations.items(): rom = ROM(db, redclass, approxclass) rom.fit()