def test_ny(self): xt, yt, _ = get_rans_crm_wing() interp = QP() interp.set_training_values(xt, yt) interp.train() v0 = np.zeros((4, 2)) for ix, i in enumerate([10, 11, 12, 13]): v0[ix, :] = interp.predict_values(np.atleast_2d(xt[i, :])) v1 = interp.predict_values(np.atleast_2d(xt[10:14, :])) expected_diff = np.zeros((4, 2)) np.testing.assert_allclose(v1 - v0, expected_diff, atol=1e-15)
def test_qp(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import QP xt = np.array([[0.0, 1.0, 2.0, 3.0, 4.0]]).T yt = np.array([[0.2, 1.4, 1.5, 0.5, 1.0], [0.0, 1.0, 2.0, 4, 3]]).T sm = QP() sm.set_training_values(xt, yt) sm.train() num = 100 x = np.linspace(0.0, 4.0, num) y = sm.predict_values(x) t1, _ = plt.plot(xt, yt[:, 0], "o", "C0") p1 = plt.plot(x, y[:, 0], "C0", label="Prediction 1") t2, _ = plt.plot(xt, yt[:, 1], "o", "C1") p2 = plt.plot(x, y[:, 1], "C1", label="Prediction 2") plt.xlabel("x") plt.ylabel("y") plt.legend() plt.show()
class SS_model_QP(SS_model_base): def __init__(self, data, x_headers, y_header): super().__init__(data, x_headers, y_header) self.model = QP(print_training=False, print_global=False) def get_hyperparameters(self): return "quadratic model" def fit(self): self.model.set_training_values(self.X_train, self.y_train) self.model.train() def model_predict(self): X = np.array(self.X_pred) self.y_pred = self.model.predict_values(X) self.y_std = None
def test_qp(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import QP xt = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) yt = np.array([0.0, 1.0, 1.5, 0.5, 1.0]) sm = QP() sm.set_training_values(xt, yt) sm.train() num = 100 x = np.linspace(0.0, 4.0, num) y = sm.predict_values(x) plt.plot(xt, yt, "o") plt.plot(x, y) plt.xlabel("x") plt.ylabel("y") plt.legend(["Training data", "Prediction"]) plt.show()
def test_qp(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import QP xt = np.array([0., 1., 2., 3., 4.]) yt = np.array([0., 1., 1.5, 0.5, 1.0]) sm = QP() sm.set_training_values(xt, yt) sm.train() num = 100 x = np.linspace(0., 4., num) y = sm.predict_values(x) plt.plot(xt, yt, 'o') plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.legend(['Training data', 'Prediction']) plt.show()