File: t_GaussianProcessFitter_std_hmat.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 (46 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download | duplicates (2)
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
46
import openturns as ot
from openturns.experimental import GaussianProcessFitter
from openturns.testing import assert_almost_equal

ot.TESTPREAMBLE()

# Set precision
ot.PlatformInfo.SetNumericalPrecision(3)
ot.ResourceMap.Set("GaussianProcessFitter-LinearAlgebra", "HMAT")

sampleSize = 6
inputDimension = 1

# Create the function to estimate
input_description = ["x0"]
formulas = ["x0"]
model = ot.SymbolicFunction(input_description, formulas)

X = ot.Sample(sampleSize, inputDimension)
X2 = ot.Sample(sampleSize, inputDimension)
for i in range(sampleSize):
    X[i, 0] = 3.0 + i
    X2[i, 0] = 2.5 + i
X[0, 0] = 1.0
X[1, 0] = 3.0
X2[0, 0] = 2.0
X2[1, 0] = 4.0
Y = model(X)
# Data validation
Y2 = model(X2)
for i in range(sampleSize):
    # Add a small noise to data
    Y[i, 0] += 0.01 * ot.DistFunc.rNormal()

basis = ot.LinearBasisFactory(inputDimension).build()
covarianceModel = ot.DiracCovarianceModel(inputDimension)
algo = GaussianProcessFitter(X, Y, covarianceModel, basis)
algo.setKeepCholeskyFactor(True)
algo.run()

# perform an evaluation
result = algo.getResult()
metaModel = result.getMetaModel()
conditionalCovariance = result.getCovarianceModel()
residual = metaModel(X) - Y
assert_almost_equal(residual.computeCentralMoment(2), [0.00013144], 1e-5, 1e-5)