.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_example/plot_example_MFKPLS.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_MFKPLS.py: Use of Multi-Fidelity Kriging Partial Least Squares --------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: default from smt.applications import MFKPLS,NestedLHS import numpy as np import otsmt import openturns as ot .. GENERATED FROM PYTHON SOURCE LINES 14-15 | Definition of Initial data .. GENERATED FROM PYTHON SOURCE LINES 15-43 .. code-block:: default # Construction of the DOE # low fidelity model def lf_function(x): return ( 0.5 * ((x * 6 - 2) ** 2) * np.sin((x * 6 - 2) * 2) + (x - 0.5) * 10.0 - 5 ) # high fidelity model def hf_function(x): return ((x * 6 - 2) ** 2) * np.sin((x * 6 - 2) * 2) # Problem set up xlimits = np.array([[0.0, 1.0]]) xdoes = NestedLHS(nlevel=2, xlimits=xlimits, random_state=0) xt_c, xt_e = xdoes(7) # Evaluate the HF and LF functions yt_e = hf_function(xt_e) yt_c = lf_function(xt_c) xv_e = ot.Sample([[0.1],[0.5]]) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /usr/share/miniconda3/envs/test/lib/python3.9/site-packages/numpy/lib/function_base.py:2845: RuntimeWarning: Degrees of freedom <= 0 for slice c = cov(x, y, rowvar, dtype=dtype) /usr/share/miniconda3/envs/test/lib/python3.9/site-packages/numpy/lib/function_base.py:2704: RuntimeWarning: divide by zero encountered in divide c *= np.true_divide(1, fact) /usr/share/miniconda3/envs/test/lib/python3.9/site-packages/numpy/lib/function_base.py:2704: RuntimeWarning: invalid value encountered in multiply c *= np.true_divide(1, fact) .. GENERATED FROM PYTHON SOURCE LINES 44-45 | Training of smt model for MFKPLS .. GENERATED FROM PYTHON SOURCE LINES 45-57 .. code-block:: default ncomp = 1 sm_mfkpls = MFKPLS(n_comp=ncomp, theta0=ncomp * [1.0]) # low-fidelity dataset names being integers from 0 to level-1 sm_mfkpls.set_training_values(xt_c, yt_c, name=0) # high-fidelity dataset without name sm_mfkpls.set_training_values(xt_e, yt_e) # train the model sm_mfkpls.train() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ___________________________________________________________________________ MFKPLS ___________________________________________________________________________ Problem size # training points. : 7 ___________________________________________________________________________ Training Training ... Training - done. Time (sec): 0.0541923 .. GENERATED FROM PYTHON SOURCE LINES 58-59 | Creation of OpenTurns PythonFunction for prediction .. GENERATED FROM PYTHON SOURCE LINES 59-68 .. code-block:: default otmfkpls = otsmt.smt2ot(sm_mfkpls) otmfkplsprediction = otmfkpls.getPredictionFunction() otmfkplspvariances = otmfkpls.getConditionalVarianceFunction() otmfkplsgradient= otmfkpls.getPredictionDerivativesFunction() print('Predicted values by MFKPLS:',otmfkplsprediction(xv_e)) print('Predicted variances values by MFKPLS:',otmfkplspvariances(xv_e)) print('Prediction derivatives by MFKPLS:',otmfkplsgradient(xv_e)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ___________________________________________________________________________ Evaluation # eval points. : 2 Predicting ... Predicting - done. Time (sec): 0.0003593 Prediction time/pt. (sec) : 0.0001796 Predicted values by MFKPLS: [ y0 ] 0 : [ -0.656621 ] 1 : [ 0.909277 ] Predicted variances values by MFKPLS: [ y0 ] 0 : [ 2.70638e-08 ] 1 : [ 1.99051e-09 ] ___________________________________________________________________________ Evaluation # eval points. : 2 Predicting ... Predicting - done. Time (sec): 0.0003285 Prediction time/pt. (sec) : 0.0001643 Prediction derivatives by MFKPLS: [ y0 ] 0 : [ -16.5312 ] 1 : [ 5.91771 ] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.115 seconds) .. _sphx_glr_download_auto_example_plot_example_MFKPLS.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_MFKPLS.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_example_MFKPLS.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_