Use of Radial Basis FunctionΒΆ

from smt.sampling_methods import LHS
from smt.problems import Sphere
from smt.surrogate_models import RBF
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 Radial Basis Function
sm_rbf = RBF()
sm_rbf.set_training_values(xt, yt[:,0])
sm_rbf.train()

Out:

___________________________________________________________________________

                                    RBF
___________________________________________________________________________

 Problem size

      # training points.        : 40

___________________________________________________________________________

 Training

   Training ...
      Initializing linear solver ...
         Performing LU fact. (40 x 40 mtx) ...
         Performing LU fact. (40 x 40 mtx) - done. Time (sec):  0.0001147
      Initializing linear solver - done. Time (sec):  0.0001836
      Solving linear system (col. 0) ...
         Back solving (40 x 40 mtx) ...
         Back solving (40 x 40 mtx) - done. Time (sec):  0.0000541
      Solving linear system (col. 0) - done. Time (sec):  0.0001123
   Training - done. Time (sec):  0.0006683
Creation of OpenTurns PythonFunction for prediction
otrbf =  otsmt.smt2ot(sm_rbf)
otrbfprediction = otrbf.getPredictionFunction()
print('Predicted values by RBF:',otrbfprediction(xv))

Out:

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0000111

Predicted values by RBF:     [ y0         ]
0 : [ 0.00737942 ]
1 : [ 0.022817   ]

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

Gallery generated by Sphinx-Gallery