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
|
"""
Create a deterministic design of experiments
============================================
"""
# %%
import openturns as ot
import openturns.viewer as otv
# %%
# Four types of deterministic designs of experiments are available:
#
# - :class:`~openturns.Axial`
# - :class:`~openturns.Factorial`
# - :class:`~openturns.Composite`
# - :class:`~openturns.Box`
#
# Each type of deterministic design is discretized differently according to a number of levels.
#
# Functionally speaking, a design is a :class:`~openturns.Sample` that lies within the unit cube :math:`(0,1)^d` and can be scaled and moved to cover the desired box.
# %%
# We will use the following function to plot bi-dimensional samples.
# %%
def drawBidimensionalSample(sample, title):
n = sample.getSize()
graph = ot.Graph("%s, size=%d" % (title, n), r"$X_1$", r"$X_2$", True, "")
# cloud = ot.Cloud(sample)
cloud = ot.Cloud(sample, "blue", "fsquare", "")
graph.add(cloud)
return graph
# %%
# Axial design
# ------------
# %%
levels = [1.0, 1.5, 3.0]
experiment = ot.Axial(2, levels)
sample = experiment.generate()
graph = drawBidimensionalSample(sample, "Axial")
view = otv.View(graph)
# %%
# Use \*= to rescale and += to move a design.
# Pay attention to the grid in the next graph.
# %%
sample *= 2.0
sample += [5.0, 8.0]
graph = drawBidimensionalSample(sample, "Axial")
view = otv.View(graph)
# %%
# Factorial design
# ----------------
#
# %%
experiment = ot.Factorial(2, levels)
sample = experiment.generate()
sample *= 2.0
sample += [5.0, 8.0]
graph = drawBidimensionalSample(sample, "Factorial")
view = otv.View(graph)
# %%
# Composite design
# ----------------
#
# A composite design is a stratified design of experiments enabling to create a pattern as the union of an Axial pattern and a Factorial one.
# The number of points generated is :math:`1 + n_{\mathrm{level}}(2n+2^n)`.
#
# %%
experiment = ot.Composite(2, levels)
sample = experiment.generate()
sample *= 2.0
sample += [5.0, 8.0]
graph = drawBidimensionalSample(sample, "Composite")
view = otv.View(graph)
# %%
# Grid design
# -----------
#
# %%
levels = [3, 4]
experiment = ot.Box(levels)
sample = experiment.generate()
sample *= 2.0
sample += [5.0, 8.0]
graph = drawBidimensionalSample(sample, "Box")
view = otv.View(graph)
# %%
# Display all graphs
otv.View.ShowAll()
|