Exemplo n.º 1
0
    def setUp(self):
        ndim = 10
        nt = 50
        ne = 100

        problems = OrderedDict()
        problems["Branin"] = Branin(ndim=2)
        problems["Rosenbrock"] = Rosenbrock(ndim=3)
        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["KPLS"] = KPLS(eval_n_comp=True)

        t_errors = {}
        e_errors = {}
        t_errors["KPLS"] = 1e-3
        e_errors["KPLS"] = 2.5

        n_comp_opt = {}
        n_comp_opt["Branin"] = 2
        n_comp_opt["Rosenbrock"] = 1
        n_comp_opt["sphere"] = 1
        n_comp_opt["exp"] = 3
        n_comp_opt["tanh"] = 1
        n_comp_opt["cos"] = 1

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
        self.n_comp_opt = n_comp_opt
Exemplo n.º 2
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.º 3
0
    def test_tensor_product(self):
        import numpy as np
        import matplotlib.pyplot as plt

        from smt.problems import TensorProduct

        ndim = 2
        problem = TensorProduct(ndim=ndim, func='cos')

        num = 100
        x = np.ones((num, ndim))
        x[:, 0] = np.linspace(-1, 1., num)
        x[:, 1] = 0.
        y = problem(x)

        yd = np.empty((num, ndim))
        for i in range(ndim):
            yd[:, i] = problem(x, kx=i).flatten()

        print(y.shape)
        print(yd.shape)

        plt.plot(x[:, 0], y[:, 0])
        plt.xlabel('x')
        plt.ylabel('y')
        plt.show()
Exemplo n.º 4
0
    def test_mfk(self):
        self.problems = ["exp", "tanh", "cos"]

        for fname in self.problems:
            prob = TensorProduct(ndim=self.ndim, func=fname)
            sampling = FullFactorial(xlimits=prob.xlimits, clip=True)

            np.random.seed(0)
            xt = sampling(self.nt)
            yt = prob(xt)
            for i in range(self.ndim):
                yt = np.concatenate((yt, prob(xt, kx=i)), axis=1)

            y_lf = 2 * prob(xt) + 2
            x_lf = deepcopy(xt)
            np.random.seed(1)
            xe = sampling(self.ne)
            ye = prob(xe)

            sm = MFK(theta0=[1e-2] * self.ndim)
            if sm.options.is_declared("xlimits"):
                sm.options["xlimits"] = prob.xlimits
            sm.options["print_global"] = False

            sm.set_training_values(xt, yt[:, 0])
            sm.set_training_values(x_lf, y_lf[:, 0], name=0)

            with Silence():
                sm.train()

            t_error = compute_rms_error(sm)
            e_error = compute_rms_error(sm, xe, ye)

            self.assert_error(t_error, 0.0, 1)
            self.assert_error(e_error, 0.0, 1)
Exemplo n.º 5
0
    def test_mfk_1fidelity(self):
        self.problems = ["exp", "tanh", "cos"]

        for fname in self.problems:
            prob = TensorProduct(ndim=self.ndim, func=fname)
            sampling = LHS(xlimits=prob.xlimits, random_state=0)

            np.random.seed(0)
            xt = sampling(self.nt)
            yt = prob(xt)
            for i in range(self.ndim):
                yt = np.concatenate((yt, prob(xt, kx=i)), axis=1)

            sampling = LHS(xlimits=prob.xlimits, random_state=1)
            xv = sampling(self.ne)
            yv = prob(xv)

            sm = MFK(
                theta0=[1e-2] * self.ndim,
                print_global=False,
            )

            sm.set_training_values(xt, yt[:, 0])

            with Silence():
                sm.train()

            t_error = compute_rms_error(sm)
            e_error = compute_rms_error(sm, xv, yv)

            self.assert_error(t_error, 0.0, 1e-6)
            self.assert_error(e_error, 0.0, 1e-6)
