.. 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_meta_modeling_kriging_metamodel_plot_kriging_cantilever_beam.py: Kriging the cantilever beam model ================================= In this example, we create a kriging metamodel of the :ref:`cantilever beam `. We use a squared exponential covariance model for the kriging. In order to estimate the hyper-parameters, we use a design of experiments which size is 20. Definition of the model ----------------------- .. code-block:: default import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) We load the cantilever beam use case : .. code-block:: default from openturns.usecases import cantilever_beam as cantilever_beam cb = cantilever_beam.CantileverBeam() We define the function which evaluates the output depending on the inputs. .. code-block:: default model = cb.model Then we define the distribution of the input random vector. .. code-block:: default dim = cb.dim # number of inputs myDistribution = cb.distribution We use a transformation because data contain very large values. .. code-block:: default transformation = myDistribution.getIsoProbabilisticTransformation() Create the design of experiments -------------------------------- We consider a simple Monte-Carlo sampling as a design of experiments. This is why we generate an input sample using the `getSample` method of the distribution. Then we evaluate the output using the `model` function. .. code-block:: default sampleSize_train = 20 X_train = myDistribution.getSample(sampleSize_train) Y_train = model(X_train) The following figure presents the distribution of the vertical deviations Y on the training sample. We observe that the large deviations occur less often. .. code-block:: default histo = ot.HistogramFactory().build(Y_train).drawPDF() histo.setXTitle("Vertical deviation (cm)") histo.setTitle("Distribution of the vertical deviation") histo.setLegends([""]) view = viewer.View(histo) .. image:: /auto_meta_modeling/kriging_metamodel/images/sphx_glr_plot_kriging_cantilever_beam_001.png :alt: Distribution of the vertical deviation :class: sphx-glr-single-img Create the metamodel -------------------- In order to create the kriging metamodel, we first select a constant trend with the `ConstantBasisFactory` class. Then we use a squared exponential covariance model. Finally, we use the `KrigingAlgorithm` class to create the kriging metamodel, taking the training sample, the covariance model and the trend basis as input arguments. .. code-block:: default dimension = myDistribution.getDimension() basis = ot.ConstantBasisFactory(dimension).build() covarianceModel = ot.SquaredExponential([1.]*dimension, [1.0]) algo = ot.KrigingAlgorithm(transformation(X_train), Y_train, covarianceModel, basis) algo.run() result = algo.getResult() krigingMetamodel = result.getMetaModel() The `run` method has optimized the hyperparameters of the metamodel. We can then print the constant trend of the metamodel, which have been estimated using the least squares method. .. code-block:: default result.getTrendCoefficients() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [class=Point name=Unnamed dimension=1 values=[0.166863]] We can also print the hyperparameters of the covariance model, which have been estimated by maximizing the likelihood. .. code-block:: default result.getCovarianceModel() .. raw:: html

SquaredExponential(scale=[5.25598,4.89996,4.56237,7.84169], amplitude=[0.0394524])