Use of Second-order polynomial approximationΒΆ

from smt.sampling_methods import LHS
from smt.problems import Sphere
from smt.surrogate_models import QP
import numpy as np
import otsmt
import openturns as ot
Definition of Initial data
# Construction of the DOE
fun = Sphere(ndim=2)
sampling = LHS(xlimits=fun.xlimits, criterion="m")
xt = sampling(40)
yt = fun(xt)
# Compute the gradient
for i in range(2):
    yd = fun(xt, kx=i)
    yt = np.concatenate((yt, yd), axis=1)

xv = ot.Sample([[0.1,1.],[1.,2.]])
Training of smt model for Second-order polynomial approximation
sm_qp = QP()
sm_qp.set_training_values(xt, yt[:,0])
sm_qp.train()

Out:

___________________________________________________________________________

                                    QP
___________________________________________________________________________

 Problem size

      # training points.        : 40

___________________________________________________________________________

 Training

   Training ...
   Training - done. Time (sec):  0.0003443
Creation of OpenTurns PythonFunction for prediction
otqp =  otsmt.smt2ot(sm_qp)
otqpprediction = otqp.getPredictionFunction()
print('Predicted values by QP:',otqpprediction(xv))

Out:

___________________________________________________________________________

 Evaluation

      # eval points. : 2

   Predicting ...
   Predicting - done. Time (sec):  0.0000496

   Prediction time/pt. (sec) :  0.0000248

Predicted values by QP:     [ y0   ]
0 : [ 1.01 ]
1 : [ 5    ]

Total running time of the script: ( 0 minutes 0.323 seconds)

Gallery generated by Sphinx-Gallery