File: t_MetaModelAnalysis_py.py

package info (click to toggle)
persalys 19.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 46,900 kB
  • sloc: xml: 97,263; cpp: 61,701; python: 4,109; sh: 397; makefile: 84
file content (63 lines) | stat: -rw-r--r-- 1,925 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python

import openturns as ot
import openturns.testing as ott
import persalys

# ot.Log.Show(ot.Log.DBG)
ot.TBB.Disable()
ot.RandomGenerator.SetSeed(0)
myStudy = persalys.Study("myStudy")

# Model
x1 = persalys.Input("x1", ot.Uniform(0.0, 10.0))
x2 = persalys.Input("x2", ot.Uniform(0.0, 10.0))
x3 = persalys.Input("x3", 0.5)
y00 = persalys.Output("fake_y0")
y00.setIsSelected(False)
y0 = persalys.Output("y0")

formula = ["0.5*x1 + x2+ 28*x3^2"] * 2
model = persalys.SymbolicPhysicalModel("model", [x1, x2, x3], [y00, y0], formula)
myStudy.add(model)

# Design of Experiment
aDesign = persalys.FixedDesignOfExperiment("design", model)
validationInputSample = ot.LHSExperiment(model.getDistribution(), 10).generate()
inputSample = ot.Sample(validationInputSample)
inputSample.stack(ot.Sample(10, [0.5]))
aDesign.setOriginalInputSample(inputSample)
myStudy.add(aDesign)

aDesign.run()

# LM
analysis = persalys.PolynomialRegressionAnalysis("lm_0", aDesign)
analysis.setDegree(2)
analysis.setInteraction(True)
myStudy.add(analysis)

analysis.run()
metaModel = analysis.getResult().getMetaModel().getFunction()

# boston price model
datamodel = persalys.DataModel(
    "datamodel", "Housing-prices-Boston.csv", range(13), [13]
)
myStudy.add(datamodel)
analysis2 = persalys.PolynomialRegressionAnalysis("lm_1", datamodel)
analysis2.setDegree(2)
analysis2.setInteraction(True)
myStudy.add(analysis2)
analysis2.run()
metaModel2 = analysis2.getResult().getMetaModel().getFunction()

# python metamodel
persalys.Study.Add(myStudy)
print("Study instances: ", persalys.Study.GetInstances(), sep='')
pythonMetaModel = analysis.asPythonPhysicalModel(myStudy).getFunction()
ott.assert_almost_equal(pythonMetaModel(validationInputSample), metaModel(validationInputSample))

pythonMetaModel2 = analysis2.asPythonPhysicalModel(myStudy).getFunction()
x = [1.5] * 13
ott.assert_almost_equal(pythonMetaModel2(x), metaModel2(x))