.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_example/plot_example_QP.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_example_plot_example_QP.py: Use of Second-order polynomial approximation -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 7-15 .. code-block:: default from smt.sampling_methods import LHS from smt.problems import Sphere from smt.surrogate_models import QP import numpy as np import otsmt import openturns as ot .. GENERATED FROM PYTHON SOURCE LINES 16-17 | Definition of Initial data .. GENERATED FROM PYTHON SOURCE LINES 17-31 .. code-block:: default # 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.]]) .. GENERATED FROM PYTHON SOURCE LINES 32-33 | Training of smt model for Second-order polynomial approximation .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: default sm_qp = QP() sm_qp.set_training_values(xt, yt[:,0]) sm_qp.train() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ___________________________________________________________________________ QP ___________________________________________________________________________ Problem size # training points. : 40 ___________________________________________________________________________ Training Training ... Training - done. Time (sec): 0.0003443 .. GENERATED FROM PYTHON SOURCE LINES 39-40 | Creation of OpenTurns PythonFunction for prediction .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default otqp = otsmt.smt2ot(sm_qp) otqpprediction = otqp.getPredictionFunction() print('Predicted values by QP:',otqpprediction(xv)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ___________________________________________________________________________ Evaluation # eval points. : 2 Predicting ... Predicting - done. Time (sec): 0.0000496 Prediction time/pt. (sec) : 0.0000248 Predicted values by QP: [ y0 ] 0 : [ 1.01 ] 1 : [ 5 ] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.323 seconds) .. _sphx_glr_download_auto_example_plot_example_QP.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_example_QP.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_example_QP.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_