.. 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 6-11 Abstract -------- In this short example we draw the loglikelihood as a function of the scale parameter of a covariance kriging model. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 16-17 We define the exact model with a :class:`~openturns.SymbolicFunction` : .. GENERATED FROM PYTHON SOURCE LINES 17-19 .. code-block:: Python f = ot.SymbolicFunction(["x"], ["x*sin(x)"]) .. GENERATED FROM PYTHON SOURCE LINES 20-21 We use the following input and output training samples : .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. 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 25-26 We choose a constant basis for the trend of the metamodel : .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: Python basis = ot.ConstantBasisFactory().build() covarianceModel = ot.SquaredExponential(1) .. GENERATED FROM PYTHON SOURCE LINES 30-31 For the covariance model, we use a Matern model with :math:`\nu = 1.5` : .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: Python covarianceModel = ot.MaternModel([1.0], 1.5) .. GENERATED FROM PYTHON SOURCE LINES 34-35 We are now ready to build the kriging algorithm, run it and store the result : .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python algo = ot.KrigingAlgorithm(inputSample, outputSample, covarianceModel, basis) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 40-42 We can retrieve the covariance model from the result object and then access the scale of the model : .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. 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 46-47 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 47-52 .. code-block:: Python ot.ResourceMap.SetAsBool( "GeneralLinearModelAlgorithm-UseAnalyticalAmplitudeEstimate", True ) reducedLogLikelihoodFunction = algo.getReducedLogLikelihoodFunction() .. GENERATED FROM PYTHON SOURCE LINES 53-55 We draw the reduced loglikelihood :math:`\mathcal{L}(\theta)` as a function of the parameter :math:`\theta`. .. GENERATED FROM PYTHON SOURCE LINES 55-60 .. 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 61-62 We represent the estimated parameter as a point on the loglikelihood curve : .. GENERATED FROM PYTHON SOURCE LINES 62-69 .. 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 70-72 We verify on the previous graph that the estimate of :math:`\theta` maximizes the loglikelihood. .. GENERATED FROM PYTHON SOURCE LINES 74-75 Display figures .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. 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 79-80 Reset default settings .. GENERATED FROM PYTHON SOURCE LINES 80-81 .. 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 `