def iDW(xt, yt, xtest, ytest): ########### The IDW model t = IDW(print_prediction=False) t.set_training_values(xt, yt) t.train() # Prediction of the validation points y = t.predict_values(xtest) print('IDW, err: ' + str(compute_rms_error(t, xtest, ytest))) title = 'IDW' return t, title, xtest, ytest
def test_idw(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import IDW 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 = IDW(p=2) 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_idw(self): import numpy as np import matplotlib.pyplot as plt from smt.surrogate_models import IDW xt = np.array([0., 1., 2., 3., 4.]) yt = np.array([0., 1., 1.5, 0.5, 1.0]) sm = IDW(p=2) 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()