.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_calibration/least_squares_and_gaussian_calibration/plot_calibration_deflection_tube.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_calibration_least_squares_and_gaussian_calibration_plot_calibration_deflection_tube.py: Calibration of the deflection of a tube ======================================= .. GENERATED FROM PYTHON SOURCE LINES 6-9 We calibrate the deflection of a tube as described :ref:`here `. More precisely, we calibrate the mechanical parameters of a model which computes the vertical deflection of a tube and two deflection angles. This example shows how to calibrate a computer code which has several outputs. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: default from openturns.usecases import deflection_tube import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 19-21 Create a calibration problem ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 23-24 We load the model from the use case module : .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: default dt = deflection_tube.DeflectionTube() .. GENERATED FROM PYTHON SOURCE LINES 27-28 We create a sample out of our input distribution : .. GENERATED FROM PYTHON SOURCE LINES 28-32 .. code-block:: default sampleSize = 100 inputSample = dt.inputDistribution.getSample(sampleSize) inputSample[0:5] .. raw:: html
ForceLengthLocationExternal diameterInternal diameterYoung Modulus
01.0489721.510.80.1201405.5
11.0817291.510.80.1198731.1
20.99551911.510.80.1197684.8
31.0264881.510.80.1198344.6
40.98685831.510.80.1197697.1


.. GENERATED FROM PYTHON SOURCE LINES 33-34 We take the image of our input sample by the model : .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: default outputDeflection = dt.model(inputSample) outputDeflection[0:5] .. raw:: html
DeflectionLeft angleRight angle
0-7.197249e-06-1.43945e-051.799312e-05
1-7.521879e-06-1.504376e-051.88047e-05
2-6.959051e-06-1.39181e-051.739763e-05
3-7.151668e-06-1.430334e-051.787917e-05
4-6.898079e-06-1.379616e-051.72452e-05


.. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: default observationNoiseSigma = [0.1e-6, 0.05e-5, 0.05e-5] observationNoiseCovariance = ot.CovarianceMatrix(3) for i in range(3): observationNoiseCovariance[i, i] = observationNoiseSigma[i]**2 .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. code-block:: default noiseSigma = ot.Normal([0., 0., 0.], observationNoiseCovariance) sampleObservationNoise = noiseSigma.getSample(sampleSize) observedOutput = outputDeflection + sampleObservationNoise observedOutput[0:5] .. raw:: html
DeflectionLeft angleRight angle
0-7.217769e-06-1.512261e-051.82937e-05
1-7.486931e-06-1.500876e-051.885333e-05
2-6.678776e-06-1.283332e-051.780391e-05
3-7.35846e-06-1.402654e-051.791085e-05
4-6.990384e-06-1.370394e-051.742711e-05


.. GENERATED FROM PYTHON SOURCE LINES 50-56 .. code-block:: default observedInput = ot.Sample(sampleSize, 2) observedInput[:, 0] = inputSample[:, 0] # F observedInput[:, 1] = inputSample[:, 5] # E observedInput.setDescription(["Force", "Young Modulus"]) observedInput[0:5] .. raw:: html
ForceYoung Modulus
01.048972201405.5
11.081729198731.1
20.9955191197684.8
31.026488198344.6
40.9868583197697.1


.. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: default fullSample = ot.Sample(sampleSize, 5) fullSample[:, 0:2] = observedInput fullSample[:, 2:5] = observedOutput fullSample.setDescription( ["Force", "Young", "Deflection", "Left Angle", "Right Angle"]) fullSample[0:5] .. raw:: html
ForceYoungDeflectionLeft AngleRight Angle
01.048972201405.5-7.217769e-06-1.512261e-051.82937e-05
11.081729198731.1-7.486931e-06-1.500876e-051.885333e-05
20.9955191197684.8-6.678776e-06-1.283332e-051.780391e-05
31.026488198344.6-7.35846e-06-1.402654e-051.791085e-05
40.9868583197697.1-6.990384e-06-1.370394e-051.742711e-05


