def test_ls(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import LS 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 = LS() 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_ls(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import LS xt = np.array([0., 1., 2., 3., 4.]) yt = np.array([0., 1., 1.5, 0.5, 1.0]) sm = LS() 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()
ydtest = np.zeros((ntest, ndim)) for i in range(ndim): ydtest[:, i] = fun(xtest, kx=i).T ########### The LS model # Initialization of the model t = LS(print_prediction=False) # Add the DOE t.set_training_values(xt, yt[:, 0]) # Train the model t.train() # Prediction of the validation points y = t.predict_values(xtest) print("LS, err: " + str(compute_rms_error(t, xtest, ytest))) if plot_status: k, l = 0, 0 f, axarr = plt.subplots(4, 3) axarr[k, l].plot(ytest, ytest, "-.") axarr[k, l].plot(ytest, y, ".") l += 1 axarr[3, 2].arrow(0.3, 0.3, 0.2, 0) axarr[3, 2].arrow(0.3, 0.3, 0.0, 0.4) axarr[3, 2].text(0.25, 0.4, r"$\hat{y}$") axarr[3, 2].text(0.35, 0.15, r"$y_{true}$") axarr[3, 2].axis("off") # Fine-tune figure; hide x ticks for top plots and y ticks for right plots plt.setp(axarr[3, 2].get_xticklabels(), visible=False)