Create a custom covariance modelΒΆ

In this basic example we are going to build a custom covariance model from elementary covariance matrices.

In [5]:
from __future__ import print_function
import openturns as ot
import math as m
In [6]:
# Create the covariance function at (s,t):
def C(s, t):
    return m.exp( -4.0 * abs(s - t) / (1 + (s * s + t * t)))

In [7]:
# Create the time grid:
N = 32
a = 4.0
myMesh = ot.IntervalMesher([N]).build(ot.Interval(-a, a))
In [8]:
# Create the collection of elementary covariance matrices
myCovarianceCollection = ot.CovarianceMatrixCollection()
for k in range(myMesh.getVerticesNumber()):
    t = myMesh.getVertices()[k]
    for l in range(k + 1):
        s = myMesh.getVertices()[l]
        matrix = ot.CovarianceMatrix(1)
        matrix[0, 0] = C(s[0], t[0])
        myCovarianceCollection.add(matrix)
In [9]:
# Create the covariance model
myCovarianceModel = ot.UserDefinedCovarianceModel(myMesh, myCovarianceCollection)