.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_surrogate_modeling/fields_surrogate_models/plot_karhunenloeve_validation.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_surrogate_modeling_fields_surrogate_models_plot_karhunenloeve_validation.py: Validation of a Karhunen-Loeve decomposition ============================================ .. GENERATED FROM PYTHON SOURCE LINES 7-9 In this example we are going to assess a Karhunen-Loeve decomposition .. GENERATED FROM PYTHON SOURCE LINES 12-15 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 16-17 Create a Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: Python numberOfVertices = 20 interval = ot.Interval(-1.0, 1.0) mesh = ot.IntervalMesher([numberOfVertices - 1]).build(interval) covariance = ot.SquaredExponential() process = ot.GaussianProcess(covariance, mesh) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Decompose it using KL-SVD. .. GENERATED FROM PYTHON SOURCE LINES 25-32 .. code-block:: Python sampleSize = 100 processSample = process.getSample(sampleSize) threshold = 1.0e-7 algo = ot.KarhunenLoeveSVDAlgorithm(processSample, threshold) algo.run() klresult = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 33-34 Instantiate the validation service. .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python validation = ot.KarhunenLoeveValidation(processSample, klresult) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Plot the residual field. .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python residualProcessSample = validation.computeResidual() view = otv.View(residualProcessSample.drawMarginal(0)) .. image-sg:: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_001.svg :alt: KL residual - 0 marginal :srcset: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 42-43 Plot the residual mean field. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python residualMean = validation.computeResidualMean() view = otv.View(residualMean.drawMarginal(0)) .. image-sg:: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_002.svg :alt: KL residual mean - 0 marginal :srcset: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-48 Plot the residual standard deviation field. .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: Python residualSigmaField = validation.computeResidualStandardDeviation() view = otv.View(residualSigmaField.drawMarginal(0)) .. image-sg:: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_003.svg :alt: KL residual standard deviation - 0 marginal :srcset: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 Build the validation graph. .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python view = otv.View(validation.drawValidation()) .. image-sg:: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_004.svg :alt: Karhunen-Loeve Validation :srcset: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_004.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-57 Build the weight graph. .. GENERATED FROM PYTHON SOURCE LINES 57-59 .. code-block:: Python view = otv.View(validation.drawObservationWeight(0)) .. image-sg:: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_005.svg :alt: Field weight axis 0 :srcset: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_005.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-61 Build the quality graph. .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python view = otv.View(validation.drawObservationQuality()) .. image-sg:: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_006.svg :alt: Field quality :srcset: /auto_surrogate_modeling/fields_surrogate_models/images/sphx_glr_plot_karhunenloeve_validation_006.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-65 Display all figures .. GENERATED FROM PYTHON SOURCE LINES 65-66 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_surrogate_modeling_fields_surrogate_models_plot_karhunenloeve_validation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_karhunenloeve_validation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_karhunenloeve_validation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_karhunenloeve_validation.zip `