def subset_event(ev): algo = ot.SubsetSampling(ev) algo.setMaximumOuterSampling(2500) algo.setBlockSize(4) algo.run() result = algo.getResult() return result.getProbabilityEstimate()
def run_SubSet( event, coefVar=0.05, outerSampling=1000, seed=1234, verbose=False, failure_domain=None, ): """ Run a Subset simulation """ # Initialize the random generator ot.RandomGenerator.SetSeed(seed) # Run LHS simulation simulation = ot.SubsetSampling(event, 2.0, 0.05) simulation.setMaximumCoefficientOfVariation(coefVar) simulation.setMaximumOuterSampling(outerSampling) # simulation.setBlockSize(blockSize) # try: simulation.run() # except Exception as e: # dump_cache(model, 'Cache/physicalModelMathFunction') # raise e result = simulation.getResult() dfResult = pd.DataFrame() dfResult = dfResult.append( pd.DataFrame([result.getProbabilityEstimate()], index=["Probability of failure"])) dfResult = dfResult.append( pd.DataFrame( [result.getCoefficientOfVariation()], index=["Coefficient of varation"], )) dfResult = dfResult.append( pd.DataFrame([result.getConfidenceLength()], index=["95 % Confidence length"])) dfResult = dfResult.append( pd.DataFrame( [result.getOuterSampling() * result.getBlockSize()], index=["Number of calls"], )) dfResult = dfResult.reset_index() dfResult.columns = ["", "Results - Subset"] if verbose: print(dfResult, "\n") return simulation
# %% Y = ot.CompositeRandomVector(g, X) # %% # Create the event :math:`\{ Y = g(X) \leq 0 \}` # ---------------------------------------------- # %% myEvent = ot.ThresholdEvent(Y, ot.LessOrEqual(), 0.0) # %% # Evaluate the probability with the subset sampling technique # ----------------------------------------------------------- # %% algo = ot.SubsetSampling(myEvent) # %% # In order to get all the inputs and outputs that realize the event, you have to mention it now: # %% algo.setKeepEventSample(True) # %% # Now you can run the algorithm! # %% algo.run() # %% result = algo.getResult()
# # Computation # bs = 1 # Monte Carlo experiment = ot.MonteCarloExperiment() myMC = ot.ProbabilitySimulationAlgorithm(myEvent, experiment) myMC.setMaximumOuterSampling(int(1e6) // bs) myMC.setBlockSize(bs) myMC.setMaximumCoefficientOfVariation(-1.0) myMC.run() # # SubsetSampling mySS = ot.SubsetSampling(myEvent) mySS.setMaximumOuterSampling(10000 // bs) mySS.setBlockSize(bs) mySS.run() # # Results # # Monte Carlo resultMC = myMC.getResult() PFMC = resultMC.getProbabilityEstimate() CVMC = resultMC.getCoefficientOfVariation() variance_PF_MC = resultMC.getVarianceEstimate() length90MC = resultMC.getConfidenceLength(0.90) N_MC = resultMC.getOuterSampling() * resultMC.getBlockSize()
# # Computation # bs = 1 # Monte Carlo experiment = ot.MonteCarloExperiment() myMC = ot.ProbabilitySimulationAlgorithm(myEvent, experiment) myMC.setMaximumOuterSampling(int(1e6) // bs) myMC.setBlockSize(bs) myMC.setMaximumCoefficientOfVariation(-1.0) myMC.run() # # SubsetSampling mySS = ot.SubsetSampling(myEvent) mySS.setMaximumOuterSampling(10000 // bs) mySS.setBlockSize(bs) mySS.setKeepEventSample(True) mySS.run() # # Results # # Monte Carlo resultMC = myMC.getResult() PFMC = resultMC.getProbabilityEstimate() CVMC = resultMC.getCoefficientOfVariation() variance_PF_MC = resultMC.getVarianceEstimate() length90MC = resultMC.getConfidenceLength(0.90)