Use of KrigingΒΆ

from smt.sampling_methods import LHS
from smt.problems import Sphere
from smt.surrogate_models import KRG
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 Kriging
sm_krg = KRG(theta0=[1e-2])
sm_krg.set_training_values(xt, yt[:,0])
sm_krg.train()

Out:

___________________________________________________________________________

                                  Kriging
___________________________________________________________________________

 Problem size

      # training points.        : 40

___________________________________________________________________________

 Training

   Training ...
   Training - done. Time (sec):  0.0650356
Creation of OpenTurns PythonFunction for prediction
otkrg =  otsmt.smt2ot(sm_krg)
otkrgprediction = otkrg.getPredictionFunction()
otkrgvariances = otkrg.getConditionalVarianceFunction()
otkrggradient = otkrg.getPredictionDerivativesFunction()

print('Predicted values by KRG:',otkrgprediction(xv))
print('Predicted variances values by KRG:',otkrgvariances(xv))
print('Prediction derivatives by KRG:',otkrggradient(xv))

Out:

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0001121

Predicted values by KRG:     [ y0      ]
0 : [ 1.01007 ]
1 : [ 4.99998 ]
Predicted variances values by KRG:     [ y0          ]
0 : [ 5.52789e-08 ]
1 : [ 9.28631e-08 ]
___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0000851

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0000689

Prediction derivatives by KRG:     [ y0       y1       ]
0 : [ 0.199996 1.99994  ]
1 : [ 1.99997  3.99991  ]

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

Gallery generated by Sphinx-Gallery