File: StationaryCovarianceModelFactory.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (45 lines) | stat: -rw-r--r-- 1,071 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
37
38
39
40
41
42
43
44
45
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View


N = 512
a = 20.0
# myMesh = ot.IntervalMesher([N]).build(ot.Interval(-a, a))
myMesh = ot.RegularGrid(0.0, 2 * a / N, N + 1)
covarianceModel = ot.ExponentialModel([1.0], [1.0])

myProcess = ot.GaussianProcess(covarianceModel, myMesh)

mySample = myProcess.getSample(1000)

myCovarianceFactory = ot.StationaryCovarianceModelFactory()

myEstimatedModel = myCovarianceFactory.build(mySample)


def f(x):
    res = covarianceModel(x)[0, 0]
    return [res]


func = ot.PythonFunction(1, 1, f)
func.setDescription(["$t$", "$cov$"])


def fEst(X):
    res = myEstimatedModel(X)[0, 0]
    return [res]


funcEst = ot.PythonFunction(1, 1, fEst)
funcEst.setDescription(["$t$", "$cov_{est}$"])


cov_graph = func.draw(-a / 4, a / 4, 1024)
cov_graph.add(funcEst.draw(-a / 4, a / 4, 1024))
cov_graph.setTitle("Stationary covariance model estimation")

fig = plt.figure(figsize=(10, 4))
cov_axis = fig.add_subplot(111)
view = View(cov_graph, figure=fig, axes=[cov_axis], add_legend=False)