Use of KPLSKΒΆ

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

Out:

___________________________________________________________________________

                                   KPLSK
___________________________________________________________________________

 Problem size

      # training points.        : 40

___________________________________________________________________________

 Training

   Training ...
   Training - done. Time (sec):  0.0953236
Creation of OpenTurns PythonFunction for prediction
otkplsk = otsmt.smt2ot(sm_kplsk)
otkplskprediction = otkplsk.getPredictionFunction()
otkplskvariances = otkplsk.getConditionalVarianceFunction()
otkplskgradient = otkplsk.getPredictionDerivativesFunction()

print('Predicted values by KPLSK:',otkplskprediction(xv))
print('Predicted variances values by KPLSK:',otkplskvariances(xv))
print('Prediction derivatives derivatives by KPLSK:',otkplskgradient(xv))

Out:

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0001112

Predicted values by KPLSK:     [ y0      ]
0 : [ 1.01022 ]
1 : [ 5.00008 ]
Predicted variances values by KPLSK:     [ y0          ]
0 : [ 5.85532e-08 ]
1 : [ 5.94511e-08 ]
___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0000869

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0000666

Prediction derivatives derivatives by KPLSK:     [ y0      y1      ]
0 : [ 0.19995 1.99993 ]
1 : [ 1.99992 3.9999  ]

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

Gallery generated by Sphinx-Gallery