Exemplo n.º 1
0
#! /usr/bin/env python

from __future__ import print_function
import openturns as ot

# Defining parameters
dimension = 5
size = 100

# Build OT LHS algorithm
lhs = ot.LHSExperiment(ot.ComposedDistribution([ot.Uniform()] * dimension),
                       size)

# Generate design without optimization
design = lhs.generate()

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

# print the criteria on this design
print("C2=%f MinDist=%f PhiP=%f, PhiP(50)=%f" % tuple([
    sf.evaluate(design) for sf in [
        spaceFillingC2, spaceFillingMinDist, spaceFillingPhiP,
        spaceFillingPhiP50
    ]
]))
Exemplo n.º 2
0
    ot.ComposedDistribution([ot.Uniform(20.0, 30.0)] * dimension), size)
lhsDesign.setRandomShift(False)  # centered
lhsDesign.setAlwaysShuffle(True)  # randomized

# Number of designs to generate
N = 10

# For each design, evaluation of some criteria
fp = open("space_filling_criteria_nonunit.val", "w")
for i in range(N):
    design = lhsDesign.generate()
    filename = "design_dim_%d_size_%d_%d_nonunit.csv" % (dimension, size,
                                                         i + 1)
    design.exportToCSVFile(filename, ";")
    c2 = ot.SpaceFillingC2().evaluate(design)
    phip = ot.SpaceFillingPhiP().evaluate(design)
    mindist = ot.SpaceFillingMinDist().evaluate(design)
    fp.write("design=%s\n" % filename)
    fp.write("c2=%1.13e, phip=%1.13e, mindist=%1.13e\n" % (c2, phip, mindist))

# New test with biggest dimension
dimension = 50

# Size of sample
size = 100
lhsDesign = ot.LHSExperiment(
    ot.ComposedDistribution([ot.Uniform(20.0, 30.0)] * dimension), size)
lhsDesign.setRandomShift(False)  # centered
lhsDesign.setAlwaysShuffle(True)  # randomized

# Number of designs to generate
Exemplo n.º 3
0
lhs = ot.LHSExperiment(distribution, size)
lhs.setRandomShift(False)  # centered
lhs.setAlwaysShuffle(True)  # randomized

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

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

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

# print the criteria on this design
print("PhiP=%f, C2=%f" % (ot.SpaceFillingPhiP().evaluate(design),
                          ot.SpaceFillingC2().evaluate(design)))

# Parameters for drawing design ==> Number of points are for the "grid"
Nx = 50
Ny = 50

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

# RandomBruteForce MonteCarlo with N designs
N = 100
Exemplo n.º 4
0
# Size of sample
size = 20

# Factory: lhs generates
lhsDesign = ot.LHSExperiment(
    ot.ComposedDistribution([ot.Uniform(0.0, 1.0)] * dimension), size)
lhsDesign.setRandomShift(False)  # centered
lhsDesign.setAlwaysShuffle(True)  # randomized

# For each design, evaluation of some criteria
fp = open("space_filling_criteria_perturbation.val", "w")
design = lhsDesign.generate()
filename = "design_dim_2_size_20_centered_perturbLHS.csv"
design.exportToCSVFile(filename, ";")
c2 = ot.SpaceFillingC2().evaluate(design)
phip = ot.SpaceFillingPhiP().evaluate(design)
mindist = ot.SpaceFillingMinDist().evaluate(design)
fp.write("initial design=%s\n" % filename)
fp.write("c2=%1.10e, phip=%1.10e, mindist=%1.10e\n" % (c2, phip, mindist))

# Perturbations
# Echange of type:
#tmp = design[row1, column]
#design[row1, column] = design[row2, column]
#design[row2, column] = tmp
for row1 in range(size):
    for row2 in range(size):
        for column in range(dimension):
            # The 3-upplet (row1, row2, column)
            # Criteria exchange design[row1, column] and design[row2, column]
            updated_c2 = ot.SpaceFillingC2().perturbLHS(
distribution.setDescription(['U' + str(i) for i in range(dimension)])
lhs = ot.LHSExperiment(distribution, size)
lhs.setRandomShift(False)  # 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
spaceFillingC2 = ot.SpaceFillingC2()
spaceFillingPhiP = ot.SpaceFillingPhiP(10)
spaceFillingMinDist = ot.SpaceFillingMinDist()

# print the criteria on this design
print("PhiP=%f, C2=%f" % (ot.SpaceFillingPhiP().evaluate(design),
                          ot.SpaceFillingC2().evaluate(design)))

# --------------------------------------------------#
# ------------- Simulated annealing  ------------- #
# --------------------------------------------------#
# Geometric profile
T0 = 10.0
iMax = 2000
c = 0.95
geomProfile = ot.GeometricProfile(T0, c, iMax)
Exemplo n.º 6
0
# Build standard LHS algorithm
distribution = ot.ComposedDistribution([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)
Exemplo n.º 7
0
distribution.setDescription(['U'+str(i) for i in range(dimension)])
lhs = ot.LHSExperiment(distribution, size)
lhs.setRandomShift(False)  # 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
spaceFillingC2 = ot.SpaceFillingC2()
spaceFillingPhiP = ot.SpaceFillingPhiP(10)

# print the criteria on this design
print("PhiP=%f, C2=%f" %
      (ot.SpaceFillingPhiP().evaluate(design), ot.SpaceFillingC2().evaluate(design)))

# --------------------------------------------------#
# ------------- Simulated annealing  ------------- #
# --------------------------------------------------#
# Geometric profile
T0 = 10.0
iMax = 2000
c = 0.95
geomProfile = ot.GeometricProfile(T0, c, iMax)

# 1) Simulated Annealing LHS with geometric temperature profile, C2
Exemplo n.º 8
0
# %%
N = 100
# Considering independent Uniform distributions of dimension 3
# Bounds are (-1,1), (0,2) and (0, 0.5)
distribution = ot.ComposedDistribution(
    [ot.Uniform(-1.0, 1.0),
     ot.Uniform(0.0, 2.0),
     ot.Uniform(0.0, 0.5)])
# Random LHS
lhs = ot.LHSExperiment(distribution, N)
lhs.setAlwaysShuffle(True)  # randomized
design = lhs.generate()
# C2
c2 = ot.SpaceFillingC2().evaluate(design)
# PhiP with default p
phip = ot.SpaceFillingPhiP().evaluate(design)
# mindist
mindist = ot.SpaceFillingMinDist().evaluate(design)
# For p->infinity
phip_inf = ot.SpaceFillingPhiP(100).evaluate(design)
print(phip, mindist, phip_inf)

# %%
# **Optimized LHS using Monte Carlo**

# %%
# As with Monte Carlo, user decides of a fixed number of iterations,
# but this time this number is part of the temperature profile.
#
# Two profiles are currently provided:
# - Linear profile: :math:`T_i = T_0 (1-\frac{1}{n_{iter}})`