File: UserDefinedStationaryCovarianceModel.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (36 lines) | stat: -rw-r--r-- 890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import openturns as ot
from math import exp
from matplotlib import pyplot as plt
from openturns.viewer import View


def C(tau):
    return 1.0 / (1.0 + tau * tau)

t0 = 0.0
t1 = 20.0
N = 40
dt = (t1 - t0) / (N - 1)
myMesh = ot.RegularGrid(t0, dt, N)

myCovarianceCollection = ot.CovarianceMatrixCollection()
for k in range(N):
    t = myMesh.getValue(k)
    matrix = ot.CovarianceMatrix(1)
    matrix[0, 0] = C(t)
    myCovarianceCollection.add(matrix)

covarianceModel = ot.UserDefinedStationaryCovarianceModel(
    myMesh, myCovarianceCollection)


def f(tau):
    return [covarianceModel(tau)[0, 0]]

func = ot.PythonFunction(1, 1, f)
func.setDescription(['$t$', '$cov$'])
cov_graph = func.draw(0.0, 20.0, 512)
fig = plt.figure(figsize=(10, 4))
plt.suptitle('User defined covariance model')
cov_axis = fig.add_subplot(111)
View(cov_graph, figure=fig, axes=[cov_axis], add_legend=False)