Use of Regularized minimal-energy tensor-product splinesΒΆ

from smt.sampling_methods import LHS
from smt.problems import Sphere
from smt.surrogate_models import RMTB
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 Regularized minimal-energy tensor-product splines
sm_rmtb = RMTB(
xlimits=fun.xlimits,
order=4,
num_ctrl_pts=20,
energy_weight=1e-15,
regularization_weight=0.0,
)
sm_rmtb.set_training_values(xt, yt[:,0])
sm_rmtb.train()

Out:

___________________________________________________________________________

                                   RMTB
___________________________________________________________________________

 Problem size

      # training points.        : 40

___________________________________________________________________________

 Training

   Training ...
      Pre-computing matrices ...
         Computing dof2coeff ...
         Computing dof2coeff - done. Time (sec):  0.0000026
         Initializing Hessian ...
         Initializing Hessian - done. Time (sec):  0.0003567
         Computing energy terms ...
         Computing energy terms - done. Time (sec):  0.0049579
         Computing approximation terms ...
         Computing approximation terms - done. Time (sec):  0.0003774
      Pre-computing matrices - done. Time (sec):  0.0059688
      Solving for degrees of freedom ...
         Solving initial startup problem (n=400) ...
            Solving for output 0 ...
               Iteration (num., iy, grad. norm, func.) :   0   0 2.498709600e+02 1.157006963e+05
               Iteration (num., iy, grad. norm, func.) :   0   0 1.799842467e-13 7.472411973e-13
            Solving for output 0 - done. Time (sec):  0.0034640
         Solving initial startup problem (n=400) - done. Time (sec):  0.0035534
         Solving nonlinear problem (n=400) ...
            Solving for output 0 ...
               Iteration (num., iy, grad. norm, func.) :   0   0 2.488416993e-15 7.472411973e-13
            Solving for output 0 - done. Time (sec):  0.0002351
         Solving nonlinear problem (n=400) - done. Time (sec):  0.0003109
      Solving for degrees of freedom - done. Time (sec):  0.0039945
   Training - done. Time (sec):  0.0103793
Creation of OpenTurns PythonFunction for prediction
otrmtb =  otsmt.smt2ot(sm_rmtb)
otrmtbprediction = otrmtb.getPredictionFunction()
print('Predicted values by RMTB:',otrmtbprediction(xv))

Out:

___________________________________________________________________________

 Evaluation

      # eval points. : 2

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

   Prediction time/pt. (sec) :  0.0001458

Predicted values by RMTB:     [ y0      ]
0 : [ 1.87176 ]
1 : [ 2.55299 ]

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

Gallery generated by Sphinx-Gallery