.. GENERATED FROM PYTHON SOURCE LINES 65-68 .. code-block:: default graph = ot.VisualTest.DrawPairs(fullSample) view = viewer.View(graph) .. image-sg:: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_001.png :alt: plot calibration deflection tube :srcset: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-71 Setting up the calibration -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 73-80 .. code-block:: default XL = 1.4 # Exact : 1.5 Xa = 1.2 # Exact : 1.0 XD = 0.7 # Exact : 0.8 Xd = 0.2 # Exact : 0.1 thetaPrior = [XL, Xa, XD, Xd] .. GENERATED FROM PYTHON SOURCE LINES 81-92 .. code-block:: default sigmaXL = 0.1 * XL sigmaXa = 0.1 * Xa sigmaXD = 0.1 * XD sigmaXd = 0.1 * Xd parameterCovariance = ot.CovarianceMatrix(4) parameterCovariance[0, 0] = sigmaXL**2 parameterCovariance[1, 1] = sigmaXa**2 parameterCovariance[2, 2] = sigmaXD**2 parameterCovariance[3, 3] = sigmaXd**2 parameterCovariance .. raw:: html

[[ 0.0196 0 0 0 ]
[ 0 0.0144 0 0 ]
[ 0 0 0.0049 0 ]
[ 0 0 0 0.0004 ]]



.. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: default calibratedIndices = [1, 2, 3, 4] calibrationFunction = ot.ParametricFunction( dt.model, calibratedIndices, thetaPrior) .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: default sigmaObservation = [0.2e-6, 0.03e-5, 0.03e-5] # Exact : 0.1e-6 .. GENERATED FROM PYTHON SOURCE LINES 101-106 .. code-block:: default errorCovariance = ot.CovarianceMatrix(3) errorCovariance[0, 0] = sigmaObservation[0]**2 errorCovariance[1, 1] = sigmaObservation[1]**2 errorCovariance[2, 2] = sigmaObservation[2]**2 .. GENERATED FROM PYTHON SOURCE LINES 107-111 .. code-block:: default calibrationFunction.setParameter(thetaPrior) predictedOutput = calibrationFunction(observedInput) predictedOutput[0:5] .. raw:: html
DeflectionLeft angleRight angle
0-3.050547e-06-1.016849e-051.65238e-05
1-3.188141e-06-1.062714e-051.72691e-05
2-2.949587e-06-9.831957e-061.597693e-05
3-3.031228e-06-1.010409e-051.641915e-05
4-2.923744e-06-9.745814e-061.583695e-05


.. GENERATED FROM PYTHON SOURCE LINES 112-114 Calibration with gaussian non linear least squares -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 116-119 .. code-block:: default algo = ot.GaussianNonLinearCalibration( calibrationFunction, observedInput, observedOutput, thetaPrior, parameterCovariance, errorCovariance) .. GENERATED FROM PYTHON SOURCE LINES 120-122 .. code-block:: default algo.run() .. GENERATED FROM PYTHON SOURCE LINES 123-125 .. code-block:: default calibrationResult = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 126-128 Analysis of the results ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 130-133 .. code-block:: default thetaMAP = calibrationResult.getParameterMAP() thetaMAP .. raw:: html

[1.50832,1.01261,0.801327,0.199875]



.. GENERATED FROM PYTHON SOURCE LINES 134-135 Compute a 95% confidence interval for each marginal. .. GENERATED FROM PYTHON SOURCE LINES 137-143 .. code-block:: default thetaPosterior = calibrationResult.getParameterPosterior() alpha = 0.95 dim = thetaPosterior.getDimension() for i in range(dim): print(thetaPosterior.getMarginal(i).computeBilateralConfidenceInterval(alpha)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [1.48921, 1.52789] [0.990035, 1.03407] [0.797322, 0.80576] [0.19985, 0.199926] .. GENERATED FROM PYTHON SOURCE LINES 144-147 .. code-block:: default graph = calibrationResult.drawObservationsVsInputs() view = viewer.View(graph) .. image-sg:: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_002.png :alt: plot calibration deflection tube :srcset: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 148-151 .. code-block:: default graph = calibrationResult.drawObservationsVsPredictions() view = viewer.View(graph) .. image-sg:: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_003.png :alt: plot calibration deflection tube :srcset: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 152-155 .. code-block:: default graph = calibrationResult.drawResiduals() view = viewer.View(graph) .. image-sg:: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_004.png :alt: , Residual analysis, Residual analysis, Residual analysis :srcset: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 156-160 .. code-block:: default graph = calibrationResult.drawParameterDistributions() view = viewer.View(graph) plt.show() .. image-sg:: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_005.png :alt: plot calibration deflection tube :srcset: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_calibration_deflection_tube_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.204 seconds) .. _sphx_glr_download_auto_calibration_least_squares_and_gaussian_calibration_plot_calibration_deflection_tube.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_calibration_deflection_tube.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_calibration_deflection_tube.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_