.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_meta_modeling/kriging_metamodel/plot_kriging_likelihood.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_meta_modeling_kriging_metamodel_plot_kriging_likelihood.py: Kriging : draw the likelihood ============================= .. GENERATED FROM PYTHON SOURCE LINES 7-12 Abstract -------- In this short example we draw the log-likelihood as a function of the scale parameter of a covariance Kriging model. .. GENERATED FROM PYTHON SOURCE LINES 12-16 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 17-18 We define the exact model with a :class:`~openturns.SymbolicFunction` : .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python f = ot.SymbolicFunction(["x"], ["x*sin(x)"]) .. GENERATED FROM PYTHON SOURCE LINES 21-22 We use the following input and output training samples : .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python inputSample = ot.Sample([[1.0], [3.0], [5.0], [6.0], [7.0], [8.0]]) outputSample = f(inputSample) .. GENERATED FROM PYTHON SOURCE LINES 26-27 We choose a constant basis for the trend of the metamodel : .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python basis = ot.ConstantBasisFactory().build() covarianceModel = ot.SquaredExponential(1) .. GENERATED FROM PYTHON SOURCE LINES 31-32 For the covariance model, we use a Matern model with :math:`\nu = 1.5` : .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python covarianceModel = ot.MaternModel([1.0], 1.5) .. GENERATED FROM PYTHON SOURCE LINES 35-36 We are now ready to build the Kriging algorithm, run it and store the result : .. GENERATED FROM PYTHON SOURCE LINES 36-40 .. code-block:: Python algo = ot.KrigingAlgorithm(inputSample, outputSample, covarianceModel, basis) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 41-43 We can retrieve the covariance model from the result object and then access the scale of the model : .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python theta = result.getCovarianceModel().getScale() print("Scale of the covariance model : %.3e" % theta[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none Scale of the covariance model : 1.978e+00 .. GENERATED FROM PYTHON SOURCE LINES 47-48 This hyperparameter is calibrated thanks to a maximization of the log-likelihood. We get this log-likehood as a function of :math:`\theta` : .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. code-block:: Python ot.ResourceMap.SetAsBool( "GeneralLinearModelAlgorithm-UseAnalyticalAmplitudeEstimate", True ) reducedLogLikelihoodFunction = algo.getReducedLogLikelihoodFunction() .. GENERATED FROM PYTHON SOURCE LINES 54-56 We draw the reduced log-likelihood :math:`\mathcal{L}(\theta)` as a function of the parameter :math:`\theta`. .. GENERATED FROM PYTHON SOURCE LINES 56-61 .. code-block:: Python graph = reducedLogLikelihoodFunction.draw(0.1, 10.0, 100) graph.setXTitle(r"$\theta$") graph.setYTitle(r"$\mathcal{L}(\theta)$") graph.setTitle(r"Log-likelihood as a function of $\theta$") .. GENERATED FROM PYTHON SOURCE LINES 62-63 We represent the estimated parameter as a point on the log-likelihood curve : .. GENERATED FROM PYTHON SOURCE LINES 63-70 .. code-block:: Python L_theta = reducedLogLikelihoodFunction(theta) cloud = ot.Cloud(theta, L_theta) cloud.setColor("red") cloud.setPointStyle("fsquare") graph.add(cloud) graph.setLegends([r"Matern $\nu = 1.5$", r"$\theta$ estimate"]) .. GENERATED FROM PYTHON SOURCE LINES 71-73 We verify on the previous graph that the estimate of :math:`\theta` maximizes the log-likelihood. .. GENERATED FROM PYTHON SOURCE LINES 75-76 Display figures .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: Python view = otv.View(graph) otv.View.ShowAll() .. image-sg:: /auto_meta_modeling/kriging_metamodel/images/sphx_glr_plot_kriging_likelihood_001.png :alt: Log-likelihood as a function of $\theta$ :srcset: /auto_meta_modeling/kriging_metamodel/images/sphx_glr_plot_kriging_likelihood_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-81 Reset default settings .. GENERATED FROM PYTHON SOURCE LINES 81-82 .. code-block:: Python ot.ResourceMap.Reload() .. _sphx_glr_download_auto_meta_modeling_kriging_metamodel_plot_kriging_likelihood.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_kriging_likelihood.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_kriging_likelihood.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_kriging_likelihood.zip `