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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#! /usr/bin/env python
import openturns as ot
import persalys
import os
anOTStudy = persalys.Study("anOTStudy")
# Model
X0 = persalys.Input("X0", 1, ot.Normal())
X1 = persalys.Input("X1", 2, ot.Normal())
Y0 = persalys.Output("Y0")
model = persalys.SymbolicPhysicalModel("aModelPhys", [X0, X1], [Y0], ["sin(X0)+8*X1"])
anOTStudy.add(model)
# Design of Experiment ##
aDesign = persalys.GridDesignOfExperiment("aDesign_1", model, [[0.9, 1.1], [1.8, 2.2]])
anOTStudy.add(aDesign)
aDesign.run()
print("outs=", aDesign.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment ##
filename = "normal.csv"
ot.Normal(3).getSample(10).exportToCSVFile(filename)
aDesign2 = persalys.ImportedDesignOfExperiment("aDesign_2", model, filename, [0, 2])
anOTStudy.add(aDesign2)
aDesign2.run()
print("outs=", aDesign2.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment - imported - already evaluated##
aDesign2_1 = persalys.ImportedDesignOfExperiment(
"aDesign_2_1", model, filename, [0, 2], [1]
)
anOTStudy.add(aDesign2_1)
# Considered already evaluated, do not run it
# aDesign2_1.run()
print("outs=", aDesign2_1.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment ##
aDesign3 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_3", model, 10, "QUASI_MONTE_CARLO"
)
anOTStudy.add(aDesign3)
aDesign3.run()
print("outs=", aDesign3.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment ##
aDesign4 = persalys.FixedDesignOfExperiment("aDesign_4", model)
inputSample = ot.LHSExperiment(model.getDistribution(), 10).generate()
# inputSample.stack(ot.Sample(10, [0.5, 1.3]))
aDesign4.setOriginalInputSample(inputSample)
anOTStudy.add(aDesign4)
aDesign4.run()
print("outs=", aDesign4.getResult().getDesignOfExperiment().getOutputSample())
# 3D Model to test Space filling algos
X0 = persalys.Input("X0", 1, ot.Normal())
X1 = persalys.Input("X1", 2, ot.Normal())
X2 = persalys.Input("X2", 3, ot.Normal())
Y0 = persalys.Output("Y0")
model = persalys.SymbolicPhysicalModel(
"aModelPhys", [X0, X1, X2], [Y0], ["sin(X0)+8*X1*X2"]
)
anOTStudy2 = persalys.Study("anOTStudy2")
anOTStudy2.add(model)
# Design of Experiment SALHS-PhiP#
aDesign5 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_5", model, 10, "SALHS", "PhiP"
)
anOTStudy2.add(aDesign5)
aDesign5.run()
print("outs=", aDesign5.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment SALHS-minDist#
aDesign6 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_6", model, 10, "SALHS", "minDist"
)
aDesign6.run()
print("outs=", aDesign6.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment SALHS-C2#
aDesign7 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_7", model, 10, "SALHS", "C2", 1000
)
anOTStudy2.add(aDesign7)
aDesign7.run()
print("outs=", aDesign7.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment MCLHS-PhiP#
aDesign8 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_8", model, 10, "MCLHS", "PhiP", 1000
)
anOTStudy2.add(aDesign8)
aDesign8.run()
print("outs=", aDesign8.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment MCLHS-minDist#
aDesign9 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_9", model, 10, "MCLHS", "minDist", 1000
)
anOTStudy2.add(aDesign9)
aDesign9.run()
print("outs=", aDesign9.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment MCLHS-C2#
aDesign10 = persalys.ProbabilisticDesignOfExperiment(
"aDesign_10", model, 10, "MCLHS", "C2", 1000
)
anOTStudy2.add(aDesign10)
aDesign10.run()
print("outs=", aDesign10.getResult().getDesignOfExperiment().getOutputSample())
# Design of Experiment with failed points ##
code = "import time\ndef _exec(X0,X1):\n Y0 = 1/(X0+X1)\n return Y0\n"
model2 = persalys.PythonPhysicalModel("aModelPhys2", [X0, X1], [Y0], code)
model2.setProcessNumber(1)
anOTStudy.add(model2)
aDesign11 = persalys.GridDesignOfExperiment(
"aDesign_11", model2, [[-3, 0, 3], [-3, 0, 3]]
)
anOTStudy.add(aDesign11)
aDesign11.run()
for err_msg in aDesign11.getErrorDescription():
assert "ZeroDivisionError" in err_msg
model2.setParallel(False)
aDesign12 = persalys.GridDesignOfExperiment(
"aDesign_12", model2, [[-3, 0, 3], [-3, 0, 3]]
)
anOTStudy.add(aDesign12)
aDesign12.run()
for err_msg in aDesign11.getErrorDescription():
assert "ZeroDivisionError" in err_msg
# script
script = anOTStudy.getPythonScript()
print(script)
exec(script)
script = anOTStudy2.getPythonScript()
print(script)
exec(script)
os.remove(filename)
|