示例#1
0
levels = ot.Indices(2)
levels.fill(5, 0)
morris_experiment = otmorris.MorrisExperimentGrid(levels, r)
grid_bound = morris_experiment.getBounds()
sample1 = morris_experiment.generate()
print("Morris experiment generated from grid = ", sample1)

print("Use Case #2 : generate trajectories from initial lhs design")
size = 20
# Generate an LHS design
dist = ot.ComposedDistribution(2 * [ot.Uniform(0, 1)])
experiment = ot.LHSExperiment(dist, size, True, False)
lhsDesign = experiment.generate()
print("Initial LHS design = ", lhsDesign)
# Generate designs
morris_experiment_lhs = otmorris.MorrisExperimentLHS(lhsDesign, r)
lhs_bound = morris_experiment_lhs.getBounds()
sample2 = morris_experiment.generate()
print("Morris experiment generated from LHS = ", sample2)

# Define model
model = ot.SymbolicFunction(["x", "y"], ["cos(x)*y + sin(y)*x + x*y -0.1"])

# Define Morris method with two designs
morrisEE1 = otmorris.Morris(sample1, model(sample1), grid_bound)
morrisEE2 = otmorris.Morris(sample2, model(sample2), lhs_bound)
print("Using level grid, E(|EE|)  = ",
      morrisEE1.getMeanAbsoluteElementaryEffects())
print("                  V(|EE|)^{1/2} = ",
      morrisEE1.getStandardDeviationElementaryEffects())
# Use Case : starting from an LHS
# OT does not allow yet to manage centered lhs designs, so a design has
# been generated outside OT
lhs = ot.Sample([[0.875, 0.575], [0.775, 0.775], [0.625,
                                                  0.925], [0.375, 0.625],
                 [0.275, 0.975], [0.075, 0.825], [0.225,
                                                  0.325], [0.425, 0.225],
                 [0.925, 0.475], [0.325, 0.725], [0.025,
                                                  0.275], [0.525, 0.175],
                 [0.125, 0.375], [0.475, 0.025], [0.825,
                                                  0.675], [0.175, 0.525],
                 [0.975, 0.875], [0.675, 0.075], [0.725, 0.125],
                 [0.575, 0.425]])
print("Use Case #2 : generate trajectories from initial lhs design")
print("Initial LHS design = ", lhs)

# generate designs
morris_experiment = otmorris.MorrisExperimentLHS(lhs, r)
Y = morris_experiment.generate()
print("Morris experiment generated from LHS = ", Y)

# Validation
for n in range(r):
    first_element = n * (Y.getDimension() + 1)
    last_element = first_element + (Y.getDimension() + 1)
    dy = Y[first_element + 1:last_element] - \
        Y[first_element:(last_element - 1)]
    print("#%d", n + 1)
    print("dy=", dy)