dim = model.getInputDimension() # We create a normal distribution point of dimension 1 mean = [50.0, 1.0, 10.0, 5.0] # E, F, L, I sigma = [1.0] * dim R = ot.IdentityMatrix(dim) myDistribution = ot.Normal(mean, sigma, R) # We create a 'usual' RandomVector from the Distribution vect = ot.RandomVector(myDistribution) # We create a composite random vector composite = ot.CompositeRandomVector(model, vect) ot.RandomGenerator.SetSeed(42) algo = ot.ExpectationSimulationAlgorithm(composite) algo.setMaximumOuterSampling(250000) algo.setBlockSize(2) # algo.setMaximumCoefficientOfVariation(1e-6) algo.setStandardDeviationCriterionType('MAX') algo.setCoefficientOfVariationCriterionType('NONE') # algo.setMaximumStandardDeviation(1.6) # print(algo.getMaximumStandardDeviation()) # algo.setProgressCallback(progress) # algo.setStopCallback(stop) print('algo=', algo) # Perform the simulation algo.run()
View(Zm.drawPDF()).show() # 4. Create the joint distribution function, # the output and the event. X = ot.ComposedDistribution([Q, Ks, Zv, Zm]) Y = ot.RandomVector(g, ot.RandomVector(X)) # 5. Estimate expectation with simple Monte-Carlo sampleSize = 10000 sampleX = X.getSample(sampleSize) sampleY = g(sampleX) sampleMean = sampleY.computeMean() print("Mean by MC = %f" % (sampleMean[0])) # 6. Estimate expectation with algorithm algo = ot.ExpectationSimulationAlgorithm(Y) algo.setMaximumOuterSampling(1000) algo.setBlockSize(1) algo.setCoefficientOfVariationCriterionType('NONE') algo.run() result = algo.getResult() expectation = result.getExpectationEstimate() print("Mean by ESA = %f " % expectation[0]) expectationDistribution = result.getExpectationDistribution() View(expectationDistribution.drawPDF()) pl.savefig("MeanDistribution.pdf") # Sensitivity analysis estimator = ot.SaltelliSensitivityAlgorithm() estimator.setUseAsymptoticDistribution(True)
# %% # We create a random vector that follows the distribution of the input variables. inputVector = ot.RandomVector(distribution) # %% # The output vector is a :class:`~openturns.CompositeRandomVector`. outputVector = ot.CompositeRandomVector(model, inputVector) # %% # The mean of the output vector is print("Mean of the output random vector : %.5f" % im.expectation) # %% # We define the algorithm simply by calling it with the output vector : algo = ot.ExpectationSimulationAlgorithm(outputVector) # %% # We can also set the algorithm parameters : algo.setMaximumOuterSampling(80000) algo.setBlockSize(1) algo.setCoefficientOfVariationCriterionType('NONE') # %% # We are then ready to launch the algorithm and store the result. algo.run() result = algo.getResult() # %% # As usual for Monte Carlo estimation we can draw the convergence history. graphConvergence = algo.drawExpectationConvergence()