File: t_GeneralLinearModelAlgorithm_nlopt.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 (41 lines) | stat: -rwxr-xr-x 1,286 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott

ot.TESTPREAMBLE()

# Set precision
ot.PlatformInfo.SetNumericalPrecision(3)

# Calibration of default optimizer
ot.ResourceMap.SetAsScalar(
    "GeneralLinearModelAlgorithm-DefaultOptimizationLowerBound", 1.0e-5
)
ot.ResourceMap.SetAsScalar(
    "GeneralLinearModelAlgorithm-DefaultOptimizationUpperBound", 100
)
# Data & estimation
inputDimension = 1
X = ot.Normal().getSample(100)
X = X.sortAccordingToAComponent(0)
covarianceModel = ot.SquaredExponential([1.0], [1.0])
model = ot.SymbolicFunction(["x"], ["x - 0.6 * cos(x/3)"])
Y = model(X)
basis = ot.QuadraticBasisFactory(inputDimension).build()
algo = ot.GeneralLinearModelAlgorithm(X, Y, covarianceModel, basis, True)
algo.setOptimizationAlgorithm(ot.NLopt("LN_NELDERMEAD"))
algo.run()

# perform an evaluation
result = algo.getResult()
metaModel = result.getMetaModel()
conditionalCovariance = result.getCovarianceModel()
residual = metaModel(X) - Y
ott.assert_almost_equal(residual.computeCentralMoment(2), [1.06e-05], 1e-5, 1e-5)
ott.assert_almost_equal(
    conditionalCovariance.getParameter(), [0.619144, 0.000937], 5e-3, 1e-3
)
likelihood = algo.getObjectiveFunction()
assert likelihood.getInputDimension() == 1, "likelihood dim"
print("ok")