Note
Click here to download the full example code
Use of KPLSΒΆ
from smt.sampling_methods import LHS
from smt.problems import Sphere
from smt.surrogate_models import KPLS
import numpy as np
import otsmt
import openturns as ot
Definition of Initial data
Training of smt model for KPLS
sm_kpls = KPLS(theta0=[1e-2])
sm_kpls.set_training_values(xt, yt[:,0])
sm_kpls.train()
Out:
___________________________________________________________________________
KPLS
___________________________________________________________________________
Problem size
# training points. : 40
___________________________________________________________________________
Training
Training ...
Training - done. Time (sec): 0.0312920
Creation of OpenTurns PythonFunction for prediction
otkpls = otsmt.smt2ot(sm_kpls)
otkplsprediction = otkpls.getPredictionFunction()
otkplsvariances = otkpls.getConditionalVarianceFunction()
otkplsgradient= otkpls.getPredictionDerivativesFunction()
print('Predicted values by KPLS:',otkplsprediction(xv))
print('Predicted variances values by KPLS:',otkplsvariances(xv))
print('Prediction derivatives by KPLS:',otkplsgradient(xv))
Out:
___________________________________________________________________________
Evaluation
# eval points. : 2
Predicting ...
Predicting - done. Time (sec): 0.0002170
Prediction time/pt. (sec) : 0.0001085
Predicted values by KPLS: [ y0 ]
0 : [ 1.00844 ]
1 : [ 4.99833 ]
Predicted variances values by KPLS: [ y0 ]
0 : [ 4.57112e-06 ]
1 : [ 4.77084e-06 ]
___________________________________________________________________________
Evaluation
# eval points. : 2
Predicting ...
Predicting - done. Time (sec): 0.0001779
Prediction time/pt. (sec) : 0.0000889
___________________________________________________________________________
Evaluation
# eval points. : 2
Predicting ...
Predicting - done. Time (sec): 0.0001414
Prediction time/pt. (sec) : 0.0000707
Prediction derivatives by KPLS: [ y0 y1 ]
0 : [ 0.199663 1.99999 ]
1 : [ 2.00019 3.99988 ]
Total running time of the script: ( 0 minutes 0.037 seconds)