def gEKPLS(xt, yt, xtest, ytest, funXLimits, ndim):
    # 'n_comp' must be an integer in [1,ndim[,  'theta0' a list of n_comp values

    t = GEKPLS(n_comp=2,
               theta0=[1e-2, 1e-2],
               xlimits=funXLimits,
               delta_x=1e-2,
               extra_points=1,
               print_prediction=False)
    t.set_training_values(xt, yt)
    # Add the gradient information
    for i in range(ndim):
        t.set_training_derivatives(xt, yt[:, 1 + i].reshape((yt.shape[0], 1)),
                                   i)
    t.train()

    # Prediction of the validation points
    y = t.predict_values(xtest)
    print('GEKPLS1,  err: ' + str(compute_rms_error(t, xtest, ytest)))
    title = ('GEKPLS model')
    return t, title, xtest, ytest

    # Prediction of the derivatives with regards to each direction space
    yd_prediction = np.zeros((ntest, ndim))
    for i in range(ndim):
        yd_prediction[:, i] = t.predict_derivatives(xtest, kx=i).T
        print('GEKPLS1, err of the ' + str(i + 1) + '-th derivative: ' +
              str(compute_rms_error(t, xtest, ydtest[:, i], kx=i)))

        if plot_status:
            plt.plot(ydtest[:, i], ydtest[:, i], '-.')
            plt.plot(ydtest[:, i], yd_prediction[:, i], '.')

        if plot_status:
            plt.show()
Exemplo n.º 2
0
    def train(self, X_train, y_train):
        if self.flavour == 'plain':
            self.smt_model = KRG(poly=self.poly,
                                 corr=self.corr,
                                 theta0=self.theta0)
        elif self.flavour == 'pls':
            self.smt_model = KPLS(poly=self.poly,
                                  corr=self.corr,
                                  theta0=self.theta0,
                                  n_comp=self.n_comp)
        elif self.flavour == 'plsk':
            self.smt_model = KPLSK(poly=self.poly,
                                   corr=self.corr,
                                   theta0=self.theta0,
                                   n_comp=self.n_comp)
        elif self.flavour == 'gepls':
            self.smt_model = GEKPLS(poly=self.poly,
                                    corr=self.corr,
                                    theta0=self.theta0,
                                    n_comp=self.n_comp,
                                    xlimits=self.xlimits,
                                    delta_x=self.delta_x,
                                    extra_points=self.extra_points)

        super(KrigingModel, self).train(X_train, y_train)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def test_gekpls(self):
        import numpy as np
        from mpl_toolkits.mplot3d import Axes3D
        import matplotlib.pyplot as plt

        from smt.surrogate_models import GEKPLS
        from smt.problems import Sphere
        from smt.sampling_methods import LHS

        # Construction of the DOE
        fun = Sphere(ndim=2)
        sampling = LHS(xlimits=fun.xlimits, criterion="m")
        xt = sampling(20)
        yt = fun(xt)
        # Compute the gradient
        for i in range(2):
            yd = fun(xt, kx=i)
            yt = np.concatenate((yt, yd), axis=1)

        # Build the GEKPLS model
        n_comp = 2
        sm = GEKPLS(
            theta0=[1e-2] * n_comp,
            xlimits=fun.xlimits,
            extra_points=1,
            print_prediction=False,
            n_comp=n_comp,
        )
        sm.set_training_values(xt, yt[:, 0])
        for i in range(2):
            sm.set_training_derivatives(xt, yt[:, 1 + i].reshape((yt.shape[0], 1)), i)
        sm.train()

        # Test the model
        X = np.arange(fun.xlimits[0, 0], fun.xlimits[0, 1], 0.25)
        Y = np.arange(fun.xlimits[1, 0], fun.xlimits[1, 1], 0.25)
        X, Y = np.meshgrid(X, Y)
        Z = np.zeros((X.shape[0], X.shape[1]))

        for i in range(X.shape[0]):
            for j in range(X.shape[1]):
                Z[i, j] = sm.predict_values(
                    np.hstack((X[i, j], Y[i, j])).reshape((1, 2))
                )

        fig = plt.figure()
        ax = fig.gca(projection="3d")
        surf = ax.plot_surface(X, Y, Z)

        plt.show()
def dEKPLS(xt, yt, xtest, ytest, funXLimits, ndim):
    # 'n_comp' must be an integer in [1,ndim[,  'theta0' a list of n_comp values

    t = GEKPLS(n_comp=1,
               theta0=[1e-2],
               xlimits=funXLimits,
               delta_x=1e-2,
               extra_points=1,
               print_prediction=False)
    t.set_training_values(xt, yt)
    # Add the gradient information
    for i in range(ndim):
        t.set_training_derivatives(xt, yt[:, 1 + i].reshape((yt.shape[0], 1)),
                                   i)
    t.train()

    title = 'GEKPLS model'
    return t, title, xtest, ytest
Exemplo n.º 6
0
    def initialize_ego_gek(func="exp", criterion="LCB"):
        from smt.problems import TensorProduct

        class TensorProductIndirect(TensorProduct):
            def __init__(self, **kwargs):
                super().__init__(**kwargs)
                self.super = super()

            def _evaluate(self, x, kx):
                assert kx is None
                response = self.super._evaluate(x, kx)
                sens = np.hstack(
                    self.super._evaluate(x, ki) for ki in range(x.shape[1]))
                return np.hstack((response, sens))

        fun = TensorProductIndirect(ndim=2, func=func)

        # Construction of the DOE
        sampling = LHS(xlimits=fun.xlimits, criterion="m", random_state=42)
        xdoe = sampling(20)
        ydoe = fun(xdoe)

        # Build the GEKPLS surrogate model
        n_comp = 2
        sm = GEKPLS(
            theta0=[1e-2] * n_comp,
            xlimits=fun.xlimits,
            extra_points=1,
            print_prediction=False,
            n_comp=n_comp,
        )

        # Build the EGO optimizer and optimize
        ego = EGO(
            xdoe=xdoe,
            ydoe=ydoe,
            n_iter=5,
            criterion=criterion,
            xlimits=fun.xlimits,
            surrogate=sm,
            n_start=30,
            enable_tunneling=False,
            random_state=42,
        )

        return ego, fun
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
            l = 0
            k += 1
        else:
            l += 1

if plot_status:
    plt.show()

########### The GEKPLS model using 1 approximating points

# 'n_comp' and 'theta0' must be an integer in [1,ndim[ and a list of length n_comp, respectively.

t = GEKPLS(
    n_comp=1,
    theta0=[1e-2],
    xlimits=fun.xlimits,
    delta_x=1e-2,
    extra_points=1,
    print_prediction=False,
)
t.set_training_values(xt, yt[:, 0])
# Add the gradient information
for i in range(ndim):
    t.set_training_derivatives(xt, yt[:, 1 + i].reshape((yt.shape[0], 1)), i)

t.train()

# Prediction of the validation points
y = t.predict_values(xtest)
print("GEKPLS1,  err: " + str(compute_rms_error(t, xtest, ytest)))
if plot_status:
    k, l = 0, 0