{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Create a stationary covariance model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This use case illustrates how the User can create a covariance function from parametric models. The library implements the *multivariate Exponential model* as a parametric model for the covariance function where the spatial covariance function $\\rho$ writes:\n", "\n", "$$\\rho(\\underline{s}, \\underline{t} ) = e^{-\\left\\| \\underline{s}- \\underline{t} \\right\\|_2} \\quad \\forall (\\underline{s}, \\underline{t}) \\in \\mathcal{D}$$\n", "\n", "It is possible to define the exponential model from the spatial covariance matrix $\\underline{\\underline{C}}^{spat}$ rather than the correlation matrix $\\underline{\\underline{R}}$:\n", "\n", "$$\\forall \\underline{t} \\in \\mathcal{D},\\quad \\underline{\\underline{C}}^{spat} = \\mathbb{E} \\left[ X_{\\underline{t}} X^t_{\\underline{t}} \\right] = \\underline{\\underline{A}}\\,\\underline{\\underline{R}}\\, \\underline{\\underline{A}}$$\n", "\n", "with:\n", "$$\\underline{\\underline{A}} = \\mbox{Diag}(a_1, \\dots, a_d)$$\n", "\n", "We call $\\underline{a}$ the amplitude vector and $\\underline{\\lambda}$ the scale vector.\n", "\n", "The library implements the multivariate exponential model thanks to the object *ExponentialModel* which is created from:\n", "\n", "\n", "- the scale and amplitude vectors $(\\underline{\\lambda}, \\underline{a})$: in that case, by default $\\underline{\\underline{R}} = \\underline{\\underline{I}}$;\n", "- the scale and amplitude vectors and the spatial correlation matrix $(\\underline{\\lambda}, \\underline{a},\\underline{\\underline{R}})$;\n", "- the scale and amplitude vectors and the spatial covariance matrix $(\\underline{\\lambda}, \\underline{a},\\underline{\\underline{C}})$; Then $\\underline{\\underline{C}}$ is mapped into the associated correlation matrix $\\underline{\\underline{R}}$ and the previous constructor is used.\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from __future__ import print_function\n", "import openturns as ot\n", "import math as m" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# Create the amplitude vector (output dimension 3)\n", "amplitude = [1.0, 2.0, 3.0]\n", "\n", "# Scale vector (input dimension 1)\n", "scale = [4.0]\n", "\n", "# spatialCorrelation\n", "spatialCorrelation = ot.CorrelationMatrix(3)\n", "spatialCorrelation[0, 1] = 0.8\n", "spatialCorrelation[0, 2] = 0.6\n", "spatialCorrelation[1, 2] = 0.1\n", "\n", "# spatialCovariance\n", "spatialCovariance = ot.CovarianceMatrix(3)\n", "spatialCovariance[0, 0] = 4.0\n", "spatialCovariance[1, 1] = 5.0\n", "spatialCovariance[2, 2] = 6.0\n", "spatialCovariance[0, 1] = 1.2\n", "spatialCovariance[0, 2] = 0.9\n", "spatialCovariance[1, 2] = -0.2" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
ExponentialModel(scale=[4], amplitude=[1,2,3], no spatial correlation)
" ], "text/plain": [ "class=ExponentialModel scale=class=Point name=Unnamed dimension=1 values=[4] amplitude=class=Point name=Unnamed dimension=3 values=[1,2,3] spatial correlation=class=CorrelationMatrix dimension=3 implementation=class=MatrixImplementation name=Unnamed rows=3 columns=3 values=[1,0,0,0,1,0,0,0,1] isDiagonal=true" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create the covariance model from the amplitude and scale, no spatial correlation\n", "ot.ExponentialModel(scale, amplitude)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "ExponentialModel(scale=[4], amplitude=[1,2,3], spatial correlation=
\n",
"[[ 1 0.8 0.6 ]
\n",
" [ 0.8 1 0.1 ]
\n",
" [ 0.6 0.1 1 ]])
ExponentialModel(scale=[4], amplitude=[2,2.23607,2.44949], no spatial correlation)
" ], "text/plain": [ "class=ExponentialModel scale=class=Point name=Unnamed dimension=1 values=[4] amplitude=class=Point name=Unnamed dimension=3 values=[2,2.23607,2.44949] spatial correlation=class=CorrelationMatrix dimension=3 implementation=class=MatrixImplementation name=Unnamed rows=3 columns=3 values=[1,0,0,0,1,0,0,0,1] isDiagonal=true" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# or from the scale and spatialCovariance\n", "ot.ExponentialModel(scale, spatialCovariance)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 1 }