Exemplo n.º 6
0
    def setUp(self):
        ndim = 3
        nt = 500
        ne = 100

        problems = OrderedDict()
        problems['carre'] = Carre(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['PA2'] = PA2()
        sms['KRG'] = KPLS(name='KRG', n_comp=ndim, theta0=[1.0] * ndim)
        if compiled_available:
            sms['IDW'] = IDW()
            sms['RBF'] = RBF()
            sms['RMTS'] = RMTS(num_elements=6)
            sms['RMTB'] = RMTB(order=4, num_ctrl_pts=10)

        t_errors = {}
        t_errors['LS'] = 1.0
        t_errors['PA2'] = 1.0
        t_errors['KRG'] = 1e-6
        t_errors['IDW'] = 1e-15
        t_errors['RBF'] = 1e-2
        t_errors['RMTS'] = 1e-2
        t_errors['RMTB'] = 1e-2

        e_errors = {}
        e_errors['LS'] = 1.5
        e_errors['PA2'] = 1.5
        e_errors['KRG'] = 1e-2
        e_errors['IDW'] = 1e0
        e_errors['RBF'] = 1e0
        e_errors['RMTS'] = 2e-1
        e_errors['RMTB'] = 2e-1

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    def setUp(self):
        ndim = 3
        nt = 2500
        ne = 500

        problems = OrderedDict()
        problems['carre'] = Carre(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()
        if compiled_available:
            sms['RMTS'] = RMTS(num_elements=6)
            sms['RMTB'] = RMTB(order=4, num_ctrl_pts=10)

        t_errors = {}
        t_errors['RMTS'] = 1e-2
        t_errors['RMTB'] = 1e-2

        e_errors = {}
        e_errors['RMTS'] = 1e-1
        e_errors['RMTB'] = 1e-1

        ge_t_errors = {}
        ge_t_errors['RMTS'] = 1e-2
        ge_t_errors['RMTB'] = 1e-2

        ge_e_errors = {}
        ge_e_errors['RMTS'] = 1e-2
        ge_e_errors['RMTB'] = 1e-2

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
        self.ge_t_errors = ge_t_errors
        self.ge_e_errors = ge_e_errors
Exemplo n.º 9
0
    def setUp(self):
        ndim = 3
        nt = 5000
        ne = 500

        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()
        if compiled_available:
            sms["RMTC"] = RMTC()
            sms["RMTB"] = RMTB()

        t_errors = {}
        t_errors["RMTC"] = 1e-1
        t_errors["RMTB"] = 1e-1

        e_errors = {}
        e_errors["RMTC"] = 1e-1
        e_errors["RMTB"] = 1e-1

        ge_t_errors = {}
        ge_t_errors["RMTC"] = 1e-2
        ge_t_errors["RMTB"] = 1e-2

        ge_e_errors = {}
        ge_e_errors["RMTC"] = 1e-2
        ge_e_errors["RMTB"] = 1e-2

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
        self.ge_t_errors = ge_t_errors
        self.ge_e_errors = ge_e_errors
Exemplo n.º 10
0
    def setUp(self):
        ndim = 3
        nt = 5000
        ne = 500

        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()
        if compiled_available:
            sms['RMTC'] = RMTC()
            sms['RMTB'] = RMTB()

        t_errors = {}
        t_errors['RMTC'] = 1e-1
        t_errors['RMTB'] = 1e-1

        e_errors = {}
        e_errors['RMTC'] = 1e-1
        e_errors['RMTB'] = 1e-1

        ge_t_errors = {}
        ge_t_errors['RMTC'] = 1e-2
        ge_t_errors['RMTB'] = 1e-2

        ge_e_errors = {}
        ge_e_errors['RMTC'] = 1e-2
        ge_e_errors['RMTB'] = 1e-2

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
        self.ge_t_errors = ge_t_errors
        self.ge_e_errors = ge_e_errors
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    def setUp(self):
        ndim = 10
        nt = 500
        ne = 100

        problems = OrderedDict()
        problems['carre'] = Carre(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['PA2'] = PA2()
        sms['KRG'] = KPLS(name='KRG', n_comp=ndim, theta0=[40e-2] * ndim)
        if compiled_available:
            sms['IDW'] = IDW()
            sms['RBF'] = RBF()

        t_errors = {}
        t_errors['LS'] = 1.0
        t_errors['PA2'] = 1.0
        t_errors['KRG'] = 1e-6
        t_errors['IDW'] = 1e-15
        t_errors['RBF'] = 1e-2

        e_errors = {}
        e_errors['LS'] = 1.5
        e_errors['PA2'] = 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
Exemplo n.º 13
0
    def setUp(self):
        ndim = 2
        nt = 10000
        ne = 1000

        problems = OrderedDict()
        problems['sphere'] = Sphere(ndim=ndim)
        problems['exp'] = TensorProduct(ndim=ndim, func='exp', width=5)
        problems['tanh'] = TensorProduct(ndim=ndim, func='tanh', width=5)
        problems['cos'] = TensorProduct(ndim=ndim, func='cos', width=5)

        sms = OrderedDict()
        sms['LS'] = LS()
        sms['QP'] = QP()
        if compiled_available:
            sms['RMTC'] = RMTC(num_elements=20, energy_weight=1e-10)
            sms['RMTB'] = RMTB(num_ctrl_pts=40, energy_weight=1e-10)

        t_errors = {}
        t_errors['LS'] = 1.0
        t_errors['QP'] = 1.0
        t_errors['RMTC'] = 1e-2
        t_errors['RMTB'] = 1e-2

        e_errors = {}
        e_errors['LS'] = 1.5
        e_errors['QP'] = 1.5
        e_errors['RMTC'] = 1e-2
        e_errors['RMTB'] = 1e-2

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
Exemplo n.º 14
0
    def setUp(self):
        ndim = 2
        nt = 10000
        ne = 1000

        problems = OrderedDict()
        problems["sphere"] = Sphere(ndim=ndim)
        problems["exp"] = TensorProduct(ndim=ndim, func="exp", width=5)
        problems["tanh"] = TensorProduct(ndim=ndim, func="tanh", width=5)
        problems["cos"] = TensorProduct(ndim=ndim, func="cos", width=5)

        sms = OrderedDict()
        sms["LS"] = LS()
        sms["QP"] = QP()
        if compiled_available:
            sms["RMTC"] = RMTC(num_elements=20, energy_weight=1e-10)
            sms["RMTB"] = RMTB(num_ctrl_pts=40, energy_weight=1e-10)

        t_errors = {}
        t_errors["LS"] = 1.0
        t_errors["QP"] = 1.0
        t_errors["RMTC"] = 1.0
        t_errors["RMTB"] = 1.0

        e_errors = {}
        e_errors["LS"] = 1.5
        e_errors["QP"] = 1.5
        e_errors["RMTC"] = 1.0
        e_errors["RMTB"] = 1.0

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
Exemplo n.º 15
0
    def setUp(self):
        ndim = 2
        nt = 10000
        ne = 1000

        problems = OrderedDict()
        problems['carre'] = Carre(ndim=ndim)
        problems['exp'] = TensorProduct(ndim=ndim, func='exp', width=5)
        problems['tanh'] = TensorProduct(ndim=ndim, func='tanh', width=5)
        problems['cos'] = TensorProduct(ndim=ndim, func='cos', width=5)

        sms = OrderedDict()
        sms['LS'] = LS()
        sms['PA2'] = PA2()
        if compiled_available:
            sms['RMTS'] = RMTS(num_elements=30, nln_max_iter=20)
            sms['RMTB'] = RMTB(order=6, num_ctrl_pts=30, nln_max_iter=20)

        t_errors = {}
        t_errors['LS'] = 1.0
        t_errors['PA2'] = 1.0
        t_errors['RMTS'] = 1e-2
        t_errors['RMTB'] = 1e-2

        e_errors = {}
        e_errors['LS'] = 1.5
        e_errors['PA2'] = 1.5
        e_errors['RMTS'] = 1e-2
        e_errors['RMTB'] = 1e-2

        self.nt = nt
        self.ne = ne
        self.problems = problems
        self.sms = sms
        self.t_errors = t_errors
        self.e_errors = e_errors
Exemplo n.º 16
0
 def test_exp(self):
     self.run_test(TensorProduct(name="TP-exp", ndim=1, func="exp"))
     self.run_test(TensorProduct(name="TP-exp", ndim=3, func="exp"))
Exemplo n.º 17
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.º 18
0
 def test_gaussian(self):
     self.run_test(TensorProduct(name='TP-gaussian', ndim=1, func='gaussian'))
     self.run_test(TensorProduct(name='TP-gaussian', ndim=3, func='gaussian'))
Exemplo n.º 19
0
 def test_cos(self):
     self.run_test(TensorProduct(name='TP-cos', ndim=1, func='cos'))
     self.run_test(TensorProduct(name='TP-cos', ndim=3, func='cos'))
Exemplo n.º 20
0
 def test_tanh(self):
     self.run_test(TensorProduct(name='TP-tanh', ndim=1, func='tanh'))
     self.run_test(TensorProduct(name='TP-tanh', ndim=3, func='tanh'))
Exemplo n.º 21
0
 def test_exp(self):
     self.run_test(TensorProduct(name='TP-exp', ndim=1, func='exp'))
     self.run_test(TensorProduct(name='TP-exp', ndim=3, func='exp'))
Exemplo n.º 22
0
 def test_gaussian(self):
     self.run_test(TensorProduct(name="TP-gaussian", ndim=1, func="gaussian"))
     self.run_test(TensorProduct(name="TP-gaussian", ndim=3, func="gaussian"))
Exemplo n.º 23
0
 def test_cos(self):
     self.run_test(TensorProduct(name="TP-cos", ndim=1, func="cos"))
     self.run_test(TensorProduct(name="TP-cos", ndim=3, func="cos"))
Exemplo n.º 24
0
 def test_tanh(self):
     self.run_test(TensorProduct(name="TP-tanh", ndim=1, func="tanh"))
     self.run_test(TensorProduct(name="TP-tanh", ndim=3, func="tanh"))