File: t_MonteCarloLHS_std.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 (78 lines) | stat: -rwxr-xr-x 2,532 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
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
#! /usr/bin/env python

import openturns as ot

# Defining parameters
dimension = 3
size = 25
# Specify if initial LHS is centered or randomized
centered = True
# Build standard LHS algorithm
distribution = ot.JointDistribution([ot.Uniform(0.0, 1.0)] * dimension)
lhs = ot.LHSExperiment(distribution, size)
lhs.setRandomShift(not centered)  # centered
lhs.setAlwaysShuffle(True)  # randomized

# print the object
print("lhs=", lhs)
print("Bounds of uniform distributions=", distribution.getRange())

# Generate design without optimization
design = lhs.generate()
print("design=", design)

# Defining space fillings
spaceFillingPhiP = ot.SpaceFillingPhiP()
spaceFillingC2 = ot.SpaceFillingC2()
spaceFillingMinDist = ot.SpaceFillingMinDist()

# print the criteria on this design
print(
    "PhiP=%f, C2=%f, MinDist=%f"
    % (
        spaceFillingPhiP.evaluate(design),
        spaceFillingC2.evaluate(design),
        spaceFillingMinDist.evaluate(design),
    )
)

# --------------------------------------------------#
# ------------ MonteCarlo algorithm  ------------- #
# --------------------------------------------------#

# RandomBruteForce MonteCarlo with N designs
N = 1000

# 1) LHS with C2 optimization
optimalLHSAlgorithmC2 = ot.MonteCarloLHS(lhs, N, spaceFillingC2)
# print lhs
print("optimal lhs=", optimalLHSAlgorithmC2)
design = optimalLHSAlgorithmC2.generate()
print("Best design with MonteCarlo and C2 space filling=", design)
resultC2 = optimalLHSAlgorithmC2.getResult()
print(
    "Final criteria: C2=%f, PhiP=%f, MinDist=%f"
    % (resultC2.getC2(), resultC2.getPhiP(), resultC2.getMinDist())
)

# 2) LHS with PhiP optimization
optimalLHSAlgorithmPhiP = ot.MonteCarloLHS(lhs, N, spaceFillingPhiP)
print("optimal lhs=", optimalLHSAlgorithmPhiP)
design = optimalLHSAlgorithmPhiP.generate()
print("Best design with MonteCarlo and PhiP space filling=", design)
resultPhiP = optimalLHSAlgorithmPhiP.getResult()
print(
    "Final criteria: C2=%f, PhiP=%f, MinDist=%f"
    % (resultPhiP.getC2(), resultPhiP.getPhiP(), resultPhiP.getMinDist())
)

# 3) LHS with MinDist optimization
optimalLHSAlgorithmMinDist = ot.MonteCarloLHS(lhs, N, spaceFillingMinDist)
print("optimal lhs=", optimalLHSAlgorithmMinDist)
design = optimalLHSAlgorithmMinDist.generate()
print("Best design with MonteCarlo and MinDist space filling=", design)
resultMinDist = optimalLHSAlgorithmMinDist.getResult()
print(
    "Final criteria: C2=%f, PhiP=%f, MinDist=%f"
    % (resultMinDist.getC2(), resultMinDist.getPhiP(), resultMinDist.getMinDist())
)