.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/reliability/subset_simulation/plot_subset_rosenbrock.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_reliability_subset_simulation_plot_subset_rosenbrock.py: Rosenbrock performance function ====================================================================== .. GENERATED FROM PYTHON SOURCE LINES 10-11 1. Import the necessary libraries .. GENERATED FROM PYTHON SOURCE LINES 14-28 .. code-block:: default import matplotlib.pyplot as plt import numpy as np import scipy.stats as stats from UQpy import PythonModel # Import this newly defined Rosenbrock distribution into the Distributions module from UQpy.distributions import Normal from UQpy.reliability import SubsetSimulation from UQpy.run_model.RunModel import RunModel from UQpy.sampling import ModifiedMetropolisHastings, Stretch # First import the file that contains the newly defined Rosenbrock distribution from local_Rosenbrock import Rosenbrock .. GENERATED FROM PYTHON SOURCE LINES 29-30 :class:`.ModifiedMetropolisHastings` Initial Samples .. GENERATED FROM PYTHON SOURCE LINES 33-65 .. code-block:: default m = PythonModel(model_script='local_Rosenbrock_pfn.py', model_object_name="RunPythonModel") model = RunModel(model=m) dist = Rosenbrock(p=100.) dist_prop1 = Normal(loc=0, scale=1) dist_prop2 = Normal(loc=0, scale=10) x = stats.norm.rvs(loc=0, scale=1, size=(100, 2), random_state=83276) mcmc_init1 = ModifiedMetropolisHastings(dimension=2, log_pdf_target=dist.log_pdf, seed=x.tolist(), burn_length=1000, proposal=[dist_prop1, dist_prop2], random_state=8765) mcmc_init1.run(10000) sampling=Stretch(log_pdf_target=dist.log_pdf, dimension=2, n_chains=1000, random_state=38546) x_ss_MMH = SubsetSimulation(sampling=sampling, runmodel_object=model, conditional_probability=0.1, nsamples_per_subset=10000, samples_init=mcmc_init1.samples) for i in range(len(x_ss_MMH.performance_function_per_level)): plt.scatter(x_ss_MMH.samples[i][:, 0], x_ss_MMH.samples[i][:, 1], marker='o') plt.grid(True) plt.xlabel(r'$X_1$') plt.ylabel(r'$X_2$') plt.yticks(np.arange(-20, 180, step=20)) plt.xlim((-10, 15)) plt.tight_layout() plt.show() print(x_ss_MMH.failure_probability) .. image-sg:: /auto_examples/reliability/subset_simulation/images/sphx_glr_plot_subset_rosenbrock_001.png :alt: plot subset rosenbrock :srcset: /auto_examples/reliability/subset_simulation/images/sphx_glr_plot_subset_rosenbrock_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 4.0450000000000015e-08 .. GENERATED FROM PYTHON SOURCE LINES 66-67 :class:`.Stretch` Initial Samples .. GENERATED FROM PYTHON SOURCE LINES 70-107 .. code-block:: default m = PythonModel(model_script='local_Rosenbrock_pfn.py', model_object_name="RunPythonModel") model = RunModel(model=m) dist = Rosenbrock(p=100.) x = stats.norm.rvs(loc=0, scale=1, size=(100, 2), random_state=83276) mcmc_init2 = Stretch(dimension=2, log_pdf_target=dist.log_pdf, seed=x.tolist(), burn_length=1000, random_state=8765) mcmc_init2.run(10000) sampling=Stretch(log_pdf_target=dist.log_pdf, dimension=2, n_chains=1000, random_state=83456) x_ss_Stretch = SubsetSimulation(sampling=sampling, runmodel_object=model, conditional_probability=0.1, nsamples_per_subset=10000, samples_init=mcmc_init2.samples) for i in range(len(x_ss_Stretch.performance_function_per_level)): plt.scatter(x_ss_Stretch.samples[i][:, 0], x_ss_Stretch.samples[i][:, 1], marker='o') plt.grid(True) plt.xlabel(r'$X_1$') plt.ylabel(r'$X_2$') plt.yticks(np.arange(-20, 180, step=20)) plt.xlim((-10, 15)) plt.tight_layout() plt.show() print(x_ss_Stretch.failure_probability) plt.figure() plt.plot(mcmc_init2.samples[:, 0], mcmc_init2.samples[:, 1], 'o') plt.plot(mcmc_init1.samples[:, 0], mcmc_init1.samples[:, 1], 'x') plt.grid(True) plt.xlabel(r'$X_1$') plt.ylabel(r'$X_2$') plt.yticks(np.arange(-20, 180, step=20)) plt.xlim((-10, 15)) plt.tight_layout() plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/reliability/subset_simulation/images/sphx_glr_plot_subset_rosenbrock_002.png :alt: plot subset rosenbrock :srcset: /auto_examples/reliability/subset_simulation/images/sphx_glr_plot_subset_rosenbrock_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/reliability/subset_simulation/images/sphx_glr_plot_subset_rosenbrock_003.png :alt: plot subset rosenbrock :srcset: /auto_examples/reliability/subset_simulation/images/sphx_glr_plot_subset_rosenbrock_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0.0004715000000000001 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.631 seconds) .. _sphx_glr_download_auto_examples_reliability_subset_simulation_plot_subset_rosenbrock.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/reliability/subset_simulation/plot_subset_rosenbrock.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_subset_rosenbrock.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_subset_rosenbrock.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_