def setUp(self): ndim = 3 nt = 100 ne = 100 ncomp = 1 problems = OrderedDict() problems['exp'] = TensorProduct(ndim=ndim, func='exp') problems['tanh'] = TensorProduct(ndim=ndim, func='tanh') problems['cos'] = TensorProduct(ndim=ndim, func='cos') sms = OrderedDict() sms['LS'] = LS() sms['QP'] = QP() sms['KRG'] = KRG(theta0=[1e-2] * ndim) sms['KPLS'] = KPLS(theta0=[1e-2] * ncomp, n_comp=ncomp) sms['KPLSK'] = KPLSK(theta0=[1] * ncomp, n_comp=ncomp) sms['GEKPLS'] = GEKPLS(theta0=[1e-2] * ncomp, n_comp=ncomp, delta_x=1e-1) if compiled_available: sms['IDW'] = IDW() sms['RBF'] = RBF() sms['RMTC'] = RMTC() sms['RMTB'] = RMTB() t_errors = {} t_errors['LS'] = 1.0 t_errors['QP'] = 1.0 t_errors['KRG'] = 1e-5 t_errors['KPLS'] = 1e-5 t_errors['KPLSK'] = 1e-5 t_errors['GEKPLS'] = 1e-5 if compiled_available: t_errors['IDW'] = 1e-15 t_errors['RBF'] = 1e-2 t_errors['RMTC'] = 1e-1 t_errors['RMTB'] = 1e-1 e_errors = {} e_errors['LS'] = 1.5 e_errors['QP'] = 1.5 e_errors['KRG'] = 1e-2 e_errors['KPLS'] = 1e-2 e_errors['KPLSK'] = 1e-2 e_errors['GEKPLS'] = 1e-2 if compiled_available: e_errors['IDW'] = 1e0 e_errors['RBF'] = 1e0 e_errors['RMTC'] = 2e-1 e_errors['RMTB'] = 2e-1 self.nt = nt self.ne = ne self.ndim = ndim self.problems = problems self.sms = sms self.t_errors = t_errors self.e_errors = e_errors
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 setUp(self): ndim = 2 self.nt = 50 self.ne = 10 self.problem = Sphere(ndim=ndim) self.sms = sms = OrderedDict() if compiled_available: sms['IDW'] = IDW() sms['RBF'] = RBF() sms['RMTB'] = RMTB(regularization_weight=1e-8, nonlinear_maxiter=100, solver_tolerance=1e-16) sms['RMTC'] = RMTC(regularization_weight=1e-8, nonlinear_maxiter=100, solver_tolerance=1e-16)
def setUp(self): ndim = 10 nt = 500 ne = 100 problems = OrderedDict() problems["sphere"] = Sphere(ndim=ndim) problems["exp"] = TensorProduct(ndim=ndim, func="exp") problems["tanh"] = TensorProduct(ndim=ndim, func="tanh") problems["cos"] = TensorProduct(ndim=ndim, func="cos") sms = OrderedDict() sms["LS"] = LS() sms["QP"] = QP() sms["KRG"] = KRG(theta0=[4e-1] * ndim) sms["KPLS"] = KPLS() if compiled_available: sms["IDW"] = IDW() sms["RBF"] = RBF() t_errors = {} t_errors["LS"] = 1.0 t_errors["QP"] = 1.0 t_errors["KRG"] = 1e-4 t_errors["IDW"] = 1e-15 t_errors["RBF"] = 1e-2 t_errors["KPLS"] = 1e-3 e_errors = {} e_errors["LS"] = 2.5 e_errors["QP"] = 2.0 e_errors["KRG"] = 2.0 e_errors["IDW"] = 4 e_errors["RBF"] = 2 e_errors["KPLS"] = 2.5 self.nt = nt self.ne = ne self.problems = problems self.sms = sms self.t_errors = t_errors self.e_errors = e_errors
def setUp(self): ndim = 10 nt = 500 ne = 100 problems = OrderedDict() problems['sphere'] = Sphere(ndim=ndim) problems['exp'] = TensorProduct(ndim=ndim, func='exp') problems['tanh'] = TensorProduct(ndim=ndim, func='tanh') problems['cos'] = TensorProduct(ndim=ndim, func='cos') sms = OrderedDict() sms['LS'] = LS() sms['QP'] = QP() sms['KRG'] = KRG(theta0=[4e-1]*ndim) if compiled_available: sms['IDW'] = IDW() sms['RBF'] = RBF() t_errors = {} t_errors['LS'] = 1.0 t_errors['QP'] = 1.0 t_errors['KRG'] = 1e-6 t_errors['IDW'] = 1e-15 t_errors['RBF'] = 1e-2 e_errors = {} e_errors['LS'] = 2.5 e_errors['QP'] = 2.0 e_errors['KRG'] = 2.0 e_errors['IDW'] = 1.5 e_errors['RBF'] = 1.5 self.nt = nt self.ne = ne self.problems = problems self.sms = sms self.t_errors = t_errors self.e_errors = e_errors
def train(self, train_method, **kwargs): """Trains the surrogate model with given training data. Parameters ---------- train_method : str Training method among ``IDW``, ``KPLS``, ``KPLSK``, ``KRG``, ``LS``, ``QP``, ``RBF``, ``RMTB``, ``RMTC`` kwargs : dict Additional keyword arguments supported by SMT objects """ if train_method == 'IDW': self.trained = IDW(**kwargs) elif train_method == 'KPLS': self.trained = KPLS(**kwargs) elif train_method == 'KPLSK': self.trained = KPLSK(**kwargs) elif train_method == 'KRG': self.trained = KRG(**kwargs) elif train_method == 'LS': self.trained = LS(**kwargs) elif train_method == 'QP': self.trained = QP(**kwargs) elif train_method == 'RBF': self.trained = RBF(**kwargs) elif train_method == 'RMTB': self.trained = RMTB(xlimits=self.limits, **kwargs) elif train_method == 'RMTC': self.trained = RMTC(xlimits=self.limits, **kwargs) else: raise ValueError( 'train_method must be one between IDW, KPLS, KPLSK, KRG, LS, QP, RBF, RMTB, RMTC' ) self.trained.set_training_values(self.x_samp, self.m_prop) self.trained.train()
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()
def setUp(self): ndim = 3 nt = 100 ne = 100 ncomp = 1 problems = OrderedDict() problems["exp"] = TensorProduct(ndim=ndim, func="exp") problems["tanh"] = TensorProduct(ndim=ndim, func="tanh") problems["cos"] = TensorProduct(ndim=ndim, func="cos") sms = OrderedDict() sms["LS"] = LS() sms["QP"] = QP() sms["KRG"] = KRG(theta0=[1e-2] * ndim) sms["MFK"] = MFK(theta0=[1e-2] * ndim) sms["KPLS"] = KPLS(theta0=[1e-2] * ncomp, n_comp=ncomp) sms["KPLSK"] = KPLSK(theta0=[1] * ncomp, n_comp=ncomp) sms["GEKPLS"] = GEKPLS(theta0=[1e-2] * ncomp, n_comp=ncomp, delta_x=1e-1) sms["GENN"] = genn() if compiled_available: sms["IDW"] = IDW() sms["RBF"] = RBF() sms["RMTC"] = RMTC() sms["RMTB"] = RMTB() t_errors = {} t_errors["LS"] = 1.0 t_errors["QP"] = 1.0 t_errors["KRG"] = 1e0 t_errors["MFK"] = 1e0 t_errors["KPLS"] = 1e0 t_errors["KPLSK"] = 1e0 t_errors["GEKPLS"] = 1e0 t_errors["GENN"] = 1e0 if compiled_available: t_errors["IDW"] = 1e0 t_errors["RBF"] = 1e-2 t_errors["RMTC"] = 1e-1 t_errors["RMTB"] = 1e-1 e_errors = {} e_errors["LS"] = 1.5 e_errors["QP"] = 1.5 e_errors["KRG"] = 1e-2 e_errors["MFK"] = 1e-2 e_errors["KPLS"] = 1e-2 e_errors["KPLSK"] = 1e-2 e_errors["GEKPLS"] = 1e-2 e_errors["GENN"] = 1e-2 if compiled_available: e_errors["IDW"] = 1e0 e_errors["RBF"] = 1e0 e_errors["RMTC"] = 2e-1 e_errors["RMTB"] = 2e-1 self.nt = nt self.ne = ne self.ndim = ndim self.problems = problems self.sms = sms self.t_errors = t_errors self.e_errors = e_errors
if plot_status: axarr[k, l].plot(ydtest[:, i], ydtest[:, i], "-.") axarr[k, l].plot(ydtest[:, i], yd_prediction[:, i], ".") if l == 2: l = 0 k += 1 else: l += 1 if plot_status: plt.show() if compiled_available: ########### The IDW model t = IDW(print_prediction=False) t.set_training_values(xt, yt[:, 0]) t.train() # Prediction of the validation points y = t.predict_values(xtest) print("IDW, err: " + str(compute_rms_error(t, xtest, ytest))) if plot_status: plt.figure() plt.plot(ytest, ytest, "-.") plt.plot(ytest, y, ".") plt.xlabel(r"$y_{true}$") plt.ylabel(r"$\hat{y}$") plt.title("Validation of the IDW model") plt.show()
def train(self, X_train, y_train): self.smt_model = IDW(p=self.p) super(IDWModel, self).train(X_train, y_train)