Use of Inverse Distance WeightingΒΆ

from smt.sampling_methods import LHS
from smt.problems import Sphere
from smt.surrogate_models import IDW
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 Inverse Distance Weighting
sm_idw = IDW(p=2)
sm_idw.set_training_values(xt, yt[:,0])
sm_idw.train()

Out:

___________________________________________________________________________

                                    IDW
___________________________________________________________________________

 Problem size

      # training points.        : 40

___________________________________________________________________________

 Training

   Training ...
   Training - done. Time (sec):  0.0001605
Creation of OpenTurns PythonFunction for prediction
otidw =  otsmt.smt2ot(sm_idw)
otidwprediction = otidw.getPredictionFunction()
print('Predicted values by IDW:',otidwprediction(xv))

Out:

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0000129

Predicted values by IDW:     [ y0       ]
0 : [  3.33771 ]
1 : [ 17.8915  ]

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

Gallery generated by Sphinx-Gallery