diff --git a/.gitignore b/.gitignore index b3693e14ed4b701992349e08223e90d260ce0148..bb6a50992da01174356ab7c15a1eac1f75b8459b 100644 --- a/.gitignore +++ b/.gitignore @@ -125,4 +125,4 @@ cython_debug/ .vscode/ # auto_examples -auto_examples/ \ No newline at end of file +docs/source/auto_examples/ \ No newline at end of file diff --git a/docs/source/_build/doctrees/auto_examples/emulator/index.doctree b/docs/source/_build/doctrees/auto_examples/emulator/index.doctree new file mode 100644 index 0000000000000000000000000000000000000000..2c2fc594593ba5face932a4c26e0f4eb00c2ebfb Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/emulator/index.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/emulator/plot_ppgasp.doctree b/docs/source/_build/doctrees/auto_examples/emulator/plot_ppgasp.doctree new file mode 100644 index 0000000000000000000000000000000000000000..22f752101dbcced07044e1d3ea49d20edadd7065 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/emulator/plot_ppgasp.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/emulator/plot_scalargasp.doctree b/docs/source/_build/doctrees/auto_examples/emulator/plot_scalargasp.doctree new file mode 100644 index 0000000000000000000000000000000000000000..e2279423a7653670b2741027739ef03390a095b8 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/emulator/plot_scalargasp.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/emulator/sg_execution_times.doctree b/docs/source/_build/doctrees/auto_examples/emulator/sg_execution_times.doctree new file mode 100644 index 0000000000000000000000000000000000000000..88fa3d19c9167c9cd224c68661154c49cff1ca0c Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/emulator/sg_execution_times.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/inference/index.doctree b/docs/source/_build/doctrees/auto_examples/inference/index.doctree new file mode 100644 index 0000000000000000000000000000000000000000..e7008d2548e49193904e452f2561bc991f040330 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/inference/index.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/inference/plot_active_learning.doctree b/docs/source/_build/doctrees/auto_examples/inference/plot_active_learning.doctree new file mode 100644 index 0000000000000000000000000000000000000000..76d8617a8567e3d2774b70c5b3917f10784fa42a Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/inference/plot_active_learning.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/inference/plot_bayes_inference.doctree b/docs/source/_build/doctrees/auto_examples/inference/plot_bayes_inference.doctree new file mode 100644 index 0000000000000000000000000000000000000000..62ce80d9b0b2abec6d65fb3548bd102b9e810f99 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/inference/plot_bayes_inference.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/inference/sg_execution_times.doctree b/docs/source/_build/doctrees/auto_examples/inference/sg_execution_times.doctree new file mode 100644 index 0000000000000000000000000000000000000000..00493b8f1a79b3f90f6f115969a34e1686195af8 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/inference/sg_execution_times.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sampler/index.doctree b/docs/source/_build/doctrees/auto_examples/sampler/index.doctree new file mode 100644 index 0000000000000000000000000000000000000000..7b280b11eba1df5e70d78d362d0a43ce95b0fa5e Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sampler/index.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sampler/plot_latin.doctree b/docs/source/_build/doctrees/auto_examples/sampler/plot_latin.doctree new file mode 100644 index 0000000000000000000000000000000000000000..0fa64e786f73c57466d9234cb4f825f36348a0df Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sampler/plot_latin.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sampler/plot_metropolis_hastings.doctree b/docs/source/_build/doctrees/auto_examples/sampler/plot_metropolis_hastings.doctree new file mode 100644 index 0000000000000000000000000000000000000000..ceff01bad24e680b9d12f37acc26adbbfa4317f9 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sampler/plot_metropolis_hastings.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sampler/plot_saltelli.doctree b/docs/source/_build/doctrees/auto_examples/sampler/plot_saltelli.doctree new file mode 100644 index 0000000000000000000000000000000000000000..a07571717bc57a968d5e498a280b514cb975dcbe Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sampler/plot_saltelli.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sampler/sg_execution_times.doctree b/docs/source/_build/doctrees/auto_examples/sampler/sg_execution_times.doctree new file mode 100644 index 0000000000000000000000000000000000000000..1110d7b9e813db52acf9bca6d7a1694b99ab7a5a Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sampler/sg_execution_times.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sensitivity/index.doctree b/docs/source/_build/doctrees/auto_examples/sensitivity/index.doctree new file mode 100644 index 0000000000000000000000000000000000000000..4ec7ce336ee5d63469775dbdc4524a0198a84f2a Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sensitivity/index.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sensitivity/plot_sobol_analyze.doctree b/docs/source/_build/doctrees/auto_examples/sensitivity/plot_sobol_analyze.doctree new file mode 100644 index 0000000000000000000000000000000000000000..f1d7f2e6308a627d9617bbf8fa4e14840a8c3717 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sensitivity/plot_sobol_analyze.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/sensitivity/sg_execution_times.doctree b/docs/source/_build/doctrees/auto_examples/sensitivity/sg_execution_times.doctree new file mode 100644 index 0000000000000000000000000000000000000000..3135a62adb9e9427642a9a6028026e606dcd5b85 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/sensitivity/sg_execution_times.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/simulator/index.doctree b/docs/source/_build/doctrees/auto_examples/simulator/index.doctree new file mode 100644 index 0000000000000000000000000000000000000000..f957970b9b940d7eed4292ce1aca5e445c25a30a Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/simulator/index.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/simulator/plot_mass_point_model.doctree b/docs/source/_build/doctrees/auto_examples/simulator/plot_mass_point_model.doctree new file mode 100644 index 0000000000000000000000000000000000000000..c140f59d6194cf424c468620674fccc79d23f480 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/simulator/plot_mass_point_model.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/simulator/plot_ravaflow24.doctree b/docs/source/_build/doctrees/auto_examples/simulator/plot_ravaflow24.doctree new file mode 100644 index 0000000000000000000000000000000000000000..4a05c523a29c6f61a362a20171f1c5238b0368b9 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/simulator/plot_ravaflow24.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/simulator/plot_run_mass_point_model.doctree b/docs/source/_build/doctrees/auto_examples/simulator/plot_run_mass_point_model.doctree new file mode 100644 index 0000000000000000000000000000000000000000..4ca8a0c6ba16ddbfb62de8fc0a42305496a7f31f Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/simulator/plot_run_mass_point_model.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/simulator/plot_run_ravaflow24.doctree b/docs/source/_build/doctrees/auto_examples/simulator/plot_run_ravaflow24.doctree new file mode 100644 index 0000000000000000000000000000000000000000..ced5144e5726a6d694f3dda9e32c709624bc5f94 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/simulator/plot_run_ravaflow24.doctree differ diff --git a/docs/source/_build/doctrees/auto_examples/simulator/sg_execution_times.doctree b/docs/source/_build/doctrees/auto_examples/simulator/sg_execution_times.doctree new file mode 100644 index 0000000000000000000000000000000000000000..c995d0c4d37c587e2753f27c28a6944860adede8 Binary files /dev/null and b/docs/source/_build/doctrees/auto_examples/simulator/sg_execution_times.doctree differ diff --git a/docs/source/_build/html/_sources/auto_examples/emulator/index.rst.txt b/docs/source/_build/html/_sources/auto_examples/emulator/index.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..43275957bbbabc40965827251ef122d3a34647a9 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/emulator/index.rst.txt @@ -0,0 +1,75 @@ +:orphan: + +Emulator +======== + + +.. raw:: html + + <div class="sphx-glr-thumbnails"> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="PPGaSP: GP emulation for multi-output functions"> + +.. only:: html + + .. image:: /auto_examples/emulator/images/thumb/sphx_glr_plot_ppgasp_thumb.png + :alt: PPGaSP: GP emulation for multi-output functions + + :ref:`sphx_glr_auto_examples_emulator_plot_ppgasp.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">PPGaSP: GP emulation for multi-output functions</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="ScalarGaSP: GP emulation for a single-output function"> + +.. only:: html + + .. image:: /auto_examples/emulator/images/thumb/sphx_glr_plot_scalargasp_thumb.png + :alt: ScalarGaSP: GP emulation for a single-output function + + :ref:`sphx_glr_auto_examples_emulator_plot_scalargasp.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">ScalarGaSP: GP emulation for a single-output function</div> + </div> + + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/emulator/plot_ppgasp + /auto_examples/emulator/plot_scalargasp + + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-gallery + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download all examples in Python source code: emulator_python.zip </auto_examples/emulator/emulator_python.zip>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download all examples in Jupyter notebooks: emulator_jupyter.zip </auto_examples/emulator/emulator_jupyter.zip>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/emulator/plot_ppgasp.rst.txt b/docs/source/_build/html/_sources/auto_examples/emulator/plot_ppgasp.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..e1b86d5aa0b7193356b91f9dc0773bc5e346f9de --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/emulator/plot_ppgasp.rst.txt @@ -0,0 +1,280 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/emulator/plot_ppgasp.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_emulator_plot_ppgasp.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_emulator_plot_ppgasp.py: + + +PPGaSP: GP emulation for multi-output functions +=============================================== + +.. GENERATED FROM PYTHON SOURCE LINES 9-23 + +This example shows how to apply Gaussian process emulation to a multi-output +function using class :class:`.PPGaSP`. + +The multi-output function that we are going to look at is the `DIAMOND` +(diplomatic and military operations in a non-warfighting domain) computer model. +It is used as a testbed to illustrate the `PP GaSP` emulator in the `R` package +`RobustGaSP`, see :cite:t:`Gu2019` for more detail. + +The simulator has :math:`13` input parameters and :math:`5` outputs. Namely, +:math:`\mathbf{y}=f(\mathbf{x})` where :math:`\mathbf{x}=(x_1,\ldots,x_{13})^T` +and :math:`\mathbf{y}=(y_1,\ldots,y_5)^T`. + +The training and testing data are provided in the folder '.../tests/data/'. +We first load the training and testing data. + +.. GENERATED FROM PYTHON SOURCE LINES 24-40 + +.. code-block:: default + + + import numpy as np + import os + + dir_data = os.path.abspath('../../../tests/data/') + + humanityX = np.genfromtxt(os.path.join(dir_data, 'humanityX.csv'), delimiter=',') + humanityY = np.genfromtxt(os.path.join(dir_data, 'humanityY.csv'), delimiter=',') + print(f"Number of training data points: ", humanityX.shape[0]) + print(f"Input dimension: ", humanityX.shape[1]) + print(f"Output dimension: ", humanityY.shape[1]) + + humanityXt = np.genfromtxt(os.path.join(dir_data, 'humanityXt.csv'), delimiter=',') + humanityYt = np.genfromtxt(os.path.join(dir_data, 'humanityYt.csv'), delimiter=',') + print(f"Number of testing data points: ", humanityXt.shape[0]) + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Number of training data points: 120 + Input dimension: 13 + Output dimension: 5 + Number of testing data points: 120 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 41-43 + +.. note:: You may need to modify ``dir_data`` according to where you save them + on your local machine. + +.. GENERATED FROM PYTHON SOURCE LINES 45-50 + +``humanityX`` and ``humanitY`` are the training data, corresponding to ``design`` +and ``response`` respectively. ``humanityXt`` are testing input data, at which +we are going to make predictions once the emulator is trained. ``humanityYt`` +are the true outputs at ``humanityXt``, which is then used to validate the +performance of the trained emulator. + +.. GENERATED FROM PYTHON SOURCE LINES 52-54 + +To build a `PP GaSP` emulator for the above simulator, first import class +:class:`.PPGaSP` by + +.. GENERATED FROM PYTHON SOURCE LINES 55-58 + +.. code-block:: default + + + from psimpy.emulator import PPGaSP + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 59-63 + +Then, create an instance of :class:`.PPGaSP`. The parameter ``ndim`` +(dimension of function input ``x``) must be specified. Optional parameters, such +as ``method``, ``kernel_type``, etc., can be set up if desired. Here, we leave +all the optional parameters to their default values. + +.. GENERATED FROM PYTHON SOURCE LINES 64-68 + +.. code-block:: default + + + emulator = PPGaSP(ndim=humanityX.shape[1]) + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 69-71 + +Next, we train the `PP GaSP` emulator based on the training data using +:py:meth:`.PPGaSP.train` method. + +.. GENERATED FROM PYTHON SOURCE LINES 72-75 + +.. code-block:: default + + + emulator.train(design=humanityX, response=humanityY) + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + The upper bounds of the range parameters are 296,974 297,1814 294,7672 295,9345 296,563 295,935 297,3198 296,4444 296,9323 298,2373 298,0619 298,7249 298,7249 + The initial values of range parameters are 5,93948 5,943628 5,895344 5,918691 5,93126 5,918701 5,946395 5,928888 5,938645 5,964745 5,961238 5,974498 5,974498 + Start of the optimization 1 : + The number of iterations is 44 + The value of the marginal posterior function is -5279,534 + Optimized range parameters are 25,46132 2,891428 5,30812 26,95519 291,1828 48,17274 84,56133 2,874385 39,12121 51,81304 0,5407651 1,728696 1,020605 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 12,37503 12,38367 12,28307 12,33172 12,3579 12,33174 12,38944 12,35296 12,37329 12,42767 12,42037 12,44799 12,44799 + Start of the optimization 2 : + The number of iterations is 45 + The value of the marginal posterior function is -5279,534 + Optimized range parameters are 25,46132 2,891428 5,308121 26,95519 291,183 48,17274 84,56133 2,874385 39,12121 51,81304 0,5407651 1,728696 1,020605 + Optimized nugget parameter is 0 + Convergence: TRUE + + + + +.. GENERATED FROM PYTHON SOURCE LINES 76-79 + +With the trained emulator, we can make predictions for any arbitrary set of +input points using :py:meth:`PPGaSP.predict` method. +Here, we make predictions at testing input points ``humanityXt``. + +.. GENERATED FROM PYTHON SOURCE LINES 80-83 + +.. code-block:: default + + + predictions = emulator.predict(humanityXt) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 84-86 + +We can validate the performance of the trained emulator based on the true outputs +``humanityYt``. + +.. GENERATED FROM PYTHON SOURCE LINES 87-106 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + fig, ax = plt.subplots(5, 1, figsize=(6,15)) + + for i in range(humanityY.shape[1]): + + ax[i].set_xlabel(f'Actual $y_{i+1}$') + ax[i].set_ylabel(f'Emulator-predicted $y_{i+1}$') + ax[i].set_xlim(np.min(humanityYt[:,i]),np.max(humanityYt[:,i])) + ax[i].set_ylim(np.min(humanityYt[:,i]),np.max(humanityYt[:,i])) + + _ = ax[i].plot([np.min(humanityYt[:,i]),np.max(humanityYt[:,i])], [np.min(humanityYt[:,i]),np.max(humanityYt[:,i])]) + _ = ax[i].errorbar(humanityYt[:,i], predictions[:,i,0], predictions[:,i,3], fmt='.', linestyle='', label='prediction and std') + _ = ax[i].legend() + + plt.tight_layout() + + + + + +.. image-sg:: /auto_examples/emulator/images/sphx_glr_plot_ppgasp_001.png + :alt: plot ppgasp + :srcset: /auto_examples/emulator/images/sphx_glr_plot_ppgasp_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 107-109 + +We can also draw any number of samples at testing input ``humanityXt`` using +:py:meth:`.PPGaSPsample()` method. + +.. GENERATED FROM PYTHON SOURCE LINES 110-112 + +.. code-block:: default + + + samples = emulator.sample(humanityXt, nsamples=10) + print("Shape of samples: ", samples.shape) + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Shape of samples: (120, 5, 10) + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 5.333 seconds) + + +.. _sphx_glr_download_auto_examples_emulator_plot_ppgasp.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_ppgasp.py <plot_ppgasp.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_ppgasp.ipynb <plot_ppgasp.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/emulator/plot_scalargasp.rst.txt b/docs/source/_build/html/_sources/auto_examples/emulator/plot_scalargasp.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..95b144be25699ba941b5c48f94ac6e56129ba66e --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/emulator/plot_scalargasp.rst.txt @@ -0,0 +1,289 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/emulator/plot_scalargasp.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_emulator_plot_scalargasp.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_emulator_plot_scalargasp.py: + + +ScalarGaSP: GP emulation for a single-output function +===================================================== + +.. GENERATED FROM PYTHON SOURCE LINES 8-13 + +This example shows how to apply Gaussian process emulation to a single-output +function using class :class:`.ScalarGaSP`. + +The task is to build a GP emulator for the function :math:`y = x * sin(x)` +based on a few number of training data. + +.. GENERATED FROM PYTHON SOURCE LINES 16-17 + +First, import the class :class:`.ScalarGaSP` by + +.. GENERATED FROM PYTHON SOURCE LINES 18-21 + +.. code-block:: default + + + from psimpy.emulator import ScalarGaSP + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 22-26 + +Then, create an instance of :class:`.ScalarGaSP`. The parameter ``ndim`` +(dimension of function input ``x``) must be specified. Optional parameters, such +as ``method``, ``kernel_type``, etc., can be set up if desired. Here, we leave +all the optional parameters to their default values. + +.. GENERATED FROM PYTHON SOURCE LINES 27-30 + +.. code-block:: default + + + emulator = ScalarGaSP(ndim=1) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 31-34 + +Given training input points ``design`` and corresponding output values ``response``, +the emulator can be trained using :py:meth:`.ScalarGaSP.train`. Below we train +an emulator using :math:`8` selected points. + +.. GENERATED FROM PYTHON SOURCE LINES 35-47 + +.. code-block:: default + + + import numpy as np + + def f(x): + #return x + 3*np.sin(x/2) + return x*np.sin(x) + + x = np.arange(2,10,1) + y = f(x) + + emulator.train(design=x, response=y) + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + The upper bounds of the range parameters are 1881,404 + The initial values of range parameters are 37,62809 + Start of the optimization 1 : + The number of iterations is 9 + The value of the marginal posterior function is -13,79116 + Optimized range parameters are 2,237467 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,21875 + Start of the optimization 2 : + The number of iterations is 9 + The value of the marginal posterior function is -13,79116 + Optimized range parameters are 2,237467 + Optimized nugget parameter is 0 + Convergence: TRUE + + + + +.. GENERATED FROM PYTHON SOURCE LINES 48-50 + +We can validate the performance of the trained emulator using the leave-one-out +cross validation method :py:meth:`loo_validate()`. + +.. GENERATED FROM PYTHON SOURCE LINES 51-54 + +.. code-block:: default + + + validation = emulator.loo_validate() + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 55-57 + +Let's plot emulator predictions vs actual outputs. The error bar indicates the +standard deviation. + +.. GENERATED FROM PYTHON SOURCE LINES 58-74 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + fig , ax = plt.subplots(figsize=(4,4)) + + ax.set_xlabel('Actual y') + ax.set_ylabel('Emulator-predicted y') + ax.set_xlim(np.min(y)-1,np.max(y)+1) + ax.set_ylim(np.min(y)-1,np.max(y)+1) + + _ = ax.plot([np.min(y)-1,np.max(y)+1], [np.min(y)-1,np.max(y)+1]) + _ = ax.errorbar(y, validation[:,0], validation[:,1], fmt='.', linestyle='', label='prediction and std') + _ = plt.legend() + plt.tight_layout() + + + + + +.. image-sg:: /auto_examples/emulator/images/sphx_glr_plot_scalargasp_001.png + :alt: plot scalargasp + :srcset: /auto_examples/emulator/images/sphx_glr_plot_scalargasp_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 75-80 + +With the trained emulator at our deposit, we can use the +:py:meth:`.ScalarGaSP.predict()` method to make predictions at +any arbitrary set of input points (``testing_input``). It should be noted that, +``testing_trend`` should be set according to ``trend`` used during emulator +training. + +.. GENERATED FROM PYTHON SOURCE LINES 81-95 + +.. code-block:: default + + + testing_input = np.arange(0,10,0.1) + predictions = emulator.predict(testing_input) + + plt.plot(testing_input, predictions[:, 0], 'r-', label= "mean") + plt.scatter(x, y, s=15, c='k', label="training data", zorder=3) + plt.plot(testing_input, f(testing_input), 'k:', zorder=2, label="true function") + plt.fill_between(testing_input, predictions[:, 1], predictions[:, 2], alpha=0.3, label="95% CI") + plt.xlabel('x') + plt.ylabel('emulator-predicted y') + plt.xlim(testing_input[0], testing_input[-1]) + _ = plt.legend() + plt.tight_layout() + + + + +.. image-sg:: /auto_examples/emulator/images/sphx_glr_plot_scalargasp_002.png + :alt: plot scalargasp + :srcset: /auto_examples/emulator/images/sphx_glr_plot_scalargasp_002.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 96-98 + +We can also draw any number of samples at ``testing_input``` using +:py:meth:`.ScalarGaSP.sample()` method. + +.. GENERATED FROM PYTHON SOURCE LINES 99-117 + +.. code-block:: default + + + nsamples = 5 + samples = emulator.sample(testing_input, nsamples=nsamples) + + # sphinx_gallery_thumbnail_number = 3 + for i in range(nsamples): + plt.plot(testing_input, samples[:,i], '--', label=f'sample{i+1}') + + plt.scatter(x, y, s=15, c='k', label="training data", zorder=2) + plt.plot(testing_input, f(testing_input), 'k:', zorder=2, label="true function") + plt.fill_between(testing_input, predictions[:, 1], predictions[:, 2], alpha=0.3, label="95% CI") + plt.xlabel('x') + plt.ylabel('emulator-predicted y') + plt.xlim(testing_input[0], testing_input[-1]) + _ = plt.legend() + plt.tight_layout() + + + + + +.. image-sg:: /auto_examples/emulator/images/sphx_glr_plot_scalargasp_003.png + :alt: plot scalargasp + :srcset: /auto_examples/emulator/images/sphx_glr_plot_scalargasp_003.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 118-124 + +.. tip:: Above example shows how to train a GP emulator based on noise-free training data, + which is often the case of emulating a deterministic simulator. If you are dealing + with noisy training data, you can + + - set the parameter ``nugget`` to a desired value, or + - set ``nugget`` to :math:`0` and ``nugget_est`` to `True`, meaning that ``nugget`` + is estimated from the noisy training data. + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.728 seconds) + + +.. _sphx_glr_download_auto_examples_emulator_plot_scalargasp.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_scalargasp.py <plot_scalargasp.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_scalargasp.ipynb <plot_scalargasp.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/emulator/sg_execution_times.rst.txt b/docs/source/_build/html/_sources/auto_examples/emulator/sg_execution_times.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..92925ce389ba64108e49fd69dad5ccd88a178dbd --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/emulator/sg_execution_times.rst.txt @@ -0,0 +1,14 @@ + +:orphan: + +.. _sphx_glr_auto_examples_emulator_sg_execution_times: + +Computation times +================= +**00:06.062** total execution time for **auto_examples_emulator** files: + ++------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_emulator_plot_ppgasp.py` (``plot_ppgasp.py``) | 00:05.333 | 0.0 MB | ++------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_emulator_plot_scalargasp.py` (``plot_scalargasp.py``) | 00:00.728 | 0.0 MB | ++------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/source/_build/html/_sources/auto_examples/inference/index.rst.txt b/docs/source/_build/html/_sources/auto_examples/inference/index.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..8df5785198ea8d53858cb899b078f088f1c0d98b --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/inference/index.rst.txt @@ -0,0 +1,75 @@ +:orphan: + +Inference +========= + + +.. raw:: html + + <div class="sphx-glr-thumbnails"> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Bayesian inference"> + +.. only:: html + + .. image:: /auto_examples/inference/images/thumb/sphx_glr_plot_bayes_inference_thumb.png + :alt: Bayesian inference + + :ref:`sphx_glr_auto_examples_inference_plot_bayes_inference.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Bayesian inference</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Active learning"> + +.. only:: html + + .. image:: /auto_examples/inference/images/thumb/sphx_glr_plot_active_learning_thumb.png + :alt: Active learning + + :ref:`sphx_glr_auto_examples_inference_plot_active_learning.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Active learning</div> + </div> + + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/inference/plot_bayes_inference + /auto_examples/inference/plot_active_learning + + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-gallery + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download all examples in Python source code: inference_python.zip </auto_examples/inference/inference_python.zip>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download all examples in Jupyter notebooks: inference_jupyter.zip </auto_examples/inference/inference_jupyter.zip>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/inference/plot_active_learning.rst.txt b/docs/source/_build/html/_sources/auto_examples/inference/plot_active_learning.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..f98c7f2a789a372881e306214aadc701031103b2 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/inference/plot_active_learning.rst.txt @@ -0,0 +1,1155 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/inference/plot_active_learning.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_inference_plot_active_learning.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_inference_plot_active_learning.py: + + +Active learning +=============== + +.. GENERATED FROM PYTHON SOURCE LINES 8-18 + +This example shows how to use the :class:`.ActiveLearning` class to iteratively +build a Gaussian process emulator for an unnormalized posterior involving a +simulator. It should be noted that this example is only for illustration +purpose, rather than a real case. For simplicity, required arguments for +:class:`.ActiveLearning` (including `simulator`, `likelihood`, `data`, etc.) are purely +made up. For a realistic case of active learning, one can refer to :cite:t:`Zhao2022`. + +First, we define the simulator, prior distribution of its variable parameters, +observed data, and likelihood function. They basically define the Bayesian +inference problem. + +.. GENERATED FROM PYTHON SOURCE LINES 19-39 + +.. code-block:: default + + + import numpy as np + + ndim = 2 # dimension of variable parameters of the simulator + bounds = bounds = np.array([[-5,5],[-5,5]]) # bounds of variable parameters + data = np.array([1,0]) + + def simulator(x1, x2): + """Simulator y=f(x).""" + y1, y2 = x1, x2 + return np.array([y1, y2]) + + def prior(x): + """Uniform prior.""" + return 1/(10*10) + + def likelihood(y, data): + """Likelihood function L(y,data).""" + return np.exp(-(y[0]-data[0])**2/100 - (y[0]**2-y[1]-data[1])**2) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 40-56 + +Imagine that the simulator is a complex solver. It is not computationally feasible +to compute the posterior distribution of the variable parameters using grid estimation +or Metropolis Hastings estimation. This is because they require evaluating the likelihood +many times which essentially leads to many evaluations of the simulator. Therefore, we +resort to use active learning to build a Gaussian process emulator for the unnormalized +posterior (prior times likelihood) based on a small number of evaluations of the simulator. +The the posterior can be estimated using the emulator. + +To do so, we need to pass arguments to following parameters of the :class:`.ActiveLearning` class: + + - run_sim_obj : instance of class :class:`.RunSimulator`. It carries information on how + to run the simulator. + - lhs_sampler : instance of class :class:`.LHS`. It is used to draw initial samples to run + simulations in order to train an inital Gaussian process emulator. + - scalar_gasp : instance of class :class:`.ScalarGaSP`. It sets up the emulator structure. + + +.. GENERATED FROM PYTHON SOURCE LINES 57-66 + +.. code-block:: default + + + from psimpy.simulator import RunSimulator + from psimpy.sampler import LHS + from psimpy.emulator import ScalarGaSP + + run_simulator = RunSimulator(simulator, var_inp_parameter=['x1','x2']) + lhs_sampler = LHS(ndim=ndim, bounds=bounds, seed=1) + scalar_gasp = ScalarGaSP(ndim=ndim) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 67-68 + +Next, we create an object of the :class:`.ActiveLearning` class by + +.. GENERATED FROM PYTHON SOURCE LINES 69-75 + +.. code-block:: default + + + from psimpy.inference import ActiveLearning + + active_learner = ActiveLearning(ndim, bounds, data, run_simulator, prior, likelihood, + lhs_sampler, scalar_gasp) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 76-81 + +Then we can call the :py:meth:`.ActiveLearning.initial_simulation` method to run initial +simulations and call the :py:meth:`.ActiveLearning.iterative_emulation` method to +iteratively run new simulation and build emulator. Here we allocate 40 simulations for +initial emulator training and 60 simulations for adaptive training. + + +.. GENERATED FROM PYTHON SOURCE LINES 82-91 + +.. code-block:: default + + n0 = 40 + niter = 60 + + init_var_samples, init_sim_outputs = active_learner.initial_simulation( + n0, mode='parallel', max_workers=4) + + var_samples, _, _ = active_learner.iterative_emulation( + n0, init_var_samples, init_sim_outputs, niter=niter) + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + The upper bounds of the range parameters are 401,3482 397,4694 + The initial values of range parameters are 8,026963 7,949389 + Start of the optimization 1 : + The number of iterations is 22 + The value of the marginal posterior function is -146,5038 + Optimized range parameters are 30,59853 130,6077 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,9828751 0,9733764 + Start of the optimization 2 : + The number of iterations is 36 + The value of the marginal posterior function is -146,5038 + Optimized range parameters are 30,59827 130,6067 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 423,194 420,3365 + The initial values of range parameters are 8,463881 8,40673 + Start of the optimization 1 : + The number of iterations is 13 + The value of the marginal posterior function is -148,6792 + Optimized range parameters are 30,19534 133,3286 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,9589025 0,9524277 + Start of the optimization 2 : + The number of iterations is 12 + The value of the marginal posterior function is -148,6792 + Optimized range parameters are 30,19539 133,329 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 422,8426 419,9874 + The initial values of range parameters are 8,456851 8,399747 + Start of the optimization 1 : + The number of iterations is 34 + The value of the marginal posterior function is -149,9595 + Optimized range parameters are 30,64771 135,0597 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,9360715 0,9297509 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -149,9595 + Optimized range parameters are 30,64696 135,0536 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 423,2876 420,4294 + The initial values of range parameters are 8,465751 8,408588 + Start of the optimization 1 : + The number of iterations is 25 + The value of the marginal posterior function is -151,304 + Optimized range parameters are 31,21605 136,8571 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,9143024 0,9081287 + Start of the optimization 2 : + The number of iterations is 23 + The value of the marginal posterior function is -151,304 + Optimized range parameters are 31,21617 136,8537 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 389,6167 386,9859 + The initial values of range parameters are 7,792334 7,739717 + Start of the optimization 1 : + The number of iterations is 13 + The value of the marginal posterior function is -152,6009 + Optimized range parameters are 32,285 141,3784 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,8935228 0,8874894 + Start of the optimization 2 : + The number of iterations is 17 + The value of the marginal posterior function is -152,6009 + Optimized range parameters are 32,28096 141,3737 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 368,8855 366,3947 + The initial values of range parameters are 7,377711 7,327894 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -153,5419 + Optimized range parameters are 32,43481 141,7852 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,8736668 0,8677675 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -153,5419 + Optimized range parameters are 32,43357 141,7844 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 339,4555 337,1634 + The initial values of range parameters are 6,789111 6,743268 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -154,9929 + Optimized range parameters are 33,69448 151,2103 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,854674 0,848903 + Start of the optimization 2 : + The number of iterations is 22 + The value of the marginal posterior function is -154,9929 + Optimized range parameters are 33,69468 151,2111 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 369,9581 367,46 + The initial values of range parameters are 7,399163 7,349201 + Start of the optimization 1 : + The number of iterations is 26 + The value of the marginal posterior function is -155,4764 + Optimized range parameters are 33,90556 152,0139 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,8364895 0,8308412 + Start of the optimization 2 : + The number of iterations is 23 + The value of the marginal posterior function is -155,4764 + Optimized range parameters are 33,90541 152,0137 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 299,8308 297,8062 + The initial values of range parameters are 5,996615 5,956124 + Start of the optimization 1 : + The number of iterations is 27 + The value of the marginal posterior function is -155,8802 + Optimized range parameters are 34,04389 152,6133 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,8190626 0,813532 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -155,8802 + Optimized range parameters are 34,04381 152,6131 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 272,589 270,7484 + The initial values of range parameters are 5,45178 5,414968 + Start of the optimization 1 : + The number of iterations is 22 + The value of the marginal posterior function is -156,1383 + Optimized range parameters are 34,46966 151,4246 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,802347 0,7969293 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -156,1383 + Optimized range parameters are 34,46972 151,4261 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 217,1413 215,6751 + The initial values of range parameters are 4,342826 4,313501 + Start of the optimization 1 : + The number of iterations is 16 + The value of the marginal posterior function is -156,184 + Optimized range parameters are 34,52228 152,8428 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,7863001 0,7809907 + Start of the optimization 2 : + The number of iterations is 29 + The value of the marginal posterior function is -156,184 + Optimized range parameters are 34,5049 152,8145 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 206,6122 205,2171 + The initial values of range parameters are 4,132244 4,104342 + Start of the optimization 1 : + The number of iterations is 25 + The value of the marginal posterior function is -156,2348 + Optimized range parameters are 34,79805 155,1646 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,7708824 0,7656772 + Start of the optimization 2 : + The number of iterations is 22 + The value of the marginal posterior function is -156,2348 + Optimized range parameters are 34,82503 155,2481 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 264,8501 263,0618 + The initial values of range parameters are 5,297002 5,261235 + Start of the optimization 1 : + The number of iterations is 30 + The value of the marginal posterior function is -156,4063 + Optimized range parameters are 34,74024 156,9499 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,7560578 0,7509526 + Start of the optimization 2 : + The number of iterations is 35 + The value of the marginal posterior function is -156,4062 + Optimized range parameters are 34,71806 156,8712 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 255,2317 253,5083 + The initial values of range parameters are 5,104633 5,070165 + Start of the optimization 1 : + The number of iterations is 20 + The value of the marginal posterior function is -156,5552 + Optimized range parameters are 35,37305 157,5615 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,7417925 0,7367837 + Start of the optimization 2 : + The number of iterations is 37 + The value of the marginal posterior function is -156,5552 + Optimized range parameters are 35,37704 157,591 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 234,5139 232,9304 + The initial values of range parameters are 4,690278 4,658607 + Start of the optimization 1 : + The number of iterations is 25 + The value of the marginal posterior function is -156,8767 + Optimized range parameters are 35,91747 161,0899 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,7280556 0,7231396 + Start of the optimization 2 : + The number of iterations is 32 + The value of the marginal posterior function is -156,8767 + Optimized range parameters are 35,92577 161,0559 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 237,6023 235,9979 + The initial values of range parameters are 4,752045 4,719958 + Start of the optimization 1 : + The number of iterations is 15 + The value of the marginal posterior function is -156,6342 + Optimized range parameters are 36,30341 161,9859 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,7148183 0,7099916 + Start of the optimization 2 : + The number of iterations is 26 + The value of the marginal posterior function is -156,6343 + Optimized range parameters are 36,30117 161,8561 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 231,5375 229,9741 + The initial values of range parameters are 4,63075 4,599482 + Start of the optimization 1 : + The number of iterations is 27 + The value of the marginal posterior function is -156,3683 + Optimized range parameters are 36,27212 162,5847 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,7020536 0,6973131 + Start of the optimization 2 : + The number of iterations is 30 + The value of the marginal posterior function is -156,3684 + Optimized range parameters are 36,25962 162,5355 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 237,6502 236,0455 + The initial values of range parameters are 4,753005 4,720911 + Start of the optimization 1 : + The number of iterations is 14 + The value of the marginal posterior function is -156,014 + Optimized range parameters are 36,19577 162,4854 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,6897369 0,6850796 + Start of the optimization 2 : + The number of iterations is 27 + The value of the marginal posterior function is -156,014 + Optimized range parameters are 36,19621 162,4877 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 221,4001 219,9051 + The initial values of range parameters are 4,428002 4,398102 + Start of the optimization 1 : + The number of iterations is 36 + The value of the marginal posterior function is -155,8456 + Optimized range parameters are 36,93092 166,708 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,6778449 0,6732679 + Start of the optimization 2 : + The number of iterations is 19 + The value of the marginal posterior function is -155,8455 + Optimized range parameters are 37,00954 166,8438 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 207,5545 206,153 + The initial values of range parameters are 4,15109 4,123061 + Start of the optimization 1 : + The number of iterations is 36 + The value of the marginal posterior function is -155,2611 + Optimized range parameters are 37,54574 171,0122 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,666356 0,6618565 + Start of the optimization 2 : + The number of iterations is 26 + The value of the marginal posterior function is -155,2611 + Optimized range parameters are 37,52707 170,9901 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 211,1368 209,7111 + The initial values of range parameters are 4,222736 4,194222 + Start of the optimization 1 : + The number of iterations is 38 + The value of the marginal posterior function is -154,6105 + Optimized range parameters are 37,27271 173,4402 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,6552501 0,6508256 + Start of the optimization 2 : + The number of iterations is 38 + The value of the marginal posterior function is -154,6104 + Optimized range parameters are 37,31152 173,4271 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 229,1987 227,651 + The initial values of range parameters are 4,583973 4,553021 + Start of the optimization 1 : + The number of iterations is 30 + The value of the marginal posterior function is -153,8922 + Optimized range parameters are 37,52317 173,0118 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,6445083 0,6401563 + Start of the optimization 2 : + The number of iterations is 29 + The value of the marginal posterior function is -153,8923 + Optimized range parameters are 37,52772 173,0381 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 200,215 198,8631 + The initial values of range parameters are 4,004301 3,977262 + Start of the optimization 1 : + The number of iterations is 29 + The value of the marginal posterior function is -153,0737 + Optimized range parameters are 37,6626 173,7851 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,634113 0,6298312 + Start of the optimization 2 : + The number of iterations is 38 + The value of the marginal posterior function is -153,0733 + Optimized range parameters are 37,57977 172,9914 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 208,2931 206,8866 + The initial values of range parameters are 4,165862 4,137733 + Start of the optimization 1 : + The number of iterations is 31 + The value of the marginal posterior function is -152,171 + Optimized range parameters are 37,55899 172,4488 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,6240477 0,6198339 + Start of the optimization 2 : + The number of iterations is 34 + The value of the marginal posterior function is -152,1711 + Optimized range parameters are 37,55216 172,3431 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 190,9562 189,6668 + The initial values of range parameters are 3,819124 3,793336 + Start of the optimization 1 : + The number of iterations is 26 + The value of the marginal posterior function is -151,4191 + Optimized range parameters are 37,87024 177,6757 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,6142969 0,610149 + Start of the optimization 2 : + The number of iterations is 31 + The value of the marginal posterior function is -151,4191 + Optimized range parameters are 37,8678 177,4358 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 187,3139 186,0491 + The initial values of range parameters are 3,746279 3,720983 + Start of the optimization 1 : + The number of iterations is 27 + The value of the marginal posterior function is -150,3521 + Optimized range parameters are 37,93228 177,0193 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,6048462 0,6007621 + Start of the optimization 2 : + The number of iterations is 15 + The value of the marginal posterior function is -150,3521 + Optimized range parameters are 37,92683 176,9819 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 201,0467 199,6892 + The initial values of range parameters are 4,020934 3,993783 + Start of the optimization 1 : + The number of iterations is 31 + The value of the marginal posterior function is -149,229 + Optimized range parameters are 37,73923 179,7933 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5956819 0,5916596 + Start of the optimization 2 : + The number of iterations is 23 + The value of the marginal posterior function is -149,2295 + Optimized range parameters are 37,68347 179,3098 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 208,1589 206,7533 + The initial values of range parameters are 4,163178 4,135067 + Start of the optimization 1 : + The number of iterations is 31 + The value of the marginal posterior function is -148,0364 + Optimized range parameters are 37,10463 181,452 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,5867911 0,5828289 + Start of the optimization 2 : + The number of iterations is 28 + The value of the marginal posterior function is -148,0353 + Optimized range parameters are 37,10023 181,8802 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 207,5545 206,153 + The initial values of range parameters are 4,15109 4,123061 + Start of the optimization 1 : + The number of iterations is 31 + The value of the marginal posterior function is -147,2549 + Optimized range parameters are 36,89036 184,8898 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,5781618 0,5742579 + Start of the optimization 2 : + The number of iterations is 18 + The value of the marginal posterior function is -147,2555 + Optimized range parameters are 36,87001 184,82 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 166,9279 165,8008 + The initial values of range parameters are 3,338559 3,316015 + Start of the optimization 1 : + The number of iterations is 24 + The value of the marginal posterior function is -146,0908 + Optimized range parameters are 34,10173 165,8008 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5697827 0,5659353 + Start of the optimization 2 : + The number of iterations is 12 + The value of the marginal posterior function is -146,091 + Optimized range parameters are 34,11888 165,8008 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 164,9351 163,8214 + The initial values of range parameters are 3,298703 3,276429 + Start of the optimization 1 : + The number of iterations is 29 + The value of the marginal posterior function is -144,8362 + Optimized range parameters are 33,02363 163,8214 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5616429 0,5578505 + Start of the optimization 2 : + The number of iterations is 15 + The value of the marginal posterior function is -144,8366 + Optimized range parameters are 32,96846 163,8214 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 161,9899 160,8961 + The initial values of range parameters are 3,239799 3,217922 + Start of the optimization 1 : + The number of iterations is 30 + The value of the marginal posterior function is -143,1679 + Optimized range parameters are 32,60853 160,8961 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5537325 0,5499935 + Start of the optimization 2 : + The number of iterations is 23 + The value of the marginal posterior function is -143,1673 + Optimized range parameters are 32,60514 160,8961 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 167,4923 166,3613 + The initial values of range parameters are 3,349846 3,327227 + Start of the optimization 1 : + The number of iterations is 31 + The value of the marginal posterior function is -141,4524 + Optimized range parameters are 32,84554 166,3613 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5460417 0,5423547 + Start of the optimization 2 : + The number of iterations is 10 + The value of the marginal posterior function is -141,4531 + Optimized range parameters are 32,87053 166,3613 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 158,1908 157,1226 + The initial values of range parameters are 3,163815 3,142452 + Start of the optimization 1 : + The number of iterations is 21 + The value of the marginal posterior function is -140,039 + Optimized range parameters are 31,62214 157,1226 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5385617 0,5349251 + Start of the optimization 2 : + The number of iterations is 16 + The value of the marginal posterior function is -140,0387 + Optimized range parameters are 31,62433 157,1226 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 174,0066 172,8316 + The initial values of range parameters are 3,480131 3,456632 + Start of the optimization 1 : + The number of iterations is 23 + The value of the marginal posterior function is -138,1222 + Optimized range parameters are 33,48823 172,8316 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5312838 0,5276964 + Start of the optimization 2 : + The number of iterations is 28 + The value of the marginal posterior function is -138,1223 + Optimized range parameters are 33,40525 172,8316 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 150,4312 149,4154 + The initial values of range parameters are 3,008624 2,988309 + Start of the optimization 1 : + The number of iterations is 21 + The value of the marginal posterior function is -139,2082 + Optimized range parameters are 30,85041 149,4154 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,5242001 0,5206605 + Start of the optimization 2 : + The number of iterations is 25 + The value of the marginal posterior function is -139,2085 + Optimized range parameters are 30,93585 149,4154 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 163,2096 162,1076 + The initial values of range parameters are 3,264193 3,242152 + Start of the optimization 1 : + The number of iterations is 30 + The value of the marginal posterior function is -136,829 + Optimized range parameters are 31,64889 162,1076 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5173027 0,5138097 + Start of the optimization 2 : + The number of iterations is 29 + The value of the marginal posterior function is -136,8292 + Optimized range parameters are 31,73272 162,1076 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 155,3651 154,316 + The initial values of range parameters are 3,107301 3,08632 + Start of the optimization 1 : + The number of iterations is 38 + The value of the marginal posterior function is -137,2507 + Optimized range parameters are 31,11748 154,316 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5105845 0,5071368 + Start of the optimization 2 : + The number of iterations is 11 + The value of the marginal posterior function is -137,2507 + Optimized range parameters are 31,11466 154,316 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 159,0334 157,9595 + The initial values of range parameters are 3,180667 3,15919 + Start of the optimization 1 : + The number of iterations is 19 + The value of the marginal posterior function is -134,9592 + Optimized range parameters are 30,6283 157,9595 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,5040385 0,5006351 + Start of the optimization 2 : + The number of iterations is 20 + The value of the marginal posterior function is -134,9589 + Optimized range parameters are 30,62948 157,9595 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 150,6829 149,6655 + The initial values of range parameters are 3,013659 2,993309 + Start of the optimization 1 : + The number of iterations is 9 + The value of the marginal posterior function is -133,0322 + Optimized range parameters are 28,62106 149,6655 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4976583 0,4942979 + Start of the optimization 2 : + The number of iterations is 27 + The value of the marginal posterior function is -133,0311 + Optimized range parameters are 28,6202 149,6655 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 143,0785 142,1124 + The initial values of range parameters are 2,86157 2,842247 + Start of the optimization 1 : + The number of iterations is 27 + The value of the marginal posterior function is -131,5134 + Optimized range parameters are 27,05986 142,1124 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,4914376 0,4881192 + Start of the optimization 2 : + The number of iterations is 28 + The value of the marginal posterior function is -131,5142 + Optimized range parameters are 27,09861 142,1124 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 149,9901 148,9774 + The initial values of range parameters are 2,999803 2,979547 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -128,3138 + Optimized range parameters are 26,94379 148,9774 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4853704 0,482093 + Start of the optimization 2 : + The number of iterations is 11 + The value of the marginal posterior function is -128,3136 + Optimized range parameters are 26,93153 148,9774 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 141,9733 141,0146 + The initial values of range parameters are 2,839465 2,820292 + Start of the optimization 1 : + The number of iterations is 15 + The value of the marginal posterior function is -126,565 + Optimized range parameters are 25,84325 141,0146 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4794513 0,4762139 + Start of the optimization 2 : + The number of iterations is 30 + The value of the marginal posterior function is -126,5658 + Optimized range parameters are 25,84843 141,0146 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 148,4124 147,4103 + The initial values of range parameters are 2,968249 2,948206 + Start of the optimization 1 : + The number of iterations is 14 + The value of the marginal posterior function is -123,2249 + Optimized range parameters are 26,04536 147,4103 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4736748 0,4704763 + Start of the optimization 2 : + The number of iterations is 37 + The value of the marginal posterior function is -123,2255 + Optimized range parameters are 26,11794 147,4103 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 141,3136 140,3594 + The initial values of range parameters are 2,826273 2,807189 + Start of the optimization 1 : + The number of iterations is 24 + The value of the marginal posterior function is -121,373 + Optimized range parameters are 25,34355 140,3594 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,4680358 0,4648754 + Start of the optimization 2 : + The number of iterations is 27 + The value of the marginal posterior function is -121,3719 + Optimized range parameters are 25,3222 140,3594 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 146,0605 145,0743 + The initial values of range parameters are 2,921211 2,901486 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -119,1731 + Optimized range parameters are 25,38398 145,0743 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4625295 0,4594063 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -119,1742 + Optimized range parameters are 25,27086 145,0743 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 136,1432 135,2239 + The initial values of range parameters are 2,722864 2,704479 + Start of the optimization 1 : + The number of iterations is 16 + The value of the marginal posterior function is -117,4765 + Optimized range parameters are 23,8631 135,2239 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4571512 0,4540644 + Start of the optimization 2 : + The number of iterations is 31 + The value of the marginal posterior function is -117,4779 + Optimized range parameters are 23,87798 135,2239 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 121,8399 121,0172 + The initial values of range parameters are 2,436797 2,420343 + Start of the optimization 1 : + The number of iterations is 21 + The value of the marginal posterior function is -117,2996 + Optimized range parameters are 22,38443 121,0172 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,4518966 0,4488452 + Start of the optimization 2 : + The number of iterations is 19 + The value of the marginal posterior function is -117,2989 + Optimized range parameters are 22,37563 121,0172 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 123,1404 122,309 + The initial values of range parameters are 2,462809 2,446179 + Start of the optimization 1 : + The number of iterations is 18 + The value of the marginal posterior function is -114,6525 + Optimized range parameters are 22,32619 122,309 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4467614 0,4437447 + Start of the optimization 2 : + The number of iterations is 38 + The value of the marginal posterior function is -114,6523 + Optimized range parameters are 22,33099 122,309 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 117,4477 116,6546 + The initial values of range parameters are 2,348953 2,333092 + Start of the optimization 1 : + The number of iterations is 23 + The value of the marginal posterior function is -113,3472 + Optimized range parameters are 21,62668 116,6546 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,4417416 0,4387588 + Start of the optimization 2 : + The number of iterations is 28 + The value of the marginal posterior function is -113,3475 + Optimized range parameters are 21,65104 116,6546 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 115,2499 114,4717 + The initial values of range parameters are 2,304998 2,289433 + Start of the optimization 1 : + The number of iterations is 12 + The value of the marginal posterior function is -110,7155 + Optimized range parameters are 20,98512 114,4717 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4368334 0,4338837 + Start of the optimization 2 : + The number of iterations is 30 + The value of the marginal posterior function is -110,7149 + Optimized range parameters are 21,00228 114,4717 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 111,8946 111,139 + The initial values of range parameters are 2,237892 2,222781 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -108,5065 + Optimized range parameters are 20,44681 111,139 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,432033 0,4291158 + Start of the optimization 2 : + The number of iterations is 19 + The value of the marginal posterior function is -108,507 + Optimized range parameters are 20,44983 111,139 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 93,38518 92,75461 + The initial values of range parameters are 1,867704 1,855092 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -111,367 + Optimized range parameters are 18,37032 92,75461 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,427337 0,4244515 + Start of the optimization 2 : + The number of iterations is 18 + The value of the marginal posterior function is -111,3671 + Optimized range parameters are 18,37078 92,75461 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 99,64494 98,97211 + The initial values of range parameters are 1,992899 1,979442 + Start of the optimization 1 : + The number of iterations is 23 + The value of the marginal posterior function is -106,2562 + Optimized range parameters are 18,89163 98,97211 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,422742 0,4198875 + Start of the optimization 2 : + The number of iterations is 27 + The value of the marginal posterior function is -106,2561 + Optimized range parameters are 18,88065 98,97211 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 99,75194 99,07838 + The initial values of range parameters are 1,995039 1,981568 + Start of the optimization 1 : + The number of iterations is 17 + The value of the marginal posterior function is -103,2099 + Optimized range parameters are 18,65492 99,07838 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4182447 0,4154206 + Start of the optimization 2 : + The number of iterations is 27 + The value of the marginal posterior function is -103,2113 + Optimized range parameters are 18,65549 99,07838 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 104,3536 103,649 + The initial values of range parameters are 2,087073 2,07298 + Start of the optimization 1 : + The number of iterations is 20 + The value of the marginal posterior function is -98,42375 + Optimized range parameters are 18,87395 103,649 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4138422 0,4110477 + Start of the optimization 2 : + The number of iterations is 27 + The value of the marginal posterior function is -98,42241 + Optimized range parameters are 18,87764 103,649 + Optimized nugget parameter is 0 + Convergence: TRUE + The upper bounds of the range parameters are 103,1118 102,4155 + The initial values of range parameters are 2,062236 2,048311 + Start of the optimization 1 : + The number of iterations is 20 + The value of the marginal posterior function is -95,30729 + Optimized range parameters are 18,51323 102,4155 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,4095313 0,406766 + Start of the optimization 2 : + The number of iterations is 29 + The value of the marginal posterior function is -95,30714 + Optimized range parameters are 18,54824 102,4155 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 95,06543 94,42352 + The initial values of range parameters are 1,901309 1,88847 + Start of the optimization 1 : + The number of iterations is 14 + The value of the marginal posterior function is -95,1497 + Optimized range parameters are 17,52307 94,42352 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,4053093 0,4025725 + Start of the optimization 2 : + The number of iterations is 23 + The value of the marginal posterior function is -95,14898 + Optimized range parameters are 17,55379 94,42352 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 91,10625 90,49107 + The initial values of range parameters are 1,822125 1,809821 + Start of the optimization 1 : + The number of iterations is 21 + The value of the marginal posterior function is -93,31858 + Optimized range parameters are 16,88561 90,49107 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,4011735 0,3984647 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -93,31829 + Optimized range parameters are 16,83654 90,49107 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 95,06911 94,42717 + The initial values of range parameters are 1,901382 1,888543 + Start of the optimization 1 : + The number of iterations is 11 + The value of the marginal posterior function is -88,62383 + Optimized range parameters are 17,19113 94,42717 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 0,3971213 0,3944398 + Start of the optimization 2 : + The number of iterations is 23 + The value of the marginal posterior function is -88,62286 + Optimized range parameters are 17,21816 94,42717 + Optimized nugget parameter is 0 + Convergence: FALSE + The upper bounds of the range parameters are 84,25512 83,6862 + The initial values of range parameters are 1,685102 1,673724 + Start of the optimization 1 : + The number of iterations is 20 + The value of the marginal posterior function is -90,56369 + Optimized range parameters are 16,01921 83,6862 + Optimized nugget parameter is 0 + Convergence: FALSE + The initial values of range parameters are 0,39315 0,3904954 + Start of the optimization 2 : + The number of iterations is 24 + The value of the marginal posterior function is -90,56328 + Optimized range parameters are 16,0189 83,6862 + Optimized nugget parameter is 0 + Convergence: FALSE + + + + +.. GENERATED FROM PYTHON SOURCE LINES 92-100 + +Once the active learning process is finished, we obtain the final emulator for the +logarithm of the unnormalized posterior, which is given by the +:py:meth:`.ActiveLearning.approx_ln_pxl` method. + +We can then estimate the posterior using grid estimation or Metropolis Hastings +estimation based on the emulator. An example is as follows. The contour plot shows +the estimated posterior. + + +.. GENERATED FROM PYTHON SOURCE LINES 101-127 + +.. code-block:: default + + from psimpy.inference import GridEstimation + import matplotlib.pyplot as plt + + grid_estimator = GridEstimation(ndim, bounds, ln_pxl=active_learner.approx_ln_pxl) + posterior, x_ndim = grid_estimator.run(nbins=50) + + fig, ax = plt.subplots(1,1,figsize=(5,4)) + + # initial training points + ax.scatter(init_var_samples[:,0], init_var_samples[:,1], s=10, c='r', marker='o', + zorder=1, alpha=0.8, label='initial training points') + # actively picked training points + ax.scatter(var_samples[n0:,0], var_samples[n0:,1], s=15, c='k', marker='+', + zorder=2, alpha=0.8, label='iterative training points') + + # estimated posterior based on the final emulator + posterior = np.where(posterior < 1e-10, None, posterior) + contour = ax.contour(x_ndim[0], x_ndim[1], np.transpose(posterior), levels=10, zorder=0) + plt.colorbar(contour, ax=ax) + + ax.legend() + ax.set_title('Active learning') + ax.set_xlabel('x1') + ax.set_ylabel('x2') + ax.set_xlim([-5,5]) + ax.set_ylim([-5,5]) + plt.tight_layout() + + +.. image-sg:: /auto_examples/inference/images/sphx_glr_plot_active_learning_001.png + :alt: Active learning + :srcset: /auto_examples/inference/images/sphx_glr_plot_active_learning_001.png + :class: sphx-glr-single-img + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 2 minutes 12.653 seconds) + + +.. _sphx_glr_download_auto_examples_inference_plot_active_learning.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_active_learning.py <plot_active_learning.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_active_learning.ipynb <plot_active_learning.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/inference/plot_bayes_inference.rst.txt b/docs/source/_build/html/_sources/auto_examples/inference/plot_bayes_inference.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8b71d72a0e03bd7ccb549b760d98186fea6e511 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/inference/plot_bayes_inference.rst.txt @@ -0,0 +1,231 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/inference/plot_bayes_inference.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_inference_plot_bayes_inference.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_inference_plot_bayes_inference.py: + + +Bayesian inference +================== + +.. GENERATED FROM PYTHON SOURCE LINES 8-16 + +This example shows how to perform Bayesian inference given the uniform prior + +:math:`p(\mathbf{x})=p(x_1,x_2)=0.01` + +where :math:`x_i \in [-5,5], i=1,2`, and likelihood + +:math:`L(\mathbf{x}|\mathbf{d})=\exp \left(-\frac{1}{100}\left(x_1-1\right)^2-\left(x_1^2-x_2\right)^2\right)`. + + +.. GENERATED FROM PYTHON SOURCE LINES 17-29 + +.. code-block:: default + + + import numpy as np + + ndim = 2 + bounds = np.array([[-5,5],[-5,5]]) + + def prior(x): + return 0.01 + + def likelihood(x): + return np.exp(-(x[0]-1)**2/100 - (x[0]**2-x[1])**2) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 30-33 + +To estimate the posterior using grid estimation, we need to import the +:class:`.GridEstimation` class, create an instance, and call the +:py:meth:`.GridEstimation.run` method. + +.. GENERATED FROM PYTHON SOURCE LINES 34-40 + +.. code-block:: default + + + from psimpy.inference.bayes_inference import GridEstimation + + grid_estimator = GridEstimation(ndim, bounds, prior, likelihood) + posterior, x_ndim = grid_estimator.run(nbins=[50,40]) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 41-43 + +The following figure plots the estimated posterior. + + +.. GENERATED FROM PYTHON SOURCE LINES 44-61 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + fig, ax = plt.subplots(1,1,figsize=(6,4)) + + # mask insignificant values + posterior = np.where(posterior < 1e-10, None, posterior) + + contour = ax.contour(x_ndim[0], x_ndim[1], np.transpose(posterior), levels=10) + plt.colorbar(contour, ax=ax) + ax.set_xlim(bounds[0,0], bounds[0,1]) + ax.set_ylim(bounds[1,0], bounds[1,1]) + ax.set_title('Grid estimation') + ax.set_xlabel('x1') + ax.set_ylabel('x2') + plt.tight_layout() + + + + +.. image-sg:: /auto_examples/inference/images/sphx_glr_plot_bayes_inference_001.png + :alt: Grid estimation + :srcset: /auto_examples/inference/images/sphx_glr_plot_bayes_inference_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 62-67 + +To estimate the posterior using Metropolis Hastings estimation, we need to import +the :class:`.MetropolisHastingsEstimation` class, create an instance, and call the +:py:meth:`.MetropolisHastingsEstimation.run` method. The +:py:meth:`.MetropolisHastingsEstimation.run` method has a parameter, ``mh_sampler``, +which takes an instance of :class:`.MetropolisHastings` as argument. + +.. GENERATED FROM PYTHON SOURCE LINES 68-92 + +.. code-block:: default + + + from psimpy.inference.bayes_inference import MetropolisHastingsEstimation + + mh_estimator = MetropolisHastingsEstimation(ndim, bounds, prior, likelihood) + + # create a mh_sampler + from psimpy.sampler.metropolis_hastings import MetropolisHastings + from scipy.stats import multivariate_normal + + init_state = np.array([-4,-4]) + f_sample = multivariate_normal.rvs + nburn = 100 + nthin = 10 + seed = 1 + kwgs_f_sample = {'random_state': np.random.default_rng(seed)} + + mh_sampler = MetropolisHastings(ndim=ndim, init_state=init_state, + f_sample=f_sample, bounds=bounds, nburn=nburn, nthin=nthin, seed=seed, + kwgs_f_sample=kwgs_f_sample) + + nsamples = 5000 + mh_samples, mh_accept = mh_estimator.run(nsamples, mh_sampler) + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 93-96 + +The following figure plots the samples drawn from the unnormalized posterior, +which can be used to estimate the posterior and its poperties. + + +.. GENERATED FROM PYTHON SOURCE LINES 97-110 + +.. code-block:: default + + import matplotlib.pyplot as plt + + fig, ax = plt.subplots(1,1,figsize=(5,4)) + + ax.scatter(mh_samples[:,0], mh_samples[:,1], s=10, c='r', marker='o', alpha=0.1) + ax.set_xlim(bounds[0,0], bounds[0,1]) + ax.set_ylim(bounds[1,0], bounds[1,1]) + ax.set_title('MH estimation') + ax.set_xlabel('x1') + ax.set_ylabel('x2') + plt.tight_layout() + + + + + +.. image-sg:: /auto_examples/inference/images/sphx_glr_plot_bayes_inference_002.png + :alt: MH estimation + :srcset: /auto_examples/inference/images/sphx_glr_plot_bayes_inference_002.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 111-116 + +.. note:: Besides ``prior`` and ``likelihood``, one can also instantiate + the :class:`.MetropolisHastingsEstimation` class with + + - ``ln_prior`` and ``ln_likelihood``: Natural logarithm of ``prior`` and ``likelihood``. + - ``ln_pxl``: Natural logarithm of the product of ``prior`` and ``likelihood``. + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 9.739 seconds) + + +.. _sphx_glr_download_auto_examples_inference_plot_bayes_inference.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_bayes_inference.py <plot_bayes_inference.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_bayes_inference.ipynb <plot_bayes_inference.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/inference/sg_execution_times.rst.txt b/docs/source/_build/html/_sources/auto_examples/inference/sg_execution_times.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f6c429bc973dbb94d386ed5a8e23c893e3cb447 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/inference/sg_execution_times.rst.txt @@ -0,0 +1,14 @@ + +:orphan: + +.. _sphx_glr_auto_examples_inference_sg_execution_times: + +Computation times +================= +**02:22.392** total execution time for **auto_examples_inference** files: + ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_inference_plot_active_learning.py` (``plot_active_learning.py``) | 02:12.653 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_inference_plot_bayes_inference.py` (``plot_bayes_inference.py``) | 00:09.739 | 0.0 MB | ++-----------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/source/_build/html/_sources/auto_examples/sampler/index.rst.txt b/docs/source/_build/html/_sources/auto_examples/sampler/index.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..619204513146bda20b6ae5e0d36c3026f7b8c869 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sampler/index.rst.txt @@ -0,0 +1,93 @@ +:orphan: + +Sampler +======= + + +.. raw:: html + + <div class="sphx-glr-thumbnails"> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Saltelli sampling"> + +.. only:: html + + .. image:: /auto_examples/sampler/images/thumb/sphx_glr_plot_saltelli_thumb.png + :alt: Saltelli sampling + + :ref:`sphx_glr_auto_examples_sampler_plot_saltelli.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Saltelli sampling</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Latin hypercube sampling"> + +.. only:: html + + .. image:: /auto_examples/sampler/images/thumb/sphx_glr_plot_latin_thumb.png + :alt: Latin hypercube sampling + + :ref:`sphx_glr_auto_examples_sampler_plot_latin.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Latin hypercube sampling</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Metropolis Hastings sampling"> + +.. only:: html + + .. image:: /auto_examples/sampler/images/thumb/sphx_glr_plot_metropolis_hastings_thumb.png + :alt: Metropolis Hastings sampling + + :ref:`sphx_glr_auto_examples_sampler_plot_metropolis_hastings.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Metropolis Hastings sampling</div> + </div> + + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/sampler/plot_saltelli + /auto_examples/sampler/plot_latin + /auto_examples/sampler/plot_metropolis_hastings + + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-gallery + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download all examples in Python source code: sampler_python.zip </auto_examples/sampler/sampler_python.zip>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download all examples in Jupyter notebooks: sampler_jupyter.zip </auto_examples/sampler/sampler_jupyter.zip>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/sampler/plot_latin.rst.txt b/docs/source/_build/html/_sources/auto_examples/sampler/plot_latin.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c1fd9079b86df82f79bd7a3dbc2ee6ee592034d --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sampler/plot_latin.rst.txt @@ -0,0 +1,209 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/sampler/plot_latin.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_sampler_plot_latin.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_sampler_plot_latin.py: + + +Latin hypercube sampling +======================== + +.. GENERATED FROM PYTHON SOURCE LINES 8-11 + +This example shows how to draw samples using Latin hypercube sampling. + + + +.. GENERATED FROM PYTHON SOURCE LINES 14-17 + +For the illustration purpose, let's have a look at a two-dimensional example +where we have two random variables X and Y. Each is uniformly distributed in its +range. + +.. GENERATED FROM PYTHON SOURCE LINES 18-25 + +.. code-block:: default + + + import numpy as np + + ndim = 2 + # range of X is 10 to 20, range of Y is -10 to 0 + bounds = np.array([[10,20], [-10,0]]) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 26-28 + +Given this setting, we can import :class:`.Latin`, create an instance, and +call the :py:meth:`.Latin.sample` method to draw required number of samples + +.. GENERATED FROM PYTHON SOURCE LINES 29-36 + +.. code-block:: default + + + from psimpy.sampler import LHS + + # setting seed leads to same samples every time when the codes are run + lhs_sampler = LHS(ndim, bounds, seed=10) + lhs_samples = lhs_sampler.sample(nsamples=5) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 37-38 + +The samples are plotted in the following figure. + +.. GENERATED FROM PYTHON SOURCE LINES 39-54 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + fig , ax = plt.subplots(figsize=(6,4)) + + ax.scatter(lhs_samples[:,0], lhs_samples[:,1], s=10, c='blue', marker='o') + + ax.set_xlabel('X') + ax.set_ylabel('Y') + ax.set_xlim(bounds[0]) + ax.set_ylim(bounds[1]) + ax.set_title("Latin hypercube samples (criterion='random')") + _ = ax.grid(visible=True, which='major', axis='both') + + + + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_latin_001.png + :alt: Latin hypercube samples (criterion='random') + :srcset: /auto_examples/sampler/images/sphx_glr_plot_latin_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 55-58 + +There are different criterions to pick samples in each hypercube. The default +is `random`, as used above. Other options are `center` and `maximin`. For instance, +we can use the `center` criterion to draw :math:`5` samples as follows: + +.. GENERATED FROM PYTHON SOURCE LINES 59-75 + +.. code-block:: default + + + lhs_sampler = LHS(ndim, bounds, criterion='center', seed=10) + lhs_samples = lhs_sampler.sample(nsamples=5) + + fig , ax = plt.subplots(figsize=(6,4)) + + ax.scatter(lhs_samples[:,0], lhs_samples[:,1], s=10, c='blue', marker='o') + + ax.set_xlabel('X') + ax.set_ylabel('Y') + ax.set_xlim(bounds[0]) + ax.set_ylim(bounds[1]) + ax.set_title("Latin hypercube samples (criterion='center')") + _ = ax.grid(visible=True, which='major', axis='both') + + + + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_latin_002.png + :alt: Latin hypercube samples (criterion='center') + :srcset: /auto_examples/sampler/images/sphx_glr_plot_latin_002.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 76-77 + +And we can use the `maximin` criterion as follows: + +.. GENERATED FROM PYTHON SOURCE LINES 78-91 + +.. code-block:: default + + + lhs_sampler = LHS(ndim, bounds, criterion='maximin', seed=10, iteration=500) + lhs_samples = lhs_sampler.sample(nsamples=5) + + fig , ax = plt.subplots(figsize=(6,4)) + + ax.scatter(lhs_samples[:,0], lhs_samples[:,1], s=10, c='blue', marker='o') + + ax.set_xlabel('X') + ax.set_ylabel('Y') + ax.set_xlim(bounds[0]) + ax.set_ylim(bounds[1]) + ax.set_title("Latin hypercube samples (criterion='maximin')") + _ = ax.grid(visible=True, which='major', axis='both') + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_latin_003.png + :alt: Latin hypercube samples (criterion='maximin') + :srcset: /auto_examples/sampler/images/sphx_glr_plot_latin_003.png + :class: sphx-glr-single-img + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.270 seconds) + + +.. _sphx_glr_download_auto_examples_sampler_plot_latin.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_latin.py <plot_latin.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_latin.ipynb <plot_latin.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/sampler/plot_metropolis_hastings.rst.txt b/docs/source/_build/html/_sources/auto_examples/sampler/plot_metropolis_hastings.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..41772d32226b84f57b1d76e28334ee33622fa404 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sampler/plot_metropolis_hastings.rst.txt @@ -0,0 +1,248 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/sampler/plot_metropolis_hastings.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_sampler_plot_metropolis_hastings.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_sampler_plot_metropolis_hastings.py: + + +Metropolis Hastings sampling +============================ + +.. GENERATED FROM PYTHON SOURCE LINES 8-22 + +This example shows how to draw samples using Metropolis Hastings sampling. +The target probability distribution is + +:math:`p(\mathbf{x})=p(x_1, x_2) \propto \exp \left(-\frac{1}{100}\left(x_1-1\right)^2-\left(x_1^2-x_2\right)^2\right)` + +where :math:`x_1 \in [-5,5]` and :math:`x_2 \in [-5,5]`. + +It should be noted that the right hand side of the equation is an unnormalized +probability density function since its integral is not equal to :math:`1`. +This can happen, for example, when the normalization constant is unknown or difficult +to compute. + +We can define the target probability distribution in Python as follows: + + +.. GENERATED FROM PYTHON SOURCE LINES 23-32 + +.. code-block:: default + + + import numpy as np + + def target_dist(x): + if (x[0]>=-5 and x[0]<=5) and (x[1]>=-5 and x[1]<=5): + return np.exp(-0.01*(x[0]-1)**2 - (x[0]**2-x[1])**2) + else: + return 0 + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 33-34 + +The figure below shows how the target distribution looks like. + +.. GENERATED FROM PYTHON SOURCE LINES 35-60 + +.. code-block:: default + + + import matplotlib.pyplot as plt + import itertools + + x1_values = np.linspace(-5,5.1,100) + x2_values = np.linspace(-5,5.1,100) + + target_values = np.zeros((100, 100)) + for i, j in itertools.product(range(100), range(100)): + x1 = x1_values[i] + x2 = x2_values[j] + target_values[i,j] = target_dist(np.array([x1, x2])) + + fig , ax = plt.subplots(figsize=(4,4)) + + ax.contourf(x1_values, x2_values, np.transpose(target_values), levels=10, cmap='Blues') + + ax.set_title('(unnormalized) target distribution') + ax.set_xlabel(r'$x_1$') + ax.set_ylabel(r'$x_2$') + ax.set_xlim(-5,5) + ax.set_ylim(-5,5) + plt.tight_layout() + + + + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_metropolis_hastings_001.png + :alt: (unnormalized) target distribution + :srcset: /auto_examples/sampler/images/sphx_glr_plot_metropolis_hastings_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 61-67 + +To perform Metropolis Hastings sampling, we need to choose a proposal distribution +which can be used to determine a new state ``x'`` given a current state ``x`` at +each iteration. This is defined by the parameter ``f_sample`` which should be a +function. A usual choice is to choose the new state from a Gaussian distribution +centered at the current state. + + +.. GENERATED FROM PYTHON SOURCE LINES 68-75 + +.. code-block:: default + + + from scipy.stats import multivariate_normal + + f_sample = multivariate_normal.rvs + # make the samples reproducible + kwgs_f_sample = {'random_state': np.random.default_rng(seed=1)} + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 76-77 + +Then, we create an instance of :class:`.MetropolisHastings` class. + +.. GENERATED FROM PYTHON SOURCE LINES 78-85 + +.. code-block:: default + + + from psimpy.sampler.metropolis_hastings import MetropolisHastings + + mh_sampler = MetropolisHastings(ndim=2, init_state=np.array([-4,-4]), + f_sample=f_sample, target=target_dist, nburn=1000, nthin=5, + seed=1, kwgs_f_sample=kwgs_f_sample) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 86-88 + +Next, we call the :py:meth:`.MetropolisHastings.sample` method to draw required +number of samples. + +.. GENERATED FROM PYTHON SOURCE LINES 89-95 + +.. code-block:: default + + + mh_samples, mh_accept = mh_sampler.sample(nsamples=5000) + + print("Acceptance ratio: ", np.mean(mh_accept)) + + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Acceptance ratio: 0.3712 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 96-97 + +The following figure shows how the samples look like. + +.. GENERATED FROM PYTHON SOURCE LINES 98-117 + +.. code-block:: default + + + import matplotlib.pyplot as plt + import itertools + + # sphinx_gallery_thumbnail_number = 2 + fig , ax = plt.subplots(figsize=(4,4)) + + ax.contourf(x1_values, x2_values, np.transpose(target_values), levels=10, cmap='Blues') + ax.scatter(mh_samples[:,0], mh_samples[:,1], s=5, c='r', marker='o',alpha=0.05) + + ax.set_title('Metropolis Hastings samples') + ax.set_xlabel(r'$x_1$') + ax.set_ylabel(r'$x_2$') + ax.set_xlim(-5,5) + ax.set_ylim(-5,5) + plt.tight_layout() + + + + + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_metropolis_hastings_002.png + :alt: Metropolis Hastings samples + :srcset: /auto_examples/sampler/images/sphx_glr_plot_metropolis_hastings_002.png + :class: sphx-glr-single-img + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 4.769 seconds) + + +.. _sphx_glr_download_auto_examples_sampler_plot_metropolis_hastings.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_metropolis_hastings.py <plot_metropolis_hastings.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_metropolis_hastings.ipynb <plot_metropolis_hastings.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/sampler/plot_saltelli.rst.txt b/docs/source/_build/html/_sources/auto_examples/sampler/plot_saltelli.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..8204636df656eac3d1f3ea8fedef983c4e56f1a8 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sampler/plot_saltelli.rst.txt @@ -0,0 +1,193 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/sampler/plot_saltelli.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_sampler_plot_saltelli.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_sampler_plot_saltelli.py: + + +Saltelli sampling +================= + +.. GENERATED FROM PYTHON SOURCE LINES 8-11 + +This example shows how to draw samples using Saltelli sampling. +Assume that there is a three-dimensional problem where X, Y, and Z are the +three random variables. + +.. GENERATED FROM PYTHON SOURCE LINES 12-19 + +.. code-block:: default + + + import numpy as np + + ndim = 3 + # range of X is 10 to 20, range of Y is 100 to 200, range of Z is 1000 to 2000 + bounds = np.array([[10,20], [100,200], [1000,2000]]) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 20-22 + +Given this setting, we can import :class:`.Saltelli`, create an instance, and +call the :py:meth:`.Saltelli.sample` method to draw required number of samples. + +.. GENERATED FROM PYTHON SOURCE LINES 23-29 + +.. code-block:: default + + + from psimpy.sampler import Saltelli + + saltelli_sampler = Saltelli(ndim, bounds, calc_second_order=False) + saltelli_samples = saltelli_sampler.sample(nbase=128) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 30-34 + +In above codes, we set ``calc_second_order`` to `False`. It means that picked +samples can be used in following Sobol' analysis to compute first-order and +total-effect Sobol' indices but not second-order Sobol' indices. It leads to +:math:`nbase*(ndim+2)` samples as shown below + +.. GENERATED FROM PYTHON SOURCE LINES 35-51 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + fig = plt.figure() + ax = fig.add_subplot(projection='3d') + + ax.scatter(saltelli_samples[:,0], saltelli_samples[:,1], saltelli_samples[:,2], marker='o') + ax.set_xlabel('X') + ax.set_ylabel('Y') + ax.set_zlabel('Z') + + plt.tight_layout() + + print('Number of samples: ', f'{len(saltelli_samples)}') + + + + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_saltelli_001.png + :alt: plot saltelli + :srcset: /auto_examples/sampler/images/sphx_glr_plot_saltelli_001.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Number of samples: 640 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 52-55 + +If we want to draw samples which can also be used to compute second-order +Sobol' indices, we need to set ``calc_second_order`` to `True`. +It leads to :math:`nbase*(2*ndim+2)` samples. + +.. GENERATED FROM PYTHON SOURCE LINES 56-73 + +.. code-block:: default + + + saltelli_sampler = Saltelli(ndim, bounds, calc_second_order=True) + saltelli_samples = saltelli_sampler.sample(nbase=128) + + fig = plt.figure() + ax = fig.add_subplot(projection='3d') + + ax.scatter(saltelli_samples[:,0], saltelli_samples[:,1], saltelli_samples[:,2], marker='o') + ax.set_xlabel('X') + ax.set_ylabel('Y') + ax.set_zlabel('Z') + + plt.tight_layout() + + print('Number of samples: ', f'{len(saltelli_samples)}') + + + + + +.. image-sg:: /auto_examples/sampler/images/sphx_glr_plot_saltelli_002.png + :alt: plot saltelli + :srcset: /auto_examples/sampler/images/sphx_glr_plot_saltelli_002.png + :class: sphx-glr-single-img + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Number of samples: 1024 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 74-78 + +.. note:: If one has a two-dimensional problem, there is no need to set + ``calc_second_order`` to `True`. The reason is that the second-order Sobol' + index can be directly computed based on the first-order and total-effect + Sobol' index in that case. + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 0.309 seconds) + + +.. _sphx_glr_download_auto_examples_sampler_plot_saltelli.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_saltelli.py <plot_saltelli.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_saltelli.ipynb <plot_saltelli.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/sampler/sg_execution_times.rst.txt b/docs/source/_build/html/_sources/auto_examples/sampler/sg_execution_times.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f0d6099dbb428a524c8b6f38db41d5315529b30 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sampler/sg_execution_times.rst.txt @@ -0,0 +1,16 @@ + +:orphan: + +.. _sphx_glr_auto_examples_sampler_sg_execution_times: + +Computation times +================= +**00:05.348** total execution time for **auto_examples_sampler** files: + ++-----------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_sampler_plot_metropolis_hastings.py` (``plot_metropolis_hastings.py``) | 00:04.769 | 0.0 MB | ++-----------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_sampler_plot_saltelli.py` (``plot_saltelli.py``) | 00:00.309 | 0.0 MB | ++-----------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_sampler_plot_latin.py` (``plot_latin.py``) | 00:00.270 | 0.0 MB | ++-----------------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/source/_build/html/_sources/auto_examples/sensitivity/index.rst.txt b/docs/source/_build/html/_sources/auto_examples/sensitivity/index.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..7275650414dd97a8cbfb7587bf523737ce6d20b8 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sensitivity/index.rst.txt @@ -0,0 +1,57 @@ +:orphan: + +Sensitivity +=========== + + +.. raw:: html + + <div class="sphx-glr-thumbnails"> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Sobol' analysis"> + +.. only:: html + + .. image:: /auto_examples/sensitivity/images/thumb/sphx_glr_plot_sobol_analyze_thumb.png + :alt: Sobol' analysis + + :ref:`sphx_glr_auto_examples_sensitivity_plot_sobol_analyze.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Sobol' analysis</div> + </div> + + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/sensitivity/plot_sobol_analyze + + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-gallery + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download all examples in Python source code: sensitivity_python.zip </auto_examples/sensitivity/sensitivity_python.zip>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download all examples in Jupyter notebooks: sensitivity_jupyter.zip </auto_examples/sensitivity/sensitivity_jupyter.zip>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/sensitivity/plot_sobol_analyze.rst.txt b/docs/source/_build/html/_sources/auto_examples/sensitivity/plot_sobol_analyze.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..4309db956f8c6955cf2df99e0710b84a94ad0ac8 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sensitivity/plot_sobol_analyze.rst.txt @@ -0,0 +1,358 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/sensitivity/plot_sobol_analyze.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_sensitivity_plot_sobol_analyze.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_sensitivity_plot_sobol_analyze.py: + + +Sobol' analysis +=============== + +.. GENERATED FROM PYTHON SOURCE LINES 8-16 + +This example shows how to compute Sobol' sensitivity indices using +the :class:`.SobolAnalyze` class. + +Let us consider the Ishigami function :cite:p:`LeGratiet2014` + +:math:`y=f\left(x_1, x_2, x_3\right)=\sin \left(x_1\right)+7 \sin \left(\mathrm{x}_2\right)^2+0.1 x_3^4 \sin \left(x_1\right)` + +where :math:`x_i` is uniformly distributed on :math:`[-\pi, \pi]` for :math:`i \in [1,2,3]`. We define the function as follows: + +.. GENERATED FROM PYTHON SOURCE LINES 17-24 + +.. code-block:: default + + + import numpy as np + + def f(x1,x2,x3): + return np.sin(x1) + 7*np.sin(x2)**2 + 0.1*x3**4*np.sin(x1) + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 25-32 + +The variation of each :math:`x_i` leads to the variation of :math:`y`. Sobol' analysis is used to quantify the contribution +of each :math:`x_i` and their interactions to the variation of :math:`y`. Steps of a Sobol' analysis are: + + #. Draw samples of input. + #. Evaluate the model at each input sample to obtain model output. + #. Compute Sobol' indices based on model outputs. + + +.. GENERATED FROM PYTHON SOURCE LINES 33-57 + +.. code-block:: default + + + from psimpy.sampler import Saltelli + from psimpy.sensitivity import SobolAnalyze + + ndim = 3 + bounds = np.array([[-np.pi, np.pi], [-np.pi, np.pi], [-np.pi, np.pi]]) + calc_second_order = False + nbase = 1024 + + # draw Saltelli samples + saltelli_sampler = Saltelli(ndim, bounds, calc_second_order) + saltelli_samples = saltelli_sampler.sample(nbase) + + # Evaluate the model to obtain model outputs + Y = f(saltelli_samples[:,0], saltelli_samples[:,1], saltelli_samples[:, 2]) + + # Compute Sobol' indices + sobol_analyzer = SobolAnalyze(ndim, Y, calc_second_order, seed=2) + S_res = sobol_analyzer.run() + + print("Estimated first-order Sobol' index: ", S_res['S1'][:,0]) + print("Analytical solution: [0.314, 0.442, 0]") + + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Estimated first-order Sobol' index: [0.31430871 0.44545644 0.01325799] + Analytical solution: [0.314, 0.442, 0] + + + + +.. GENERATED FROM PYTHON SOURCE LINES 58-62 + +Figure below shows the results. The bar plots represent estimated first-order +and total-effect Sobol' indices, as well as their 95% confidence interval. The +red stars represent true values of the first-order Sobol' indices. + + +.. GENERATED FROM PYTHON SOURCE LINES 63-103 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + name_vars = [r'$x_1$',r'$x_2$',r'$x_3$'] + x = {'S1':[1,4,7], 'ST':[2,5,8]} + color = {'S1':'#69b3a2', 'ST':'#3399e6'} + width=0.8 + capsize=3 + + fig, ax1 = plt.subplots(figsize=(4,3)) + + # estimated first-order Sobol' indices and their confidence interval + ax1.bar(x['S1'], S_res['S1'][:,0], width=width, yerr=S_res['S1'][:,2], color=color['S1'], capsize=capsize) + + ax1.axis([0,9,0,0.7]) + ax1.set_xticks([1.5,4.5,7.5]) + ax1.set_xticklabels(name_vars) + ax1.tick_params(axis='both',bottom=False) + ax1.tick_params(axis="y", labelcolor=color['S1']) + ax1.yaxis.grid(True, linestyle='--', which='major', color='grey', alpha=.25) + ax1.set_ylabel('First-order index', color=color['S1']) + + # analytical solution for first-order indices + ax1.scatter(x['S1'], [0.314, 0.442, 0], s=30, c='red', marker='*') + + + # estimated total-effect Sobol' indices and their confidence interval + ax2 = ax1.twinx() + ax2.bar(x['ST'], S_res['ST'][:,0], width=width, yerr=S_res['ST'][:,2], color=color['ST'], capsize=capsize) + + ax2.axis([0,9,0,0.7]) + ax2.set_xticks([1.5,4.5,7.5]) + ax2.tick_params(axis='both',bottom=False) + ax2.tick_params(axis="y", labelcolor=color['ST']) + ax2.yaxis.grid(True, linestyle='--', which='major', color='grey', alpha=.25) + ax2.set_ylabel('Total-effect index', color=color['ST']) + + plt.tight_layout() + + + + + +.. image-sg:: /auto_examples/sensitivity/images/sphx_glr_plot_sobol_analyze_001.png + :alt: plot sobol analyze + :srcset: /auto_examples/sensitivity/images/sphx_glr_plot_sobol_analyze_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 104-109 + +.. note:: The interaction between one parameter and all other parameters can be + quantified by the difference between its first-order and total-effet Sobol' + indices. If detailed information on interaction between any two parameters + is needed, one can set ``calc_second_order`` to `True`. + + +.. GENERATED FROM PYTHON SOURCE LINES 112-128 + +**Many models of interest in real-world applications are very computationally +expensive. In that case, we resort to emulation techniques in order to efficiently +conduct Sobol' analysis.** See :cite:t:`Zhao2021a` for the detailed theory. + +Steps of such an analysis are: + + #. Draw input samples for emulator training. + #. Evaluate the model at each training input point to obtain training data. + #. Train an emulator for the computationally expensive model of interest. + #. Draw samples of input for Sobol' analysis. + #. Evaluate the emulator at each input sample at step 3 to obtain approximated model outputs. + #. Compute Sobol' indices based on approximated model outputs. + +Assume that the above Ishigami function is computationally expensive, an emulator-based +Sobol' analysis can be conducted as follows: + + +.. GENERATED FROM PYTHON SOURCE LINES 129-178 + +.. code-block:: default + + + import numpy as np + from psimpy.sampler import LHS + from psimpy.emulator import ScalarGaSP + from psimpy.sampler import Saltelli + from psimpy.sensitivity import SobolAnalyze + + # define the model + def f(x1,x2,x3): + return np.sin(x1) + 7*np.sin(x2)**2 + 0.1*x3**4*np.sin(x1) + + ndim = 3 + bounds = np.array([[-np.pi, np.pi], [-np.pi, np.pi], [-np.pi, np.pi]]) + seed = 2 + + # draw 100 input samples for emulator training using Latin hypercube sampling + lhs_sampler = LHS(ndim, bounds, seed, criterion='maximin', iteration=200) + design = lhs_sampler.sample(nsamples=100) + + # evaluate the model at each training input point + response = f(design[:,0], design[:,1], design[:,2]) + + # train an emulator + scalar_gasp = ScalarGaSP(ndim) + scalar_gasp.train(design, response) + + # the trained emulator needs to be validated before moving on + # here we leave out this step for simplicity... + + # draw samples of input for Sobol' analysis + calc_second_order = False + nbase = 1024 + + saltelli_sampler = Saltelli(ndim, bounds, calc_second_order) + saltelli_samples = saltelli_sampler.sample(nbase) + + # evaluate the emulator to obtain approximated model output. + # in order to take emulator-induced uncertainty into account, we draw 50 realizations + # from the emulator + Y = scalar_gasp.sample(saltelli_samples, 50) + + # Compute Sobol' indices based on approximated model outputs + sobol_analyzer = SobolAnalyze(ndim, Y, calc_second_order, seed=seed) + S_res = sobol_analyzer.run(mode='parallel', max_workers=5) + + print("\n") + print("Emulator-based first-order Sobol' index: ", S_res['S1'][:,0]) + print("Analytical solution: [0.314, 0.442, 0]") + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + The upper bounds of the range parameters are 173,6849 174,6991 174,3157 + The initial values of range parameters are 3,473697 3,493981 3,486314 + Start of the optimization 1 : + The number of iterations is 14 + The value of the marginal posterior function is -284,0714 + Optimized range parameters are 3,183999 2,786247 4,315419 + Optimized nugget parameter is 0 + Convergence: TRUE + The initial values of range parameters are 1,721972 1,732027 1,728226 + Start of the optimization 2 : + The number of iterations is 14 + The value of the marginal posterior function is -284,0714 + Optimized range parameters are 3,183999 2,786247 4,315419 + Optimized nugget parameter is 0 + Convergence: TRUE + + + Emulator-based first-order Sobol' index: [0.29064086 0.46853437 0.01096656] + Analytical solution: [0.314, 0.442, 0] + + + + +.. GENERATED FROM PYTHON SOURCE LINES 179-182 + +The following figure shows how the results of emulator-based Sobol' analysis +look like. + + +.. GENERATED FROM PYTHON SOURCE LINES 182-213 + +.. code-block:: default + + + import matplotlib.pyplot as plt + + name_vars = [r'$x_1$',r'$x_2$',r'$x_3$'] + x = {'S1':[1,4,7], 'ST':[2,5,8]} + color = {'S1':'#69b3a2', 'ST':'#3399e6'} + width=0.8 + capsize=3 + + fig, ax1 = plt.subplots(figsize=(4,3)) + + ax1.bar(x['S1'], S_res['S1'][:,0], width=width, yerr=S_res['S1'][:,2], color=color['S1'], capsize=capsize) + ax1.axis([0,9,0,0.7]) + ax1.set_xticks([1.5,4.5,7.5]) + ax1.set_xticklabels(name_vars) + ax1.tick_params(axis='both',bottom=False) + ax1.tick_params(axis="y", labelcolor=color['S1']) + ax1.yaxis.grid(True, linestyle='--', which='major', color='grey', alpha=.25) + ax1.set_ylabel('First-order index', color=color['S1']) + + ax1.scatter(x['S1'], [0.314, 0.442, 0], s=30, c='red', marker='*') + + ax2 = ax1.twinx() + ax2.bar(x['ST'], S_res['ST'][:,0], width=width, yerr=S_res['ST'][:,2], color=color['ST'], capsize=capsize) + ax2.axis([0,9,0,0.7]) + ax2.set_xticks([1.5,4.5,7.5]) + ax2.tick_params(axis='both',bottom=False) + ax2.tick_params(axis="y", labelcolor=color['ST']) + ax2.yaxis.grid(True, linestyle='--', which='major', color='grey', alpha=.25) + ax2.set_ylabel('Total-effect index', color=color['ST']) + + plt.tight_layout() + + +.. image-sg:: /auto_examples/sensitivity/images/sphx_glr_plot_sobol_analyze_002.png + :alt: plot sobol analyze + :srcset: /auto_examples/sensitivity/images/sphx_glr_plot_sobol_analyze_002.png + :class: sphx-glr-single-img + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 16.499 seconds) + + +.. _sphx_glr_download_auto_examples_sensitivity_plot_sobol_analyze.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_sobol_analyze.py <plot_sobol_analyze.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_sobol_analyze.ipynb <plot_sobol_analyze.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/sensitivity/sg_execution_times.rst.txt b/docs/source/_build/html/_sources/auto_examples/sensitivity/sg_execution_times.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..77cb35d41755950ead705066fa8a2fe424b93572 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/sensitivity/sg_execution_times.rst.txt @@ -0,0 +1,12 @@ + +:orphan: + +.. _sphx_glr_auto_examples_sensitivity_sg_execution_times: + +Computation times +================= +**00:16.499** total execution time for **auto_examples_sensitivity** files: + ++---------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_sensitivity_plot_sobol_analyze.py` (``plot_sobol_analyze.py``) | 00:16.499 | 0.0 MB | ++---------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/source/_build/html/_sources/auto_examples/simulator/index.rst.txt b/docs/source/_build/html/_sources/auto_examples/simulator/index.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..c994f6130f14f09a1b215270a1bf10a637583ef5 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/simulator/index.rst.txt @@ -0,0 +1,112 @@ +:orphan: + +Simulator +========= + + + +.. raw:: html + + <div class="sphx-glr-thumbnails"> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Mass Point Model"> + +.. only:: html + + .. image:: /auto_examples/simulator/images/thumb/sphx_glr_plot_mass_point_model_thumb.png + :alt: Mass Point Model + + :ref:`sphx_glr_auto_examples_simulator_plot_mass_point_model.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Mass Point Model</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="RunSimulator: Mass Point Model"> + +.. only:: html + + .. image:: /auto_examples/simulator/images/thumb/sphx_glr_plot_run_mass_point_model_thumb.png + :alt: RunSimulator: Mass Point Model + + :ref:`sphx_glr_auto_examples_simulator_plot_run_mass_point_model.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">RunSimulator: Mass Point Model</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="Ravaflow24 Mixture Model"> + +.. only:: html + + .. image:: /auto_examples/simulator/images/thumb/sphx_glr_plot_ravaflow24_thumb.png + :alt: Ravaflow24 Mixture Model + + :ref:`sphx_glr_auto_examples_simulator_plot_ravaflow24.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">Ravaflow24 Mixture Model</div> + </div> + + +.. raw:: html + + <div class="sphx-glr-thumbcontainer" tooltip="RunSimulator: Ravaflow24 Mixture Model"> + +.. only:: html + + .. image:: /auto_examples/simulator/images/thumb/sphx_glr_plot_run_ravaflow24_thumb.png + :alt: RunSimulator: Ravaflow24 Mixture Model + + :ref:`sphx_glr_auto_examples_simulator_plot_run_ravaflow24.py` + +.. raw:: html + + <div class="sphx-glr-thumbnail-title">RunSimulator: Ravaflow24 Mixture Model</div> + </div> + + +.. raw:: html + + </div> + + +.. toctree:: + :hidden: + + /auto_examples/simulator/plot_mass_point_model + /auto_examples/simulator/plot_run_mass_point_model + /auto_examples/simulator/plot_ravaflow24 + /auto_examples/simulator/plot_run_ravaflow24 + + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-gallery + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download all examples in Python source code: simulator_python.zip </auto_examples/simulator/simulator_python.zip>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download all examples in Jupyter notebooks: simulator_jupyter.zip </auto_examples/simulator/simulator_jupyter.zip>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/simulator/plot_mass_point_model.rst.txt b/docs/source/_build/html/_sources/auto_examples/simulator/plot_mass_point_model.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce38db11a3c6fd89bac202e4552c61fad44c31c8 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/simulator/plot_mass_point_model.rst.txt @@ -0,0 +1,259 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/simulator/plot_mass_point_model.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_simulator_plot_mass_point_model.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_simulator_plot_mass_point_model.py: + + +Mass Point Model +================ + +.. GENERATED FROM PYTHON SOURCE LINES 8-12 + +This example shows how to simulate the movement of a masspoint on a topography +using :class:`.MassPointModel`. + + + +.. GENERATED FROM PYTHON SOURCE LINES 15-16 + +First, import the class :class:`.MassPointModel` and create an instance by + +.. GENERATED FROM PYTHON SOURCE LINES 17-22 + +.. code-block:: default + + + from psimpy.simulator import MassPointModel + + mpm = MassPointModel() + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 23-31 + +Required inputs for a simulation using :class:`.MassPointModel` include: + 1. topographic data: digital elevation model (in `ESRI ascii` format) + 2. friction coefficients: coulomb friction and turbulent friction coefficients + 3. initial state: initial location and initial velocity of the masspoint + 4. computational parameters: such as time step, end time, etc. + +The synthetic topography ``synthetic_topo.asc`` is used here for illustration. +It is located at the `tests/data/` folder. + +.. GENERATED FROM PYTHON SOURCE LINES 32-41 + +.. code-block:: default + + + import os + import linecache + import numpy as np + + dir_data = os.path.abspath('../../../tests/data/') + elevation = os.path.join(dir_data, 'synthetic_topo.asc') + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 42-44 + +.. note:: You may need to modify ``dir_data`` according to where you save + ``synthetic_topo.asc`` on your local machine. + +.. GENERATED FROM PYTHON SOURCE LINES 46-49 + +We can load the elevation data and visulize it. The figure below shows how +the topography looks like, as well as the initial location of the masspoint +(noted by the red dot). + +.. GENERATED FROM PYTHON SOURCE LINES 49-90 + +.. code-block:: default + + + header = [linecache.getline(elevation, i) for i in range(1,6)] + header_values = [float(h.split()[-1].strip()) for h in header] + ncols, nrows, xll, yll, cellsize = header_values + ncols = int(ncols) + nrows = int(nrows) + + x_values = np.arange(xll, xll+(cellsize*ncols), cellsize) + y_values = np.arange(yll, yll+(cellsize*nrows), cellsize) + + z_values = np.loadtxt(elevation, skiprows=6) + z_values = np.rot90(np.transpose(z_values)) + + # initial location + x0 = 200 + y0 = 2000 + z0 = z_values[0, int(x0/cellsize)] + + import matplotlib.pyplot as plt + + fig, ax = plt.subplots(2, 1, figsize=(10,6), height_ratios=[3,2]) + + fig0 = ax[0].contourf(x_values, y_values, z_values, levels=20) + ax[0].set_xlabel('x') + ax[0].set_ylabel('y') + ax[0].set_title('synthetic topography') + ax[0].scatter(x0, y0, s=10, c='r', marker='o') + cbar = plt.colorbar(fig0, ax=ax[0], format='%d', orientation='horizontal', + fraction=0.1, pad=0.2) + cbar.ax.set_ylabel('z') + + + ax[1].plot(x_values, z_values[0, :]) + ax[1].scatter(x0, z0, s=10, c='r', marker='o') + ax[1].set_xlabel('x') + ax[1].set_ylabel('z') + ax[1].set_xlim(0, 5000) + ax[1].set_title('cross section at any y') + + plt.tight_layout() + + + + +.. image-sg:: /auto_examples/simulator/images/sphx_glr_plot_mass_point_model_001.png + :alt: synthetic topography, cross section at any y + :srcset: /auto_examples/simulator/images/sphx_glr_plot_mass_point_model_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 91-92 + +We set the friction coefficients as + +.. GENERATED FROM PYTHON SOURCE LINES 92-96 + +.. code-block:: default + + + mu = 0.15 + xi = 1000 + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 97-101 + +Given above topography, initial location, and friction coefficients, we can +call the :py:meth:`.MassPointModel.run` method to perform a simulation. Other +parameters are set to their default values. (we suppress raised warnings ) +(other parameters are set to their default values). + +.. GENERATED FROM PYTHON SOURCE LINES 101-107 + +.. code-block:: default + + + import warnings + + warnings.filterwarnings("ignore") + output = mpm.run(elevation=elevation, coulomb_friction=mu, turbulent_friction=xi, x0=x0, y0=y0) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 108-110 + +The simulation returns time history of the mass point's location and velocity. +Following plots show the simulation results. + +.. GENERATED FROM PYTHON SOURCE LINES 110-129 + +.. code-block:: default + + + fig, ax = plt.subplots(3, 1, figsize=(10,6)) + + ax[0].set_xlabel('time (s)') + ax[0].set_ylabel('x') + ax[0].set_title("x-t plot") + ax[0].plot(output[:,0], output[:,1]) + + ax[1].set_xlabel('time (s)') + ax[1].set_ylabel('velocity') + ax[1].set_title("v-t plot") + ax[1].plot(output[:,0], output[:,5]) + + ax[2].set_xlabel('x') + ax[2].set_ylabel('velocity') + ax[2].set_title("x-v plot") + ax[2].plot(output[:,1], output[:,5]) + + plt.tight_layout() + + + +.. image-sg:: /auto_examples/simulator/images/sphx_glr_plot_mass_point_model_002.png + :alt: x-t plot, v-t plot, x-v plot + :srcset: /auto_examples/simulator/images/sphx_glr_plot_mass_point_model_002.png + :class: sphx-glr-single-img + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.550 seconds) + + +.. _sphx_glr_download_auto_examples_simulator_plot_mass_point_model.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_mass_point_model.py <plot_mass_point_model.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_mass_point_model.ipynb <plot_mass_point_model.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/simulator/plot_ravaflow24.rst.txt b/docs/source/_build/html/_sources/auto_examples/simulator/plot_ravaflow24.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..473735745278000e0b4be796a52d2335cd8ac76a --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/simulator/plot_ravaflow24.rst.txt @@ -0,0 +1,304 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/simulator/plot_ravaflow24.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_simulator_plot_ravaflow24.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_simulator_plot_ravaflow24.py: + + +Ravaflow24 Mixture Model +======================== + +.. GENERATED FROM PYTHON SOURCE LINES 8-12 + +This example shows how to simulate mass flow on a topography using +:class:`.Ravaflow24Mixture`. + + + +.. GENERATED FROM PYTHON SOURCE LINES 15-16 + +First, import the class :class:`.Ravaflow24Mixture` by + +.. GENERATED FROM PYTHON SOURCE LINES 17-20 + +.. code-block:: default + + + from psimpy.simulator import Ravaflow24Mixture + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 21-24 + +To create an instance of this class, we must specify the parameter ``dir_sim``. +It represents the directory in which output files generated by r.avaflow will be +saved. + +.. GENERATED FROM PYTHON SOURCE LINES 25-35 + +.. code-block:: default + + + import os + + # Here we create a folder called `temp_Ravaflow24Mixture_example` to save output + # files generated by r.avaflow + cwd = os.getcwd() + if not os.path.exists('temp_Ravaflow24Mixture_example'): + os.mkdir('temp_Ravaflow24Mixture_example') + dir_sim = os.path.join(cwd, 'temp_Ravaflow24Mixture_example') + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 36-40 + +Now, we can create an instance of :class:`.Ravaflow24Mixture` by given +``dir_sim`` and leaving other parameters to their default values +(Other parameters include ``time_step``, ``time_end``, ``curvature_control``, +``entrainment_control``, ``stopping_control``, etc.) + +.. GENERATED FROM PYTHON SOURCE LINES 41-44 + +.. code-block:: default + + + voellmy_model = Ravaflow24Mixture(dir_sim) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 45-57 + +To run a simulation using above `voellmy_model`, one needs to specify + 1. ``elevation`` – Name of elevation raster file (including its path). + 2. ``hrelease`` – Name of release height raster file (including its path). + 3. ``prefix`` – Prefix required by r.avaflow to name output files. + 4. If ``elevation`` is not a georeferenced file which can be used to create + a `GRASS Location`, ``EPSG`` must be provided. + +Other optional parameters include ``internal_friction``, ``basal_friction``, +``turbulent_friction``, ``entrainment_coef`` etc. + +The synthetic topography ``synthetic_topo.tif`` and release mass ``synthetic_rel.tif`` +are used here for illustration. They are located at the `/tests/data/` folder. + +.. GENERATED FROM PYTHON SOURCE LINES 58-64 + +.. code-block:: default + + + dir_data = os.path.abspath('../../../tests/data/') + elevation = os.path.join(dir_data, 'synthetic_topo.tif') + hrelease = os.path.join(dir_data, 'synthetic_rel.tif') + prefix = 'synthetic' + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 65-67 + +.. note:: You may need to modify ``dir_data`` according to where you save them + on your local machine. + +.. GENERATED FROM PYTHON SOURCE LINES 70-73 + +Given above inputs, we can create a `GRASS Location` and a shell file by calling +:py:meth:`.Ravaflow24Mixture.preprocess` method, and run the simulation using +:py:meth:`.Ravaflow24Mixture.run` method + +.. GENERATED FROM PYTHON SOURCE LINES 74-79 + +.. code-block:: default + + + grass_location, sh_file = voellmy_model.preprocess( + prefix=prefix, elevation=elevation, hrelease=hrelease, EPSG='2326') + voellmy_model.run(grass_location, sh_file) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 80-86 + +Once the simulation is finished, the results are located in the folder +`/dir_sim/your_prefix_results`. In this case, they are located in +`/temp_Ravaflow24Mixture_example/synthetic_results`. We can extract desired +outputs using respective method and visualize them. +For example, we can extract the overall impact area, maximum flow velocity, or +maximum flow velocity at specific locations: + +.. GENERATED FROM PYTHON SOURCE LINES 87-104 + +.. code-block:: default + + + import numpy as np + + # overall impact area + impact_area = voellmy_model.extract_impact_area(prefix) + print(f"Impact_area is {impact_area} m^2") + + # overall maximum flow velocity + v_mmax = voellmy_model.extract_qoi_max(prefix, 'v', aggregate=True) + print(f"Maximum flow velocity is {v_mmax} m/s^2") + + # maximum flow velocity at specific locations + loc = np.array([[500, 2000], [1500, 2000]]) + v_max_loc = voellmy_model.extract_qoi_max_loc(prefix, loc, 'v') + print(f"Maximum flow velocity at location {loc[0]} is {v_max_loc[0]} m/s^2") + print(f"Maximum flow velocity at location {loc[1]} is {v_max_loc[1]} m/s^2") + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Impact_area is 1394800.0 m^2 + Maximum flow velocity is 41.39 m/s^2 + Maximum flow velocity at location [ 500 2000] is 34.264 m/s^2 + Maximum flow velocity at location [1500 2000] is 36.689 m/s^2 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 105-106 + +We can visulize point-wise maximum flow height and velocity using heatmaps: + +.. GENERATED FROM PYTHON SOURCE LINES 107-144 + +.. code-block:: default + + + import matplotlib.pyplot as plt + import linecache + + # extract head information of result ascii files and compute x and y coordinates + hmax_asc = os.path.join(dir_sim, f'{prefix}_results', f'{prefix}_ascii', f'{prefix}_hflow_max.asc') + + header = [linecache.getline(hmax_asc, i) for i in range(1,6)] + header_values = [float(h.split()[-1].strip()) for h in header] + ncols, nrows, xll, yll, cellsize = header_values + ncols = int(ncols) + nrows = int(nrows) + + x = np.arange(xll, xll+(cellsize*ncols), cellsize) + y = np.arange(yll, yll+(cellsize*nrows), cellsize) + + # point-wise maximum flow height + h_max = voellmy_model.extract_qoi_max(prefix, 'h', aggregate=False) + # point-wise maximum flow velocity + v_max = voellmy_model.extract_qoi_max(prefix, 'v', aggregate=False) + + fig, ax = plt.subplots(2, 1, figsize=(10,6)) + + fig0 = ax[0].contourf(x, y, h_max, levels=20) + ax[0].set_xlabel('x') + ax[0].set_ylabel('y') + ax[0].set_title('maximum flow height' + r' $(m/s)$') + cbar0 = plt.colorbar(fig0, ax=ax[0], format='%.1f', orientation='vertical', fraction=0.1) + + fig1 = ax[1].contourf(x, y, v_max, levels=20) + ax[1].set_xlabel('x') + ax[1].set_ylabel('y') + ax[1].set_title('maximum flow velocity' + r' ($m/s^2$)') + cbar1 = plt.colorbar(fig1, ax=ax[1], format='%.1f', orientation='vertical', fraction=0.1) + + plt.tight_layout() + + + + +.. image-sg:: /auto_examples/simulator/images/sphx_glr_plot_ravaflow24_001.png + :alt: maximum flow height $(m/s)$, maximum flow velocity ($m/s^2$) + :srcset: /auto_examples/simulator/images/sphx_glr_plot_ravaflow24_001.png + :class: sphx-glr-single-img + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 145-146 + +Here we delete the folder `temp_Ravaflow24Mixture_example` and all files therein. + +.. GENERATED FROM PYTHON SOURCE LINES 147-151 + +.. code-block:: default + + + import shutil + + shutil.rmtree(dir_sim) + + + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 5 minutes 56.157 seconds) + + +.. _sphx_glr_download_auto_examples_simulator_plot_ravaflow24.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_ravaflow24.py <plot_ravaflow24.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_ravaflow24.ipynb <plot_ravaflow24.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/simulator/plot_run_mass_point_model.rst.txt b/docs/source/_build/html/_sources/auto_examples/simulator/plot_run_mass_point_model.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..c969e754b82c5cadc733013c7b4ccfb69b8f2d42 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/simulator/plot_run_mass_point_model.rst.txt @@ -0,0 +1,376 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/simulator/plot_run_mass_point_model.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_simulator_plot_run_mass_point_model.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_simulator_plot_run_mass_point_model.py: + + +RunSimulator: Mass Point Model +============================== + +.. GENERATED FROM PYTHON SOURCE LINES 8-12 + +This example shows how to run multiple MassPointModel simulations in serial +and parallelly using :class:`.RunSimulator`. + + + +.. GENERATED FROM PYTHON SOURCE LINES 16-18 + +First, we import the class :class:`.MassPointModel` and define a `simulator` +based on :py:meth:`.MassPointModel.run` method. + +.. GENERATED FROM PYTHON SOURCE LINES 19-26 + +.. code-block:: default + + + from psimpy.simulator import MassPointModel + + mpm = MassPointModel() + mpm_simulator = mpm.run + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 27-39 + +This simulator takes required input data, solves the mass point model, and +returns time history of the mass point's location and velocity +(see :py:meth:`.MassPointModel.run`). + +Required inputs for `mpm_simulator` include: + 1. topographic data: digital elevation model (in `ESRI ascii` format) + 2. friction coefficients: coulomb friction and turbulent friction coefficients + 3. initial state: initial location and initial velocity of the masspoint + 4. computational parameters: such as time step, end time, etc. + +The synthetic topography ``synthetic_topo.asc`` is used here for illustration. +It is located at the `/tests/data/` folder. + +.. GENERATED FROM PYTHON SOURCE LINES 40-46 + +.. code-block:: default + + + import os + + dir_data = os.path.abspath('../../../tests/data/') + elevation = os.path.join(dir_data, 'synthetic_topo.asc') + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 47-49 + +.. note:: You may need to modify ``dir_data`` according to where you save + ``synthetic_topo.asc`` on your local machine. + +.. GENERATED FROM PYTHON SOURCE LINES 51-57 + +For this example, we are going to run multiple simulations at different values +of coulomb friction coefficient (``coulomb_friction``) and turbulent friction +coefficient (``turbulent_friction``) while keep other inputs fixed. Namely, +``coulomb_friction`` and ``turbulent_friction`` are variable input parameters. +All other inputs are fixed input parameters. + + +.. GENERATED FROM PYTHON SOURCE LINES 58-74 + +.. code-block:: default + + + import numpy as np + import itertools + + # Variable iput parameters are defined as a list of strings. Their values will be + # passed as a numpy array (var_samples) when run simulations. + var_inp_parameter = ['coulomb_friction', 'turbulent_friction'] + coulomb_friction = np.arange(0.1, 0.31, 0.1) + turbulent_friction = np.arange(500, 2001, 400) + var_samples = np.array( + [x for x in itertools.product(coulomb_friction, turbulent_friction)]) + print("Number of variable input samples are: ", len(var_samples)) + + # Fixed input parameters are defined as a dictionary. Their values are given. + fix_inp = {'elevation': elevation, 'x0': 200, 'y0': 2000, 'tend': 50} + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Number of variable input samples are: 12 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 75-78 + +.. note:: Parameters of `mpm_simulator` which are not included in + ``var_inp_parameter`` and ``fix_inp``, such as ``ux0``, ``uy0`` and + ``curvature``, will automatically take their default values. + +.. GENERATED FROM PYTHON SOURCE LINES 80-83 + +We may want to save outputs returned by `mpm_simulator` at each simulation for +later inspection or processing. In that case, we need to define ``dir_out`` and +set ``save_out`` as `True`. + +.. GENERATED FROM PYTHON SOURCE LINES 84-95 + +.. code-block:: default + + + import os + + # Here we create a folder called `temp_run_MassPointModel_example` to save outputs + # returned at each simulation. + cwd = os.getcwd() + if not os.path.exists('temp_run_MassPointModel_example'): + os.mkdir('temp_run_MassPointModel_example') + dir_out = os.path.join(cwd, 'temp_run_MassPointModel_example') + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 96-97 + +Now we can define an object of :class:`.RunSimulator` by + +.. GENERATED FROM PYTHON SOURCE LINES 98-104 + +.. code-block:: default + + + from psimpy.simulator import RunSimulator + + run_mpm_simulator = RunSimulator(mpm_simulator, var_inp_parameter, fix_inp, + dir_out=dir_out, save_out=True) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 105-108 + +.. note:: Since outputs of each simulation are saved in the same folder ``dir_out``, + we need to give each file a unique name in order to avoid conflict. This is + realized by defining ``prefixes``. + +.. GENERATED FROM PYTHON SOURCE LINES 108-113 + +.. code-block:: default + + + serial_prefixes = ["serial"+str(i) for i in range(len(var_samples))] + parallel_prefixes = ["parallel"+str(i) for i in range(len(var_samples))] + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 114-117 + +Using :py:meth:`.RunSimulator.serial_run` method or +:py:meth:`.RunSimulator.parallel_run` method, we can run the simulations +in serial or parallelly. + +.. GENERATED FROM PYTHON SOURCE LINES 118-136 + +.. code-block:: default + + + import time + + start = time.time() + run_mpm_simulator.serial_run(var_samples=var_samples, prefixes=serial_prefixes) + serial_time = time.time() - start + serial_output = run_mpm_simulator.outputs + + start = time.time() + # max_workers controls maximum number of tasks running in parallel + run_mpm_simulator.parallel_run(var_samples, prefixes=parallel_prefixes, max_workers=4) + parallel_time = time.time() - start + parallel_output = run_mpm_simulator.outputs + + print("Serial run time: ", serial_time) + print("Parallel run time: ", parallel_time) + + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Serial run time: 1.1941184997558594 + Parallel run time: 0.4859800338745117 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 137-139 + +Once a simulation is done, its output is saved to ``dir_out``. All output files +generated by above simulations are as follows: + +.. GENERATED FROM PYTHON SOURCE LINES 140-144 + +.. code-block:: default + + + os.listdir(dir_out) + + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + + ['serial0_output.npy', 'serial9_output.npy', 'serial11_output.npy', 'parallel10_output.npy', 'parallel0_output.npy', 'parallel5_output.npy', 'parallel11_output.npy', 'serial1_output.npy', 'serial4_output.npy', 'parallel7_output.npy', 'serial5_output.npy', 'serial8_output.npy', 'parallel6_output.npy', 'parallel4_output.npy', 'parallel2_output.npy', 'serial3_output.npy', 'serial6_output.npy', 'parallel3_output.npy', 'serial2_output.npy', 'parallel9_output.npy', 'serial7_output.npy', 'parallel1_output.npy', 'parallel8_output.npy', 'serial10_output.npy'] + + + +.. GENERATED FROM PYTHON SOURCE LINES 145-147 + +Once all simulations are done, their outputs can also be accessed by +:py:attr:`.RunSimulator.outputs` attribute, which is a list. + +.. GENERATED FROM PYTHON SOURCE LINES 148-157 + +.. code-block:: default + + + # Here we print the maximum velocity of each simulation in the parallel run. + max_v = [np.max(output[:,5]) for output in parallel_output] + print( + f"Maximum velocity of {parallel_prefixes[0]} to {parallel_prefixes[-1]} are: ", + '\n', + max_v) + + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + Maximum velocity of parallel0 to parallel11 are: + [16.55505557211892, 22.014114896121015, 26.245546886730782, 29.78487303612985, 15.34198274528081, 20.371864007499866, 24.249957243412815, 27.485487855011687, 14.031665649204944, 18.589324449452967, 22.092803891476187, 24.99727320816709] + + + + +.. GENERATED FROM PYTHON SOURCE LINES 158-164 + +.. warning:: If one simulation failed due to whatever reason, the error massage + will be printed to the screen but other simulations will continue. In that + case, the output file of failed simulation will not be writted to ``dir_out``. + Also, the element of :py:attr:`.RunSimulator.outputs` corresponding to that + simulation will be a string representing the error message, instead of a + numpy array. + +.. GENERATED FROM PYTHON SOURCE LINES 167-168 + +Here we delete the folder `temp_run_MassPointModel_example` and all files therein. + +.. GENERATED FROM PYTHON SOURCE LINES 169-185 + +.. code-block:: default + + + import shutil + + shutil.rmtree(dir_out) + + + + + + + + + + + + + + + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 0 minutes 1.687 seconds) + + +.. _sphx_glr_download_auto_examples_simulator_plot_run_mass_point_model.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_run_mass_point_model.py <plot_run_mass_point_model.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_run_mass_point_model.ipynb <plot_run_mass_point_model.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/simulator/plot_run_ravaflow24.rst.txt b/docs/source/_build/html/_sources/auto_examples/simulator/plot_run_ravaflow24.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..b727903cb1928792576923c90872d4fbbc3a0761 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/simulator/plot_run_ravaflow24.rst.txt @@ -0,0 +1,444 @@ + +.. DO NOT EDIT. +.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. +.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: +.. "auto_examples/simulator/plot_run_ravaflow24.py" +.. LINE NUMBERS ARE GIVEN BELOW. + +.. only:: html + + .. note:: + :class: sphx-glr-download-link-note + + Click :ref:`here <sphx_glr_download_auto_examples_simulator_plot_run_ravaflow24.py>` + to download the full example code + +.. rst-class:: sphx-glr-example-title + +.. _sphx_glr_auto_examples_simulator_plot_run_ravaflow24.py: + + +RunSimulator: Ravaflow24 Mixture Model +====================================== + +.. GENERATED FROM PYTHON SOURCE LINES 8-11 + +This example shows how to run multiple Ravaflow24Mixture simulations in serial +and parallelly using :class:`.RunSimulator`. + + +.. GENERATED FROM PYTHON SOURCE LINES 14-15 + +First, we import the class :class:`.Ravaflow24Mixture`. + +.. GENERATED FROM PYTHON SOURCE LINES 16-19 + +.. code-block:: default + + + from psimpy.simulator import Ravaflow24Mixture + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 20-23 + +To create an instance of this class, we must specify the parameter ``dir_sim``. +It represents the directory in which output files generated by r.avaflow will be +saved. + +.. GENERATED FROM PYTHON SOURCE LINES 24-34 + +.. code-block:: default + + + import os + + # Here we create a folder called `temp1_run_Ravaflow24Mixture_example` to save + # output files generated by r.avaflow + cwd = os.getcwd() + if not os.path.exists('temp1_run_Ravaflow24Mixture_example'): + os.mkdir('temp1_run_Ravaflow24Mixture_example') + dir_sim = os.path.join(cwd, 'temp1_run_Ravaflow24Mixture_example') + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 35-38 + +Given ``dir_sim``, we can create an instance of :class:`.Ravaflow24Mixture`. +To reduce simulation time, we set ``time_end`` to :math:`50`. Other parameters +are set to their default values. + +.. GENERATED FROM PYTHON SOURCE LINES 39-42 + +.. code-block:: default + + + voellmy_model = Ravaflow24Mixture(dir_sim, time_end=50) + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 43-45 + +The `simulator` in this example is defined based on ``voellmy_model`` as follows. +It takes required inputs and returns the overall impact area. + +.. GENERATED FROM PYTHON SOURCE LINES 46-59 + +.. code-block:: default + + + import numpy as np + + def simulator(prefix, elevation, hrelease, basal_friction, turbulent_friction, EPSG): + """Preprocess required inputs, run simulation, and return output as a numpy array.""" + grass_location, sh_file = voellmy_model.preprocess(prefix=prefix, elevation=elevation, + hrelease=hrelease, basal_friction=basal_friction, turbulent_friction=turbulent_friction, EPSG=EPSG) + voellmy_model.run(grass_location, sh_file) # run this line, r.avaflow will write outputs to dir_sim + impact_area = voellmy_model.extract_impact_area(prefix) + + return np.array([impact_area]) # define dir_out and set save_out to True, returned numpy array will be saved to dir_out + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 60-63 + +To demonstrate how to run multiple simulations using :class:`.RunSimulator`, +we choose ``basal_friction`` and ``turbulent_friction`` as variable input +parameters. Each has two different values, leading to four simulations. + +.. GENERATED FROM PYTHON SOURCE LINES 64-74 + +.. code-block:: default + + + import itertools + + var_inp_parameter = ['basal_friction', 'turbulent_friction'] + basal_friction = [20, 30] + turbulent_friction = [3, 4] + var_samples = np.array( + [x for x in itertools.product(basal_friction, turbulent_friction)]) + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 75-78 + +Other parameters of the `simulator`, including ``elevation``, ``hrelease``, and +``EPSG`` are treated as fixed input. It means that their values are the same in +all simulations. + +.. GENERATED FROM PYTHON SOURCE LINES 79-85 + +.. code-block:: default + + + dir_data = os.path.abspath('../../../tests/data/') + elevation = os.path.join(dir_data, 'synthetic_topo.tif') + hrelease = os.path.join(dir_data, 'synthetic_rel.tif') + fix_inp = {'elevation': elevation, 'hrelease': hrelease, 'EPSG': '2326'} + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 86-91 + +The parameter ``prefix`` of the `simulator` is special. It is not involved in +the computational model, but only used to name output files generated by r.avaflow. +Such parameter is not defined in ``var_inp_parameter`` or ``fix_inp`` of +:class:`.RunSimulator`. Instead, we use a seperate parameter, called ``o_parameter`` +for this purpose. + +.. GENERATED FROM PYTHON SOURCE LINES 92-96 + +.. code-block:: default + + + o_parameter = 'prefix' + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 97-100 + +We may want to save outputs returned by the `simulator` at each simulation for +later inspection or processing. In that case, we need to define ``dir_out`` and +set ``save_out`` as `True`. + +.. GENERATED FROM PYTHON SOURCE LINES 101-109 + +.. code-block:: default + + + import os + + cwd = os.getcwd() + if not os.path.exists('temp2_run_Ravaflow24Mixture_example'): + os.mkdir('temp2_run_Ravaflow24Mixture_example') + dir_out = os.path.join(cwd, 'temp2_run_Ravaflow24Mixture_example') + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 110-132 + +.. note:: Please note that ``dir_out`` and ``dir_sim`` are two different + parameters for different purposes. + + - ``dir_out`` is a parameter of :class:`.RunSimulator`. The `simulator` + returns output of interest as a numpy array for each simulation. If + we want to save this returned output of interest (here impact area) + to our local machine, we need to specify the value of ``dir_out`` which + represents the directory in which output of interest will be saved and + set ``save_out`` to `True`. Otherwise, we do not need ``dir_out`` and + leave ``save_out`` to `False`. + - ``dir_sim`` is a parameter of :class:`.Ravaflow24Mixture`. :class:`.Ravaflow24Mixture` + relies on the third party software r.avaflow 2.4. When we call + :py:meth:`.Ravaflow24Mixture.run` in the function body of above `simulator`, + r.avaflow 2.4 will be run and it generates output files. The value of + ``dir_sim`` specifies the directory in which output files generated by + r.avaflow 2.4 are going to be saved. + + The value of ``dir_out`` and ``dir_sim`` can be the same if file names + have no conflict. We recommend to keep them seperate. In addition, if the function + body of the `simulator` does not write files to disk, ``dir_sim`` is not required. Our + :class:`.MassPointModel` is an example. Similarly, if we do not want to save + returned numpy array of the `simulator`, ``dir_out`` is not needed. + +.. GENERATED FROM PYTHON SOURCE LINES 135-136 + +Now we can define an object of :class:`.RunSimulator` by + +.. GENERATED FROM PYTHON SOURCE LINES 137-144 + +.. code-block:: default + + + from psimpy.simulator import RunSimulator + + run_simulator = RunSimulator(simulator, var_inp_parameter, fix_inp, o_parameter, + dir_out, save_out=True) + + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 145-148 + +Before running simulations, we need to specify values of ``prefixes`` which +will be used to name files generated by each r.avaflow simulation and +each returned numpy array of `simulator`. + +.. GENERATED FROM PYTHON SOURCE LINES 149-153 + +.. code-block:: default + + + serial_prefixes = ["serial"+str(i) for i in range(len(var_samples))] + parallel_prefixes = ["parallel"+str(i) for i in range(len(var_samples))] + + + + + + + + +.. GENERATED FROM PYTHON SOURCE LINES 154-157 + +Now we can use :py:meth:`.RunSimulator.serial_run` method or +:py:meth:`.RunSimulator.parallel_run` method to run the simulations +in serial or parallelly. + +.. GENERATED FROM PYTHON SOURCE LINES 158-181 + +.. code-block:: default + + + import time + + start = time.time() + run_simulator.serial_run(var_samples=var_samples, prefixes=serial_prefixes) + serial_time = time.time() - start + serial_output = run_simulator.outputs + print(f"serial_output: {serial_output}") + + start = time.time() + # append setting to True means that simulation outputs of parallel run will be + # appended to above serial run outputs + run_simulator.parallel_run(var_samples, prefixes=parallel_prefixes, + max_workers=2, append=True) + parallel_time = time.time() - start + + parallel_output = run_simulator.outputs[len(var_samples):] + print(f"parallel_output: {parallel_output}") + + + print("Serial run time: ", serial_time) + print("Parallel run time: ", parallel_time) + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + serial_output: [array([1008000.]), array([1520800.]), array([674000.]), array([869600.])] + parallel_output: [array([1008000.]), array([1520800.]), array([674000.]), array([869600.])] + Serial run time: 110.85352993011475 + Parallel run time: 62.39644193649292 + + + + +.. GENERATED FROM PYTHON SOURCE LINES 182-183 + +All output files returned by the `simulator` are + +.. GENERATED FROM PYTHON SOURCE LINES 184-187 + +.. code-block:: default + + + os.listdir(dir_out) + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + + ['serial0_output.npy', 'parallel0_output.npy', 'serial1_output.npy', 'parallel2_output.npy', 'serial3_output.npy', 'parallel3_output.npy', 'serial2_output.npy', 'parallel1_output.npy'] + + + +.. GENERATED FROM PYTHON SOURCE LINES 188-190 + +All output files/directories generated by r.avaflow simulations +(including files/directories generated during preprocessing) are + +.. GENERATED FROM PYTHON SOURCE LINES 191-195 + +.. code-block:: default + + + os.listdir(dir_sim) + + + + + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + + ['serial0_glocation', 'parallel3_results', 'parallel2_glocation', 'serial3_shell.sh', 'parallel1_results', 'serial3_glocation', 'serial1_shell.sh', 'parallel2_results', 'serial0_shell.sh', 'parallel1_glocation', 'parallel3_shell.sh', 'parallel0_shell.sh', 'serial1_glocation', 'parallel1_shell.sh', 'parallel2_shell.sh', 'serial0_results', 'serial1_results', 'serial2_shell.sh', 'serial2_glocation', 'serial2_results', 'parallel3_glocation', 'parallel0_glocation', 'serial3_results', 'parallel0_results'] + + + +.. GENERATED FROM PYTHON SOURCE LINES 196-202 + +.. warning:: If one simulation failed due to whatever reason, the error massage + will be printed to the screen but other simulations will continue. In that + case, the output file of failed simulation will not be writted to ``dir_out``. + Also, the element of :py:attr:`.RunSimulator.outputs` corresponding to that + simulation will be a string representing the error message, instead of a + numpy array. + +.. GENERATED FROM PYTHON SOURCE LINES 205-207 + +In the end, we delete the folder `temp1_run_Ravaflow24Mixture_example` and +`temp2_run_Ravaflow24Mixture_example` and all files therein. + +.. GENERATED FROM PYTHON SOURCE LINES 208-212 + +.. code-block:: default + + + import shutil + + shutil.rmtree(dir_sim) + shutil.rmtree(dir_out) + + + + + + + +.. rst-class:: sphx-glr-timing + + **Total running time of the script:** ( 2 minutes 53.318 seconds) + + +.. _sphx_glr_download_auto_examples_simulator_plot_run_ravaflow24.py: + +.. only:: html + + .. container:: sphx-glr-footer sphx-glr-footer-example + + + .. container:: sphx-glr-download sphx-glr-download-python + + :download:`Download Python source code: plot_run_ravaflow24.py <plot_run_ravaflow24.py>` + + .. container:: sphx-glr-download sphx-glr-download-jupyter + + :download:`Download Jupyter notebook: plot_run_ravaflow24.ipynb <plot_run_ravaflow24.ipynb>` + + +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ diff --git a/docs/source/_build/html/_sources/auto_examples/simulator/sg_execution_times.rst.txt b/docs/source/_build/html/_sources/auto_examples/simulator/sg_execution_times.rst.txt new file mode 100644 index 0000000000000000000000000000000000000000..383f3587befbf9381425d3c8125ed9d28b05d0c2 --- /dev/null +++ b/docs/source/_build/html/_sources/auto_examples/simulator/sg_execution_times.rst.txt @@ -0,0 +1,18 @@ + +:orphan: + +.. _sphx_glr_auto_examples_simulator_sg_execution_times: + +Computation times +================= +**08:52.712** total execution time for **auto_examples_simulator** files: + ++---------------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_simulator_plot_ravaflow24.py` (``plot_ravaflow24.py``) | 05:56.157 | 0.0 MB | ++---------------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_simulator_plot_run_ravaflow24.py` (``plot_run_ravaflow24.py``) | 02:53.318 | 0.0 MB | ++---------------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_simulator_plot_run_mass_point_model.py` (``plot_run_mass_point_model.py``) | 00:01.687 | 0.0 MB | ++---------------------------------------------------------------------------------------------------------+-----------+--------+ +| :ref:`sphx_glr_auto_examples_simulator_plot_mass_point_model.py` (``plot_mass_point_model.py``) | 00:01.550 | 0.0 MB | ++---------------------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/source/_build/html/auto_examples/emulator/index.html b/docs/source/_build/html/auto_examples/emulator/index.html new file mode 100644 index 0000000000000000000000000000000000000000..ad9a429c1d33e13c50deb1b72bc1c002cf1997a1 --- /dev/null +++ b/docs/source/_build/html/auto_examples/emulator/index.html @@ -0,0 +1,147 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Emulator — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="PPGaSP: GP emulation for multi-output functions" href="plot_ppgasp.html" /> + <link rel="prev" title="Example Gallery" href="../../examples.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2 current"><a class="current reference internal" href="#">Emulator</a><ul> +<li class="toctree-l3"><a class="reference internal" href="plot_ppgasp.html">PPGaSP: GP emulation for multi-output functions</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_scalargasp.html">ScalarGaSP: GP emulation for a single-output function</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item active">Emulator</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/emulator/index.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="emulator"> +<h1>Emulator<a class="headerlink" href="#emulator" title="Permalink to this heading"></a></h1> +<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="PPGaSP: GP emulation for multi-output functions"><img alt="PPGaSP: GP emulation for multi-output functions" src="../../_images/sphx_glr_plot_ppgasp_thumb.png" /> +<p><a class="reference internal" href="plot_ppgasp.html#sphx-glr-auto-examples-emulator-plot-ppgasp-py"><span class="std std-ref">PPGaSP: GP emulation for multi-output functions</span></a></p> + <div class="sphx-glr-thumbnail-title">PPGaSP: GP emulation for multi-output functions</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="ScalarGaSP: GP emulation for a single-output function"><img alt="ScalarGaSP: GP emulation for a single-output function" src="../../_images/sphx_glr_plot_scalargasp_thumb.png" /> +<p><a class="reference internal" href="plot_scalargasp.html#sphx-glr-auto-examples-emulator-plot-scalargasp-py"><span class="std std-ref">ScalarGaSP: GP emulation for a single-output function</span></a></p> + <div class="sphx-glr-thumbnail-title">ScalarGaSP: GP emulation for a single-output function</div> +</div></div><div class="toctree-wrapper compound"> +</div> +<div class="sphx-glr-footer sphx-glr-footer-gallery docutils container"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/ff2071d6226ad5ba480d05dc9b72039e/emulator_python.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">emulator_python.zip</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/af73dbd4cdfb71a4d5cac0b204c855e0/emulator_jupyter.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Jupyter</span> <span class="pre">notebooks:</span> <span class="pre">emulator_jupyter.zip</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="../../examples.html" class="btn btn-neutral float-left" title="Example Gallery" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_ppgasp.html" class="btn btn-neutral float-right" title="PPGaSP: GP emulation for multi-output functions" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/emulator/plot_ppgasp.html b/docs/source/_build/html/auto_examples/emulator/plot_ppgasp.html new file mode 100644 index 0000000000000000000000000000000000000000..f34a15a41fbee380e379e76444cc79f80fa3b700 --- /dev/null +++ b/docs/source/_build/html/auto_examples/emulator/plot_ppgasp.html @@ -0,0 +1,259 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>PPGaSP: GP emulation for multi-output functions — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="ScalarGaSP: GP emulation for a single-output function" href="plot_scalargasp.html" /> + <link rel="prev" title="Emulator" href="index.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Emulator</a><ul class="current"> +<li class="toctree-l3 current"><a class="current reference internal" href="#">PPGaSP: GP emulation for multi-output functions</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_scalargasp.html">ScalarGaSP: GP emulation for a single-output function</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Emulator</a></li> + <li class="breadcrumb-item active">PPGaSP: GP emulation for multi-output functions</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/emulator/plot_ppgasp.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-emulator-plot-ppgasp-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="ppgasp-gp-emulation-for-multi-output-functions"> +<span id="sphx-glr-auto-examples-emulator-plot-ppgasp-py"></span><h1>PPGaSP: GP emulation for multi-output functions<a class="headerlink" href="#ppgasp-gp-emulation-for-multi-output-functions" title="Permalink to this heading"></a></h1> +<p>This example shows how to apply Gaussian process emulation to a multi-output +function using class <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.PPGaSP" title="psimpy.emulator.robustgasp.PPGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">PPGaSP</span></code></a>.</p> +<p>The multi-output function that we are going to look at is the <cite>DIAMOND</cite> +(diplomatic and military operations in a non-warfighting domain) computer model. +It is used as a testbed to illustrate the <cite>PP GaSP</cite> emulator in the <cite>R</cite> package +<cite>RobustGaSP</cite>, see <span id="id1">Gu <em>et al.</em> [<a class="reference internal" href="../../refs.html#id6" title="Meng Yang Gu, Jesus Palomo, and James O. Berger. Robustgasp: robust Gaussian stochastic process emulation in R. The R Journal, 11(1):112–136, 2019. doi:10.32614/RJ-2019-011.">2019</a>]</span> for more detail.</p> +<p>The simulator has <span class="math notranslate nohighlight">\(13\)</span> input parameters and <span class="math notranslate nohighlight">\(5\)</span> outputs. Namely, +<span class="math notranslate nohighlight">\(\mathbf{y}=f(\mathbf{x})\)</span> where <span class="math notranslate nohighlight">\(\mathbf{x}=(x_1,\ldots,x_{13})^T\)</span> +and <span class="math notranslate nohighlight">\(\mathbf{y}=(y_1,\ldots,y_5)^T\)</span>.</p> +<p>The training and testing data are provided in the folder ‘…/tests/data/’. +We first load the training and testing data.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> +<span class="kn">import</span> <span class="nn">os</span> + +<span class="n">dir_data</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s1">'../../../tests/data/'</span><span class="p">)</span> + +<span class="n">humanityX</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'humanityX.csv'</span><span class="p">),</span> <span class="n">delimiter</span><span class="o">=</span><span class="s1">','</span><span class="p">)</span> +<span class="n">humanityY</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'humanityY.csv'</span><span class="p">),</span> <span class="n">delimiter</span><span class="o">=</span><span class="s1">','</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Number of training data points: "</span><span class="p">,</span> <span class="n">humanityX</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Input dimension: "</span><span class="p">,</span> <span class="n">humanityX</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Output dimension: "</span><span class="p">,</span> <span class="n">humanityY</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> + +<span class="n">humanityXt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'humanityXt.csv'</span><span class="p">),</span> <span class="n">delimiter</span><span class="o">=</span><span class="s1">','</span><span class="p">)</span> +<span class="n">humanityYt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'humanityYt.csv'</span><span class="p">),</span> <span class="n">delimiter</span><span class="o">=</span><span class="s1">','</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Number of testing data points: "</span><span class="p">,</span> <span class="n">humanityXt</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Number of training data points: 120 +Input dimension: 13 +Output dimension: 5 +Number of testing data points: 120 +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>You may need to modify <code class="docutils literal notranslate"><span class="pre">dir_data</span></code> according to where you save them +on your local machine.</p> +</div> +<p><code class="docutils literal notranslate"><span class="pre">humanityX</span></code> and <code class="docutils literal notranslate"><span class="pre">humanitY</span></code> are the training data, corresponding to <code class="docutils literal notranslate"><span class="pre">design</span></code> +and <code class="docutils literal notranslate"><span class="pre">response</span></code> respectively. <code class="docutils literal notranslate"><span class="pre">humanityXt</span></code> are testing input data, at which +we are going to make predictions once the emulator is trained. <code class="docutils literal notranslate"><span class="pre">humanityYt</span></code> +are the true outputs at <code class="docutils literal notranslate"><span class="pre">humanityXt</span></code>, which is then used to validate the +performance of the trained emulator.</p> +<p>To build a <cite>PP GaSP</cite> emulator for the above simulator, first import class +<a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.PPGaSP" title="psimpy.emulator.robustgasp.PPGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">PPGaSP</span></code></a> by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.emulator</span> <span class="kn">import</span> <span class="n">PPGaSP</span> +</pre></div> +</div> +<p>Then, create an instance of <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.PPGaSP" title="psimpy.emulator.robustgasp.PPGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">PPGaSP</span></code></a>. The parameter <code class="docutils literal notranslate"><span class="pre">ndim</span></code> +(dimension of function input <code class="docutils literal notranslate"><span class="pre">x</span></code>) must be specified. Optional parameters, such +as <code class="docutils literal notranslate"><span class="pre">method</span></code>, <code class="docutils literal notranslate"><span class="pre">kernel_type</span></code>, etc., can be set up if desired. Here, we leave +all the optional parameters to their default values.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">emulator</span> <span class="o">=</span> <span class="n">PPGaSP</span><span class="p">(</span><span class="n">ndim</span><span class="o">=</span><span class="n">humanityX</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> +</pre></div> +</div> +<p>Next, we train the <cite>PP GaSP</cite> emulator based on the training data using +<a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.PPGaSP.train" title="psimpy.emulator.robustgasp.PPGaSP.train"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PPGaSP.train()</span></code></a> method.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">emulator</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">design</span><span class="o">=</span><span class="n">humanityX</span><span class="p">,</span> <span class="n">response</span><span class="o">=</span><span class="n">humanityY</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>The upper bounds of the range parameters are 296,974 297,1814 294,7672 295,9345 296,563 295,935 297,3198 296,4444 296,9323 298,2373 298,0619 298,7249 298,7249 +The initial values of range parameters are 5,93948 5,943628 5,895344 5,918691 5,93126 5,918701 5,946395 5,928888 5,938645 5,964745 5,961238 5,974498 5,974498 +Start of the optimization 1 : +The number of iterations is 44 + The value of the marginal posterior function is -5279,534 + Optimized range parameters are 25,46132 2,891428 5,30812 26,95519 291,1828 48,17274 84,56133 2,874385 39,12121 51,81304 0,5407651 1,728696 1,020605 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 12,37503 12,38367 12,28307 12,33172 12,3579 12,33174 12,38944 12,35296 12,37329 12,42767 12,42037 12,44799 12,44799 +Start of the optimization 2 : +The number of iterations is 45 + The value of the marginal posterior function is -5279,534 + Optimized range parameters are 25,46132 2,891428 5,308121 26,95519 291,183 48,17274 84,56133 2,874385 39,12121 51,81304 0,5407651 1,728696 1,020605 + Optimized nugget parameter is 0 + Convergence: TRUE +</pre></div> +</div> +<p>With the trained emulator, we can make predictions for any arbitrary set of +input points using <code class="xref py py-meth docutils literal notranslate"><span class="pre">PPGaSP.predict()</span></code> method. +Here, we make predictions at testing input points <code class="docutils literal notranslate"><span class="pre">humanityXt</span></code>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">predictions</span> <span class="o">=</span> <span class="n">emulator</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">humanityXt</span><span class="p">)</span> +</pre></div> +</div> +<p>We can validate the performance of the trained emulator based on the true outputs +<code class="docutils literal notranslate"><span class="pre">humanityYt</span></code>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">15</span><span class="p">))</span> + +<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">humanityY</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> + + <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Actual $y_</span><span class="si">{</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s1">$'</span><span class="p">)</span> + <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Emulator-predicted $y_</span><span class="si">{</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s1">$'</span><span class="p">)</span> + <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">]),</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">]))</span> + <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">]),</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">]))</span> + + <span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">]),</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">])],</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">]),</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">])])</span> + <span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">errorbar</span><span class="p">(</span><span class="n">humanityYt</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">predictions</span><span class="p">[:,</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">predictions</span><span class="p">[:,</span><span class="n">i</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="n">fmt</span><span class="o">=</span><span class="s1">'.'</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'prediction and std'</span><span class="p">)</span> + <span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_ppgasp_001.png" srcset="../../_images/sphx_glr_plot_ppgasp_001.png" alt="plot ppgasp" class = "sphx-glr-single-img"/><p>We can also draw any number of samples at testing input <code class="docutils literal notranslate"><span class="pre">humanityXt</span></code> using +<code class="xref py py-meth docutils literal notranslate"><span class="pre">PPGaSPsample()</span></code> method.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">samples</span> <span class="o">=</span> <span class="n">emulator</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">humanityXt</span><span class="p">,</span> <span class="n">nsamples</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Shape of samples: "</span><span class="p">,</span> <span class="n">samples</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Shape of samples: (120, 5, 10) +</pre></div> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 5.333 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-emulator-plot-ppgasp-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/bfca202fd55dbe4c4a07ec2f8128e4cc/plot_ppgasp.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_ppgasp.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/9ac7682e0f10ab62297eb4ff29689bc8/plot_ppgasp.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_ppgasp.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="index.html" class="btn btn-neutral float-left" title="Emulator" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_scalargasp.html" class="btn btn-neutral float-right" title="ScalarGaSP: GP emulation for a single-output function" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/emulator/plot_scalargasp.html b/docs/source/_build/html/auto_examples/emulator/plot_scalargasp.html new file mode 100644 index 0000000000000000000000000000000000000000..9ed6b504c1fe44ff452d2cae6249db2bd3975f3d --- /dev/null +++ b/docs/source/_build/html/auto_examples/emulator/plot_scalargasp.html @@ -0,0 +1,267 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>ScalarGaSP: GP emulation for a single-output function — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Inference" href="../inference/index.html" /> + <link rel="prev" title="PPGaSP: GP emulation for multi-output functions" href="plot_ppgasp.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Emulator</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_ppgasp.html">PPGaSP: GP emulation for multi-output functions</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">ScalarGaSP: GP emulation for a single-output function</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Emulator</a></li> + <li class="breadcrumb-item active">ScalarGaSP: GP emulation for a single-output function</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/emulator/plot_scalargasp.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-emulator-plot-scalargasp-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="scalargasp-gp-emulation-for-a-single-output-function"> +<span id="sphx-glr-auto-examples-emulator-plot-scalargasp-py"></span><h1>ScalarGaSP: GP emulation for a single-output function<a class="headerlink" href="#scalargasp-gp-emulation-for-a-single-output-function" title="Permalink to this heading"></a></h1> +<p>This example shows how to apply Gaussian process emulation to a single-output +function using class <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP" title="psimpy.emulator.robustgasp.ScalarGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScalarGaSP</span></code></a>.</p> +<p>The task is to build a GP emulator for the function <span class="math notranslate nohighlight">\(y = x * sin(x)\)</span> +based on a few number of training data.</p> +<p>First, import the class <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP" title="psimpy.emulator.robustgasp.ScalarGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScalarGaSP</span></code></a> by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.emulator</span> <span class="kn">import</span> <span class="n">ScalarGaSP</span> +</pre></div> +</div> +<p>Then, create an instance of <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP" title="psimpy.emulator.robustgasp.ScalarGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScalarGaSP</span></code></a>. The parameter <code class="docutils literal notranslate"><span class="pre">ndim</span></code> +(dimension of function input <code class="docutils literal notranslate"><span class="pre">x</span></code>) must be specified. Optional parameters, such +as <code class="docutils literal notranslate"><span class="pre">method</span></code>, <code class="docutils literal notranslate"><span class="pre">kernel_type</span></code>, etc., can be set up if desired. Here, we leave +all the optional parameters to their default values.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">emulator</span> <span class="o">=</span> <span class="n">ScalarGaSP</span><span class="p">(</span><span class="n">ndim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> +</pre></div> +</div> +<p>Given training input points <code class="docutils literal notranslate"><span class="pre">design</span></code> and corresponding output values <code class="docutils literal notranslate"><span class="pre">response</span></code>, +the emulator can be trained using <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP.train" title="psimpy.emulator.robustgasp.ScalarGaSP.train"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ScalarGaSP.train()</span></code></a>. Below we train +an emulator using <span class="math notranslate nohighlight">\(8\)</span> selected points.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> + <span class="c1">#return x + 3*np.sin(x/2)</span> + <span class="k">return</span> <span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> + +<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> +<span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> + +<span class="n">emulator</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">design</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">response</span><span class="o">=</span><span class="n">y</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>The upper bounds of the range parameters are 1881,404 +The initial values of range parameters are 37,62809 +Start of the optimization 1 : +The number of iterations is 9 + The value of the marginal posterior function is -13,79116 + Optimized range parameters are 2,237467 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,21875 +Start of the optimization 2 : +The number of iterations is 9 + The value of the marginal posterior function is -13,79116 + Optimized range parameters are 2,237467 + Optimized nugget parameter is 0 + Convergence: TRUE +</pre></div> +</div> +<p>We can validate the performance of the trained emulator using the leave-one-out +cross validation method <code class="xref py py-meth docutils literal notranslate"><span class="pre">loo_validate()</span></code>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">validation</span> <span class="o">=</span> <span class="n">emulator</span><span class="o">.</span><span class="n">loo_validate</span><span class="p">()</span> +</pre></div> +</div> +<p>Let’s plot emulator predictions vs actual outputs. The error bar indicates the +standard deviation.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span> <span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'Actual y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Emulator-predicted y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> + +<span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">errorbar</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">validation</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">validation</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">fmt</span><span class="o">=</span><span class="s1">'.'</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'prediction and std'</span><span class="p">)</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_scalargasp_001.png" srcset="../../_images/sphx_glr_plot_scalargasp_001.png" alt="plot scalargasp" class = "sphx-glr-single-img"/><p>With the trained emulator at our deposit, we can use the +<a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP.predict" title="psimpy.emulator.robustgasp.ScalarGaSP.predict"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ScalarGaSP.predict()</span></code></a> method to make predictions at +any arbitrary set of input points (<code class="docutils literal notranslate"><span class="pre">testing_input</span></code>). It should be noted that, +<code class="docutils literal notranslate"><span class="pre">testing_trend</span></code> should be set according to <code class="docutils literal notranslate"><span class="pre">trend</span></code> used during emulator +training.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">testing_input</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mf">0.1</span><span class="p">)</span> +<span class="n">predictions</span> <span class="o">=</span> <span class="n">emulator</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">testing_input</span><span class="p">)</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">predictions</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">],</span> <span class="s1">'r-'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span> <span class="s2">"mean"</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'k'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">"training data"</span><span class="p">,</span> <span class="n">zorder</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">f</span><span class="p">(</span><span class="n">testing_input</span><span class="p">),</span> <span class="s1">'k:'</span><span class="p">,</span> <span class="n">zorder</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">"true function"</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">fill_between</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">predictions</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">predictions</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.3</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">"95% CI"</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">'emulator-predicted y'</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="n">testing_input</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">testing_input</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_scalargasp_002.png" srcset="../../_images/sphx_glr_plot_scalargasp_002.png" alt="plot scalargasp" class = "sphx-glr-single-img"/><p>We can also draw any number of samples at <code class="docutils literal notranslate"><span class="pre">testing_input`</span></code> using +<a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP.sample" title="psimpy.emulator.robustgasp.ScalarGaSP.sample"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ScalarGaSP.sample()</span></code></a> method.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">nsamples</span> <span class="o">=</span> <span class="mi">5</span> +<span class="n">samples</span> <span class="o">=</span> <span class="n">emulator</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">nsamples</span><span class="o">=</span><span class="n">nsamples</span><span class="p">)</span> + +<span class="c1"># sphinx_gallery_thumbnail_number = 3</span> +<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nsamples</span><span class="p">):</span> + <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">samples</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="s1">'--'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="sa">f</span><span class="s1">'sample</span><span class="si">{</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'k'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">"training data"</span><span class="p">,</span> <span class="n">zorder</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">f</span><span class="p">(</span><span class="n">testing_input</span><span class="p">),</span> <span class="s1">'k:'</span><span class="p">,</span> <span class="n">zorder</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">"true function"</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">fill_between</span><span class="p">(</span><span class="n">testing_input</span><span class="p">,</span> <span class="n">predictions</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">predictions</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.3</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">"95% CI"</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">'emulator-predicted y'</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="n">testing_input</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">testing_input</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_scalargasp_003.png" srcset="../../_images/sphx_glr_plot_scalargasp_003.png" alt="plot scalargasp" class = "sphx-glr-single-img"/><div class="admonition tip"> +<p class="admonition-title">Tip</p> +<p>Above example shows how to train a GP emulator based on noise-free training data, +which is often the case of emulating a deterministic simulator. If you are dealing +with noisy training data, you can</p> +<blockquote> +<div><ul class="simple"> +<li><p>set the parameter <code class="docutils literal notranslate"><span class="pre">nugget</span></code> to a desired value, or</p></li> +<li><p>set <code class="docutils literal notranslate"><span class="pre">nugget</span></code> to <span class="math notranslate nohighlight">\(0\)</span> and <code class="docutils literal notranslate"><span class="pre">nugget_est</span></code> to <cite>True</cite>, meaning that <code class="docutils literal notranslate"><span class="pre">nugget</span></code> +is estimated from the noisy training data.</p></li> +</ul> +</div></blockquote> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 0.728 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-emulator-plot-scalargasp-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/ca97a6211ade4816b175cce5bc31a34b/plot_scalargasp.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_scalargasp.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/8c06e92daa6ae4230f607ca4f47a3769/plot_scalargasp.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_scalargasp.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_ppgasp.html" class="btn btn-neutral float-left" title="PPGaSP: GP emulation for multi-output functions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="../inference/index.html" class="btn btn-neutral float-right" title="Inference" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/emulator/sg_execution_times.html b/docs/source/_build/html/auto_examples/emulator/sg_execution_times.html new file mode 100644 index 0000000000000000000000000000000000000000..c67dc830502c50c53c9296abe1583eef3c39f753 --- /dev/null +++ b/docs/source/_build/html/auto_examples/emulator/sg_execution_times.html @@ -0,0 +1,131 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Computation times — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../examples.html">Example Gallery</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item active">Computation times</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/emulator/sg_execution_times.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="computation-times"> +<span id="sphx-glr-auto-examples-emulator-sg-execution-times"></span><h1>Computation times<a class="headerlink" href="#computation-times" title="Permalink to this heading"></a></h1> +<p><strong>00:06.062</strong> total execution time for <strong>auto_examples_emulator</strong> files:</p> +<table class="docutils align-default"> +<colgroup> +<col style="width: 82%" /> +<col style="width: 11%" /> +<col style="width: 8%" /> +</colgroup> +<tbody> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_ppgasp.html#sphx-glr-auto-examples-emulator-plot-ppgasp-py"><span class="std std-ref">PPGaSP: GP emulation for multi-output functions</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_ppgasp.py</span></code>)</p></td> +<td><p>00:05.333</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-even"><td><p><a class="reference internal" href="plot_scalargasp.html#sphx-glr-auto-examples-emulator-plot-scalargasp-py"><span class="std std-ref">ScalarGaSP: GP emulation for a single-output function</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_scalargasp.py</span></code>)</p></td> +<td><p>00:00.728</p></td> +<td><p>0.0 MB</p></td> +</tr> +</tbody> +</table> +</section> + + + </div> + </div> + <footer> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/inference/index.html b/docs/source/_build/html/auto_examples/inference/index.html new file mode 100644 index 0000000000000000000000000000000000000000..6d740226a50c4bc4eb729aa50059549734c9834d --- /dev/null +++ b/docs/source/_build/html/auto_examples/inference/index.html @@ -0,0 +1,147 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Inference — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Bayesian inference" href="plot_bayes_inference.html" /> + <link rel="prev" title="ScalarGaSP: GP emulation for a single-output function" href="../emulator/plot_scalargasp.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2 current"><a class="current reference internal" href="#">Inference</a><ul> +<li class="toctree-l3"><a class="reference internal" href="plot_bayes_inference.html">Bayesian inference</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_active_learning.html">Active learning</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item active">Inference</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/inference/index.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="inference"> +<h1>Inference<a class="headerlink" href="#inference" title="Permalink to this heading"></a></h1> +<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="Bayesian inference"><img alt="Bayesian inference" src="../../_images/sphx_glr_plot_bayes_inference_thumb.png" /> +<p><a class="reference internal" href="plot_bayes_inference.html#sphx-glr-auto-examples-inference-plot-bayes-inference-py"><span class="std std-ref">Bayesian inference</span></a></p> + <div class="sphx-glr-thumbnail-title">Bayesian inference</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="Active learning"><img alt="Active learning" src="../../_images/sphx_glr_plot_active_learning_thumb.png" /> +<p><a class="reference internal" href="plot_active_learning.html#sphx-glr-auto-examples-inference-plot-active-learning-py"><span class="std std-ref">Active learning</span></a></p> + <div class="sphx-glr-thumbnail-title">Active learning</div> +</div></div><div class="toctree-wrapper compound"> +</div> +<div class="sphx-glr-footer sphx-glr-footer-gallery docutils container"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/4647ee707541b918a88f2f6fccfe8f6e/inference_python.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">inference_python.zip</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/a7f224bf083830ea00d3ddeb607984f7/inference_jupyter.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Jupyter</span> <span class="pre">notebooks:</span> <span class="pre">inference_jupyter.zip</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="../emulator/plot_scalargasp.html" class="btn btn-neutral float-left" title="ScalarGaSP: GP emulation for a single-output function" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_bayes_inference.html" class="btn btn-neutral float-right" title="Bayesian inference" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/inference/plot_active_learning.html b/docs/source/_build/html/auto_examples/inference/plot_active_learning.html new file mode 100644 index 0000000000000000000000000000000000000000..4068de96ade14c025eb924a47452c9d516a33a9e --- /dev/null +++ b/docs/source/_build/html/auto_examples/inference/plot_active_learning.html @@ -0,0 +1,1174 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Active learning — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Sampler" href="../sampler/index.html" /> + <link rel="prev" title="Bayesian inference" href="plot_bayes_inference.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Inference</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_bayes_inference.html">Bayesian inference</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Active learning</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Inference</a></li> + <li class="breadcrumb-item active">Active learning</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/inference/plot_active_learning.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-inference-plot-active-learning-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="active-learning"> +<span id="sphx-glr-auto-examples-inference-plot-active-learning-py"></span><h1>Active learning<a class="headerlink" href="#active-learning" title="Permalink to this heading"></a></h1> +<p>This example shows how to use the <a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning" title="psimpy.inference.active_learning.ActiveLearning"><code class="xref py py-class docutils literal notranslate"><span class="pre">ActiveLearning</span></code></a> class to iteratively +build a Gaussian process emulator for an unnormalized posterior involving a +simulator. It should be noted that this example is only for illustration +purpose, rather than a real case. For simplicity, required arguments for +<a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning" title="psimpy.inference.active_learning.ActiveLearning"><code class="xref py py-class docutils literal notranslate"><span class="pre">ActiveLearning</span></code></a> (including <cite>simulator</cite>, <cite>likelihood</cite>, <cite>data</cite>, etc.) are purely +made up. For a realistic case of active learning, one can refer to <span id="id1">Zhao and Kowalski [<a class="reference internal" href="../../refs.html#id16" title="Hu Zhao and Julia Kowalski. Bayesian active learning for parameter calibration of landslide run-out models. Landslides, 19():2033–2045, 2022. doi:https://doi.org/10.1007/s10346-022-01857-z.">2022</a>]</span>.</p> +<p>First, we define the simulator, prior distribution of its variable parameters, +observed data, and likelihood function. They basically define the Bayesian +inference problem.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="n">ndim</span> <span class="o">=</span> <span class="mi">2</span> <span class="c1"># dimension of variable parameters of the simulator</span> +<span class="n">bounds</span> <span class="o">=</span> <span class="n">bounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">],[</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">]])</span> <span class="c1"># bounds of variable parameters</span> +<span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span> + +<span class="k">def</span> <span class="nf">simulator</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">):</span> + <span class="sd">"""Simulator y=f(x)."""</span> + <span class="n">y1</span><span class="p">,</span> <span class="n">y2</span> <span class="o">=</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span> + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">y1</span><span class="p">,</span> <span class="n">y2</span><span class="p">])</span> + +<span class="k">def</span> <span class="nf">prior</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> + <span class="sd">"""Uniform prior."""</span> + <span class="k">return</span> <span class="mi">1</span><span class="o">/</span><span class="p">(</span><span class="mi">10</span><span class="o">*</span><span class="mi">10</span><span class="p">)</span> + +<span class="k">def</span> <span class="nf">likelihood</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> + <span class="sd">"""Likelihood function L(y,data)."""</span> + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">100</span> <span class="o">-</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">data</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> +</pre></div> +</div> +<p>Imagine that the simulator is a complex solver. It is not computationally feasible +to compute the posterior distribution of the variable parameters using grid estimation +or Metropolis Hastings estimation. This is because they require evaluating the likelihood +many times which essentially leads to many evaluations of the simulator. Therefore, we +resort to use active learning to build a Gaussian process emulator for the unnormalized +posterior (prior times likelihood) based on a small number of evaluations of the simulator. +The the posterior can be estimated using the emulator.</p> +<p>To do so, we need to pass arguments to following parameters of the <a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning" title="psimpy.inference.active_learning.ActiveLearning"><code class="xref py py-class docutils literal notranslate"><span class="pre">ActiveLearning</span></code></a> class:</p> +<blockquote> +<div><ul class="simple"> +<li><p>run_sim_obj : instance of class <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a>. It carries information on how +to run the simulator.</p></li> +<li><p>lhs_sampler : instance of class <a class="reference internal" href="../../sampler/latin.html#psimpy.sampler.latin.LHS" title="psimpy.sampler.latin.LHS"><code class="xref py py-class docutils literal notranslate"><span class="pre">LHS</span></code></a>. It is used to draw initial samples to run +simulations in order to train an inital Gaussian process emulator.</p></li> +<li><p>scalar_gasp : instance of class <a class="reference internal" href="../../emulator/robustgasp.html#psimpy.emulator.robustgasp.ScalarGaSP" title="psimpy.emulator.robustgasp.ScalarGaSP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScalarGaSP</span></code></a>. It sets up the emulator structure.</p></li> +</ul> +</div></blockquote> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">RunSimulator</span> +<span class="kn">from</span> <span class="nn">psimpy.sampler</span> <span class="kn">import</span> <span class="n">LHS</span> +<span class="kn">from</span> <span class="nn">psimpy.emulator</span> <span class="kn">import</span> <span class="n">ScalarGaSP</span> + +<span class="n">run_simulator</span> <span class="o">=</span> <span class="n">RunSimulator</span><span class="p">(</span><span class="n">simulator</span><span class="p">,</span> <span class="n">var_inp_parameter</span><span class="o">=</span><span class="p">[</span><span class="s1">'x1'</span><span class="p">,</span><span class="s1">'x2'</span><span class="p">])</span> +<span class="n">lhs_sampler</span> <span class="o">=</span> <span class="n">LHS</span><span class="p">(</span><span class="n">ndim</span><span class="o">=</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="o">=</span><span class="n">bounds</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> +<span class="n">scalar_gasp</span> <span class="o">=</span> <span class="n">ScalarGaSP</span><span class="p">(</span><span class="n">ndim</span><span class="o">=</span><span class="n">ndim</span><span class="p">)</span> +</pre></div> +</div> +<p>Next, we create an object of the <a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning" title="psimpy.inference.active_learning.ActiveLearning"><code class="xref py py-class docutils literal notranslate"><span class="pre">ActiveLearning</span></code></a> class by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.inference</span> <span class="kn">import</span> <span class="n">ActiveLearning</span> + +<span class="n">active_learner</span> <span class="o">=</span> <span class="n">ActiveLearning</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">run_simulator</span><span class="p">,</span> <span class="n">prior</span><span class="p">,</span> <span class="n">likelihood</span><span class="p">,</span> + <span class="n">lhs_sampler</span><span class="p">,</span> <span class="n">scalar_gasp</span><span class="p">)</span> +</pre></div> +</div> +<p>Then we can call the <a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning.initial_simulation" title="psimpy.inference.active_learning.ActiveLearning.initial_simulation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ActiveLearning.initial_simulation()</span></code></a> method to run initial +simulations and call the <a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning.iterative_emulation" title="psimpy.inference.active_learning.ActiveLearning.iterative_emulation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ActiveLearning.iterative_emulation()</span></code></a> method to +iteratively run new simulation and build emulator. Here we allocate 40 simulations for +initial emulator training and 60 simulations for adaptive training.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">n0</span> <span class="o">=</span> <span class="mi">40</span> +<span class="n">niter</span> <span class="o">=</span> <span class="mi">60</span> + +<span class="n">init_var_samples</span><span class="p">,</span> <span class="n">init_sim_outputs</span> <span class="o">=</span> <span class="n">active_learner</span><span class="o">.</span><span class="n">initial_simulation</span><span class="p">(</span> + <span class="n">n0</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">'parallel'</span><span class="p">,</span> <span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> + +<span class="n">var_samples</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">active_learner</span><span class="o">.</span><span class="n">iterative_emulation</span><span class="p">(</span> + <span class="n">n0</span><span class="p">,</span> <span class="n">init_var_samples</span><span class="p">,</span> <span class="n">init_sim_outputs</span><span class="p">,</span> <span class="n">niter</span><span class="o">=</span><span class="n">niter</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>The upper bounds of the range parameters are 401,3482 397,4694 +The initial values of range parameters are 8,026963 7,949389 +Start of the optimization 1 : +The number of iterations is 22 + The value of the marginal posterior function is -146,5038 + Optimized range parameters are 30,59853 130,6077 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,9828751 0,9733764 +Start of the optimization 2 : +The number of iterations is 36 + The value of the marginal posterior function is -146,5038 + Optimized range parameters are 30,59827 130,6067 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 423,194 420,3365 +The initial values of range parameters are 8,463881 8,40673 +Start of the optimization 1 : +The number of iterations is 13 + The value of the marginal posterior function is -148,6792 + Optimized range parameters are 30,19534 133,3286 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,9589025 0,9524277 +Start of the optimization 2 : +The number of iterations is 12 + The value of the marginal posterior function is -148,6792 + Optimized range parameters are 30,19539 133,329 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 422,8426 419,9874 +The initial values of range parameters are 8,456851 8,399747 +Start of the optimization 1 : +The number of iterations is 34 + The value of the marginal posterior function is -149,9595 + Optimized range parameters are 30,64771 135,0597 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,9360715 0,9297509 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -149,9595 + Optimized range parameters are 30,64696 135,0536 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 423,2876 420,4294 +The initial values of range parameters are 8,465751 8,408588 +Start of the optimization 1 : +The number of iterations is 25 + The value of the marginal posterior function is -151,304 + Optimized range parameters are 31,21605 136,8571 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,9143024 0,9081287 +Start of the optimization 2 : +The number of iterations is 23 + The value of the marginal posterior function is -151,304 + Optimized range parameters are 31,21617 136,8537 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 389,6167 386,9859 +The initial values of range parameters are 7,792334 7,739717 +Start of the optimization 1 : +The number of iterations is 13 + The value of the marginal posterior function is -152,6009 + Optimized range parameters are 32,285 141,3784 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,8935228 0,8874894 +Start of the optimization 2 : +The number of iterations is 17 + The value of the marginal posterior function is -152,6009 + Optimized range parameters are 32,28096 141,3737 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 368,8855 366,3947 +The initial values of range parameters are 7,377711 7,327894 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -153,5419 + Optimized range parameters are 32,43481 141,7852 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,8736668 0,8677675 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -153,5419 + Optimized range parameters are 32,43357 141,7844 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 339,4555 337,1634 +The initial values of range parameters are 6,789111 6,743268 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -154,9929 + Optimized range parameters are 33,69448 151,2103 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,854674 0,848903 +Start of the optimization 2 : +The number of iterations is 22 + The value of the marginal posterior function is -154,9929 + Optimized range parameters are 33,69468 151,2111 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 369,9581 367,46 +The initial values of range parameters are 7,399163 7,349201 +Start of the optimization 1 : +The number of iterations is 26 + The value of the marginal posterior function is -155,4764 + Optimized range parameters are 33,90556 152,0139 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,8364895 0,8308412 +Start of the optimization 2 : +The number of iterations is 23 + The value of the marginal posterior function is -155,4764 + Optimized range parameters are 33,90541 152,0137 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 299,8308 297,8062 +The initial values of range parameters are 5,996615 5,956124 +Start of the optimization 1 : +The number of iterations is 27 + The value of the marginal posterior function is -155,8802 + Optimized range parameters are 34,04389 152,6133 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,8190626 0,813532 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -155,8802 + Optimized range parameters are 34,04381 152,6131 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 272,589 270,7484 +The initial values of range parameters are 5,45178 5,414968 +Start of the optimization 1 : +The number of iterations is 22 + The value of the marginal posterior function is -156,1383 + Optimized range parameters are 34,46966 151,4246 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,802347 0,7969293 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -156,1383 + Optimized range parameters are 34,46972 151,4261 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 217,1413 215,6751 +The initial values of range parameters are 4,342826 4,313501 +Start of the optimization 1 : +The number of iterations is 16 + The value of the marginal posterior function is -156,184 + Optimized range parameters are 34,52228 152,8428 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,7863001 0,7809907 +Start of the optimization 2 : +The number of iterations is 29 + The value of the marginal posterior function is -156,184 + Optimized range parameters are 34,5049 152,8145 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 206,6122 205,2171 +The initial values of range parameters are 4,132244 4,104342 +Start of the optimization 1 : +The number of iterations is 25 + The value of the marginal posterior function is -156,2348 + Optimized range parameters are 34,79805 155,1646 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,7708824 0,7656772 +Start of the optimization 2 : +The number of iterations is 22 + The value of the marginal posterior function is -156,2348 + Optimized range parameters are 34,82503 155,2481 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 264,8501 263,0618 +The initial values of range parameters are 5,297002 5,261235 +Start of the optimization 1 : +The number of iterations is 30 + The value of the marginal posterior function is -156,4063 + Optimized range parameters are 34,74024 156,9499 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,7560578 0,7509526 +Start of the optimization 2 : +The number of iterations is 35 + The value of the marginal posterior function is -156,4062 + Optimized range parameters are 34,71806 156,8712 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 255,2317 253,5083 +The initial values of range parameters are 5,104633 5,070165 +Start of the optimization 1 : +The number of iterations is 20 + The value of the marginal posterior function is -156,5552 + Optimized range parameters are 35,37305 157,5615 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,7417925 0,7367837 +Start of the optimization 2 : +The number of iterations is 37 + The value of the marginal posterior function is -156,5552 + Optimized range parameters are 35,37704 157,591 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 234,5139 232,9304 +The initial values of range parameters are 4,690278 4,658607 +Start of the optimization 1 : +The number of iterations is 25 + The value of the marginal posterior function is -156,8767 + Optimized range parameters are 35,91747 161,0899 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,7280556 0,7231396 +Start of the optimization 2 : +The number of iterations is 32 + The value of the marginal posterior function is -156,8767 + Optimized range parameters are 35,92577 161,0559 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 237,6023 235,9979 +The initial values of range parameters are 4,752045 4,719958 +Start of the optimization 1 : +The number of iterations is 15 + The value of the marginal posterior function is -156,6342 + Optimized range parameters are 36,30341 161,9859 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,7148183 0,7099916 +Start of the optimization 2 : +The number of iterations is 26 + The value of the marginal posterior function is -156,6343 + Optimized range parameters are 36,30117 161,8561 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 231,5375 229,9741 +The initial values of range parameters are 4,63075 4,599482 +Start of the optimization 1 : +The number of iterations is 27 + The value of the marginal posterior function is -156,3683 + Optimized range parameters are 36,27212 162,5847 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,7020536 0,6973131 +Start of the optimization 2 : +The number of iterations is 30 + The value of the marginal posterior function is -156,3684 + Optimized range parameters are 36,25962 162,5355 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 237,6502 236,0455 +The initial values of range parameters are 4,753005 4,720911 +Start of the optimization 1 : +The number of iterations is 14 + The value of the marginal posterior function is -156,014 + Optimized range parameters are 36,19577 162,4854 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,6897369 0,6850796 +Start of the optimization 2 : +The number of iterations is 27 + The value of the marginal posterior function is -156,014 + Optimized range parameters are 36,19621 162,4877 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 221,4001 219,9051 +The initial values of range parameters are 4,428002 4,398102 +Start of the optimization 1 : +The number of iterations is 36 + The value of the marginal posterior function is -155,8456 + Optimized range parameters are 36,93092 166,708 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,6778449 0,6732679 +Start of the optimization 2 : +The number of iterations is 19 + The value of the marginal posterior function is -155,8455 + Optimized range parameters are 37,00954 166,8438 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 207,5545 206,153 +The initial values of range parameters are 4,15109 4,123061 +Start of the optimization 1 : +The number of iterations is 36 + The value of the marginal posterior function is -155,2611 + Optimized range parameters are 37,54574 171,0122 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,666356 0,6618565 +Start of the optimization 2 : +The number of iterations is 26 + The value of the marginal posterior function is -155,2611 + Optimized range parameters are 37,52707 170,9901 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 211,1368 209,7111 +The initial values of range parameters are 4,222736 4,194222 +Start of the optimization 1 : +The number of iterations is 38 + The value of the marginal posterior function is -154,6105 + Optimized range parameters are 37,27271 173,4402 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,6552501 0,6508256 +Start of the optimization 2 : +The number of iterations is 38 + The value of the marginal posterior function is -154,6104 + Optimized range parameters are 37,31152 173,4271 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 229,1987 227,651 +The initial values of range parameters are 4,583973 4,553021 +Start of the optimization 1 : +The number of iterations is 30 + The value of the marginal posterior function is -153,8922 + Optimized range parameters are 37,52317 173,0118 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,6445083 0,6401563 +Start of the optimization 2 : +The number of iterations is 29 + The value of the marginal posterior function is -153,8923 + Optimized range parameters are 37,52772 173,0381 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 200,215 198,8631 +The initial values of range parameters are 4,004301 3,977262 +Start of the optimization 1 : +The number of iterations is 29 + The value of the marginal posterior function is -153,0737 + Optimized range parameters are 37,6626 173,7851 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,634113 0,6298312 +Start of the optimization 2 : +The number of iterations is 38 + The value of the marginal posterior function is -153,0733 + Optimized range parameters are 37,57977 172,9914 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 208,2931 206,8866 +The initial values of range parameters are 4,165862 4,137733 +Start of the optimization 1 : +The number of iterations is 31 + The value of the marginal posterior function is -152,171 + Optimized range parameters are 37,55899 172,4488 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,6240477 0,6198339 +Start of the optimization 2 : +The number of iterations is 34 + The value of the marginal posterior function is -152,1711 + Optimized range parameters are 37,55216 172,3431 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 190,9562 189,6668 +The initial values of range parameters are 3,819124 3,793336 +Start of the optimization 1 : +The number of iterations is 26 + The value of the marginal posterior function is -151,4191 + Optimized range parameters are 37,87024 177,6757 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,6142969 0,610149 +Start of the optimization 2 : +The number of iterations is 31 + The value of the marginal posterior function is -151,4191 + Optimized range parameters are 37,8678 177,4358 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 187,3139 186,0491 +The initial values of range parameters are 3,746279 3,720983 +Start of the optimization 1 : +The number of iterations is 27 + The value of the marginal posterior function is -150,3521 + Optimized range parameters are 37,93228 177,0193 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,6048462 0,6007621 +Start of the optimization 2 : +The number of iterations is 15 + The value of the marginal posterior function is -150,3521 + Optimized range parameters are 37,92683 176,9819 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 201,0467 199,6892 +The initial values of range parameters are 4,020934 3,993783 +Start of the optimization 1 : +The number of iterations is 31 + The value of the marginal posterior function is -149,229 + Optimized range parameters are 37,73923 179,7933 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5956819 0,5916596 +Start of the optimization 2 : +The number of iterations is 23 + The value of the marginal posterior function is -149,2295 + Optimized range parameters are 37,68347 179,3098 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 208,1589 206,7533 +The initial values of range parameters are 4,163178 4,135067 +Start of the optimization 1 : +The number of iterations is 31 + The value of the marginal posterior function is -148,0364 + Optimized range parameters are 37,10463 181,452 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,5867911 0,5828289 +Start of the optimization 2 : +The number of iterations is 28 + The value of the marginal posterior function is -148,0353 + Optimized range parameters are 37,10023 181,8802 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 207,5545 206,153 +The initial values of range parameters are 4,15109 4,123061 +Start of the optimization 1 : +The number of iterations is 31 + The value of the marginal posterior function is -147,2549 + Optimized range parameters are 36,89036 184,8898 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,5781618 0,5742579 +Start of the optimization 2 : +The number of iterations is 18 + The value of the marginal posterior function is -147,2555 + Optimized range parameters are 36,87001 184,82 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 166,9279 165,8008 +The initial values of range parameters are 3,338559 3,316015 +Start of the optimization 1 : +The number of iterations is 24 + The value of the marginal posterior function is -146,0908 + Optimized range parameters are 34,10173 165,8008 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5697827 0,5659353 +Start of the optimization 2 : +The number of iterations is 12 + The value of the marginal posterior function is -146,091 + Optimized range parameters are 34,11888 165,8008 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 164,9351 163,8214 +The initial values of range parameters are 3,298703 3,276429 +Start of the optimization 1 : +The number of iterations is 29 + The value of the marginal posterior function is -144,8362 + Optimized range parameters are 33,02363 163,8214 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5616429 0,5578505 +Start of the optimization 2 : +The number of iterations is 15 + The value of the marginal posterior function is -144,8366 + Optimized range parameters are 32,96846 163,8214 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 161,9899 160,8961 +The initial values of range parameters are 3,239799 3,217922 +Start of the optimization 1 : +The number of iterations is 30 + The value of the marginal posterior function is -143,1679 + Optimized range parameters are 32,60853 160,8961 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5537325 0,5499935 +Start of the optimization 2 : +The number of iterations is 23 + The value of the marginal posterior function is -143,1673 + Optimized range parameters are 32,60514 160,8961 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 167,4923 166,3613 +The initial values of range parameters are 3,349846 3,327227 +Start of the optimization 1 : +The number of iterations is 31 + The value of the marginal posterior function is -141,4524 + Optimized range parameters are 32,84554 166,3613 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5460417 0,5423547 +Start of the optimization 2 : +The number of iterations is 10 + The value of the marginal posterior function is -141,4531 + Optimized range parameters are 32,87053 166,3613 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 158,1908 157,1226 +The initial values of range parameters are 3,163815 3,142452 +Start of the optimization 1 : +The number of iterations is 21 + The value of the marginal posterior function is -140,039 + Optimized range parameters are 31,62214 157,1226 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5385617 0,5349251 +Start of the optimization 2 : +The number of iterations is 16 + The value of the marginal posterior function is -140,0387 + Optimized range parameters are 31,62433 157,1226 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 174,0066 172,8316 +The initial values of range parameters are 3,480131 3,456632 +Start of the optimization 1 : +The number of iterations is 23 + The value of the marginal posterior function is -138,1222 + Optimized range parameters are 33,48823 172,8316 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5312838 0,5276964 +Start of the optimization 2 : +The number of iterations is 28 + The value of the marginal posterior function is -138,1223 + Optimized range parameters are 33,40525 172,8316 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 150,4312 149,4154 +The initial values of range parameters are 3,008624 2,988309 +Start of the optimization 1 : +The number of iterations is 21 + The value of the marginal posterior function is -139,2082 + Optimized range parameters are 30,85041 149,4154 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,5242001 0,5206605 +Start of the optimization 2 : +The number of iterations is 25 + The value of the marginal posterior function is -139,2085 + Optimized range parameters are 30,93585 149,4154 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 163,2096 162,1076 +The initial values of range parameters are 3,264193 3,242152 +Start of the optimization 1 : +The number of iterations is 30 + The value of the marginal posterior function is -136,829 + Optimized range parameters are 31,64889 162,1076 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5173027 0,5138097 +Start of the optimization 2 : +The number of iterations is 29 + The value of the marginal posterior function is -136,8292 + Optimized range parameters are 31,73272 162,1076 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 155,3651 154,316 +The initial values of range parameters are 3,107301 3,08632 +Start of the optimization 1 : +The number of iterations is 38 + The value of the marginal posterior function is -137,2507 + Optimized range parameters are 31,11748 154,316 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5105845 0,5071368 +Start of the optimization 2 : +The number of iterations is 11 + The value of the marginal posterior function is -137,2507 + Optimized range parameters are 31,11466 154,316 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 159,0334 157,9595 +The initial values of range parameters are 3,180667 3,15919 +Start of the optimization 1 : +The number of iterations is 19 + The value of the marginal posterior function is -134,9592 + Optimized range parameters are 30,6283 157,9595 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,5040385 0,5006351 +Start of the optimization 2 : +The number of iterations is 20 + The value of the marginal posterior function is -134,9589 + Optimized range parameters are 30,62948 157,9595 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 150,6829 149,6655 +The initial values of range parameters are 3,013659 2,993309 +Start of the optimization 1 : +The number of iterations is 9 + The value of the marginal posterior function is -133,0322 + Optimized range parameters are 28,62106 149,6655 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4976583 0,4942979 +Start of the optimization 2 : +The number of iterations is 27 + The value of the marginal posterior function is -133,0311 + Optimized range parameters are 28,6202 149,6655 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 143,0785 142,1124 +The initial values of range parameters are 2,86157 2,842247 +Start of the optimization 1 : +The number of iterations is 27 + The value of the marginal posterior function is -131,5134 + Optimized range parameters are 27,05986 142,1124 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,4914376 0,4881192 +Start of the optimization 2 : +The number of iterations is 28 + The value of the marginal posterior function is -131,5142 + Optimized range parameters are 27,09861 142,1124 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 149,9901 148,9774 +The initial values of range parameters are 2,999803 2,979547 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -128,3138 + Optimized range parameters are 26,94379 148,9774 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4853704 0,482093 +Start of the optimization 2 : +The number of iterations is 11 + The value of the marginal posterior function is -128,3136 + Optimized range parameters are 26,93153 148,9774 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 141,9733 141,0146 +The initial values of range parameters are 2,839465 2,820292 +Start of the optimization 1 : +The number of iterations is 15 + The value of the marginal posterior function is -126,565 + Optimized range parameters are 25,84325 141,0146 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4794513 0,4762139 +Start of the optimization 2 : +The number of iterations is 30 + The value of the marginal posterior function is -126,5658 + Optimized range parameters are 25,84843 141,0146 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 148,4124 147,4103 +The initial values of range parameters are 2,968249 2,948206 +Start of the optimization 1 : +The number of iterations is 14 + The value of the marginal posterior function is -123,2249 + Optimized range parameters are 26,04536 147,4103 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4736748 0,4704763 +Start of the optimization 2 : +The number of iterations is 37 + The value of the marginal posterior function is -123,2255 + Optimized range parameters are 26,11794 147,4103 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 141,3136 140,3594 +The initial values of range parameters are 2,826273 2,807189 +Start of the optimization 1 : +The number of iterations is 24 + The value of the marginal posterior function is -121,373 + Optimized range parameters are 25,34355 140,3594 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,4680358 0,4648754 +Start of the optimization 2 : +The number of iterations is 27 + The value of the marginal posterior function is -121,3719 + Optimized range parameters are 25,3222 140,3594 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 146,0605 145,0743 +The initial values of range parameters are 2,921211 2,901486 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -119,1731 + Optimized range parameters are 25,38398 145,0743 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4625295 0,4594063 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -119,1742 + Optimized range parameters are 25,27086 145,0743 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 136,1432 135,2239 +The initial values of range parameters are 2,722864 2,704479 +Start of the optimization 1 : +The number of iterations is 16 + The value of the marginal posterior function is -117,4765 + Optimized range parameters are 23,8631 135,2239 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4571512 0,4540644 +Start of the optimization 2 : +The number of iterations is 31 + The value of the marginal posterior function is -117,4779 + Optimized range parameters are 23,87798 135,2239 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 121,8399 121,0172 +The initial values of range parameters are 2,436797 2,420343 +Start of the optimization 1 : +The number of iterations is 21 + The value of the marginal posterior function is -117,2996 + Optimized range parameters are 22,38443 121,0172 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,4518966 0,4488452 +Start of the optimization 2 : +The number of iterations is 19 + The value of the marginal posterior function is -117,2989 + Optimized range parameters are 22,37563 121,0172 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 123,1404 122,309 +The initial values of range parameters are 2,462809 2,446179 +Start of the optimization 1 : +The number of iterations is 18 + The value of the marginal posterior function is -114,6525 + Optimized range parameters are 22,32619 122,309 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4467614 0,4437447 +Start of the optimization 2 : +The number of iterations is 38 + The value of the marginal posterior function is -114,6523 + Optimized range parameters are 22,33099 122,309 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 117,4477 116,6546 +The initial values of range parameters are 2,348953 2,333092 +Start of the optimization 1 : +The number of iterations is 23 + The value of the marginal posterior function is -113,3472 + Optimized range parameters are 21,62668 116,6546 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,4417416 0,4387588 +Start of the optimization 2 : +The number of iterations is 28 + The value of the marginal posterior function is -113,3475 + Optimized range parameters are 21,65104 116,6546 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 115,2499 114,4717 +The initial values of range parameters are 2,304998 2,289433 +Start of the optimization 1 : +The number of iterations is 12 + The value of the marginal posterior function is -110,7155 + Optimized range parameters are 20,98512 114,4717 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4368334 0,4338837 +Start of the optimization 2 : +The number of iterations is 30 + The value of the marginal posterior function is -110,7149 + Optimized range parameters are 21,00228 114,4717 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 111,8946 111,139 +The initial values of range parameters are 2,237892 2,222781 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -108,5065 + Optimized range parameters are 20,44681 111,139 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,432033 0,4291158 +Start of the optimization 2 : +The number of iterations is 19 + The value of the marginal posterior function is -108,507 + Optimized range parameters are 20,44983 111,139 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 93,38518 92,75461 +The initial values of range parameters are 1,867704 1,855092 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -111,367 + Optimized range parameters are 18,37032 92,75461 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,427337 0,4244515 +Start of the optimization 2 : +The number of iterations is 18 + The value of the marginal posterior function is -111,3671 + Optimized range parameters are 18,37078 92,75461 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 99,64494 98,97211 +The initial values of range parameters are 1,992899 1,979442 +Start of the optimization 1 : +The number of iterations is 23 + The value of the marginal posterior function is -106,2562 + Optimized range parameters are 18,89163 98,97211 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,422742 0,4198875 +Start of the optimization 2 : +The number of iterations is 27 + The value of the marginal posterior function is -106,2561 + Optimized range parameters are 18,88065 98,97211 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 99,75194 99,07838 +The initial values of range parameters are 1,995039 1,981568 +Start of the optimization 1 : +The number of iterations is 17 + The value of the marginal posterior function is -103,2099 + Optimized range parameters are 18,65492 99,07838 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4182447 0,4154206 +Start of the optimization 2 : +The number of iterations is 27 + The value of the marginal posterior function is -103,2113 + Optimized range parameters are 18,65549 99,07838 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 104,3536 103,649 +The initial values of range parameters are 2,087073 2,07298 +Start of the optimization 1 : +The number of iterations is 20 + The value of the marginal posterior function is -98,42375 + Optimized range parameters are 18,87395 103,649 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4138422 0,4110477 +Start of the optimization 2 : +The number of iterations is 27 + The value of the marginal posterior function is -98,42241 + Optimized range parameters are 18,87764 103,649 + Optimized nugget parameter is 0 + Convergence: TRUE +The upper bounds of the range parameters are 103,1118 102,4155 +The initial values of range parameters are 2,062236 2,048311 +Start of the optimization 1 : +The number of iterations is 20 + The value of the marginal posterior function is -95,30729 + Optimized range parameters are 18,51323 102,4155 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,4095313 0,406766 +Start of the optimization 2 : +The number of iterations is 29 + The value of the marginal posterior function is -95,30714 + Optimized range parameters are 18,54824 102,4155 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 95,06543 94,42352 +The initial values of range parameters are 1,901309 1,88847 +Start of the optimization 1 : +The number of iterations is 14 + The value of the marginal posterior function is -95,1497 + Optimized range parameters are 17,52307 94,42352 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,4053093 0,4025725 +Start of the optimization 2 : +The number of iterations is 23 + The value of the marginal posterior function is -95,14898 + Optimized range parameters are 17,55379 94,42352 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 91,10625 90,49107 +The initial values of range parameters are 1,822125 1,809821 +Start of the optimization 1 : +The number of iterations is 21 + The value of the marginal posterior function is -93,31858 + Optimized range parameters are 16,88561 90,49107 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,4011735 0,3984647 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -93,31829 + Optimized range parameters are 16,83654 90,49107 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 95,06911 94,42717 +The initial values of range parameters are 1,901382 1,888543 +Start of the optimization 1 : +The number of iterations is 11 + The value of the marginal posterior function is -88,62383 + Optimized range parameters are 17,19113 94,42717 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 0,3971213 0,3944398 +Start of the optimization 2 : +The number of iterations is 23 + The value of the marginal posterior function is -88,62286 + Optimized range parameters are 17,21816 94,42717 + Optimized nugget parameter is 0 + Convergence: FALSE +The upper bounds of the range parameters are 84,25512 83,6862 +The initial values of range parameters are 1,685102 1,673724 +Start of the optimization 1 : +The number of iterations is 20 + The value of the marginal posterior function is -90,56369 + Optimized range parameters are 16,01921 83,6862 + Optimized nugget parameter is 0 + Convergence: FALSE +The initial values of range parameters are 0,39315 0,3904954 +Start of the optimization 2 : +The number of iterations is 24 + The value of the marginal posterior function is -90,56328 + Optimized range parameters are 16,0189 83,6862 + Optimized nugget parameter is 0 + Convergence: FALSE +</pre></div> +</div> +<p>Once the active learning process is finished, we obtain the final emulator for the +logarithm of the unnormalized posterior, which is given by the +<a class="reference internal" href="../../inference/active_learning.html#psimpy.inference.active_learning.ActiveLearning.approx_ln_pxl" title="psimpy.inference.active_learning.ActiveLearning.approx_ln_pxl"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ActiveLearning.approx_ln_pxl()</span></code></a> method.</p> +<p>We can then estimate the posterior using grid estimation or Metropolis Hastings +estimation based on the emulator. An example is as follows. The contour plot shows +the estimated posterior.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.inference</span> <span class="kn">import</span> <span class="n">GridEstimation</span> +<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">grid_estimator</span> <span class="o">=</span> <span class="n">GridEstimation</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">ln_pxl</span><span class="o">=</span><span class="n">active_learner</span><span class="o">.</span><span class="n">approx_ln_pxl</span><span class="p">)</span> +<span class="n">posterior</span><span class="p">,</span> <span class="n">x_ndim</span> <span class="o">=</span> <span class="n">grid_estimator</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">nbins</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="c1"># initial training points</span> +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">init_var_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">init_var_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'r'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">,</span> + <span class="n">zorder</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'initial training points'</span><span class="p">)</span> +<span class="c1"># actively picked training points</span> +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">var_samples</span><span class="p">[</span><span class="n">n0</span><span class="p">:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">var_samples</span><span class="p">[</span><span class="n">n0</span><span class="p">:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'k'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'+'</span><span class="p">,</span> + <span class="n">zorder</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'iterative training points'</span><span class="p">)</span> + +<span class="c1"># estimated posterior based on the final emulator</span> +<span class="n">posterior</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">posterior</span> <span class="o"><</span> <span class="mf">1e-10</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">posterior</span><span class="p">)</span> +<span class="n">contour</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">contour</span><span class="p">(</span><span class="n">x_ndim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">x_ndim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">posterior</span><span class="p">),</span> <span class="n">levels</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">zorder</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">contour</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Active learning'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x1'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'x2'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">([</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">])</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_active_learning_001.png" srcset="../../_images/sphx_glr_plot_active_learning_001.png" alt="Active learning" class = "sphx-glr-single-img"/><p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 2 minutes 12.653 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-inference-plot-active-learning-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/49e9d5799ebf50f0ee6452a55ef932ec/plot_active_learning.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_active_learning.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/e02cb6046784acec18b4383ffbd83d67/plot_active_learning.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_active_learning.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_bayes_inference.html" class="btn btn-neutral float-left" title="Bayesian inference" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="../sampler/index.html" class="btn btn-neutral float-right" title="Sampler" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/inference/plot_bayes_inference.html b/docs/source/_build/html/auto_examples/inference/plot_bayes_inference.html new file mode 100644 index 0000000000000000000000000000000000000000..9c48546d6b15e2cc543c678bb3f9d7b706f0a66b --- /dev/null +++ b/docs/source/_build/html/auto_examples/inference/plot_bayes_inference.html @@ -0,0 +1,244 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Bayesian inference — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Active learning" href="plot_active_learning.html" /> + <link rel="prev" title="Inference" href="index.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Inference</a><ul class="current"> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Bayesian inference</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_active_learning.html">Active learning</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Inference</a></li> + <li class="breadcrumb-item active">Bayesian inference</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/inference/plot_bayes_inference.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-inference-plot-bayes-inference-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="bayesian-inference"> +<span id="sphx-glr-auto-examples-inference-plot-bayes-inference-py"></span><h1>Bayesian inference<a class="headerlink" href="#bayesian-inference" title="Permalink to this heading"></a></h1> +<p>This example shows how to perform Bayesian inference given the uniform prior</p> +<p><span class="math notranslate nohighlight">\(p(\mathbf{x})=p(x_1,x_2)=0.01\)</span></p> +<p>where <span class="math notranslate nohighlight">\(x_i \in [-5,5], i=1,2\)</span>, and likelihood</p> +<p><span class="math notranslate nohighlight">\(L(\mathbf{x}|\mathbf{d})=\exp \left(-\frac{1}{100}\left(x_1-1\right)^2-\left(x_1^2-x_2\right)^2\right)\)</span>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="n">ndim</span> <span class="o">=</span> <span class="mi">2</span> +<span class="n">bounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">],[</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">]])</span> + +<span class="k">def</span> <span class="nf">prior</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> + <span class="k">return</span> <span class="mf">0.01</span> + +<span class="k">def</span> <span class="nf">likelihood</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">100</span> <span class="o">-</span> <span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="o">-</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> +</pre></div> +</div> +<p>To estimate the posterior using grid estimation, we need to import the +<a class="reference internal" href="../../inference/bayes_inference.html#psimpy.inference.bayes_inference.GridEstimation" title="psimpy.inference.bayes_inference.GridEstimation"><code class="xref py py-class docutils literal notranslate"><span class="pre">GridEstimation</span></code></a> class, create an instance, and call the +<a class="reference internal" href="../../inference/bayes_inference.html#psimpy.inference.bayes_inference.GridEstimation.run" title="psimpy.inference.bayes_inference.GridEstimation.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">GridEstimation.run()</span></code></a> method.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.inference.bayes_inference</span> <span class="kn">import</span> <span class="n">GridEstimation</span> + +<span class="n">grid_estimator</span> <span class="o">=</span> <span class="n">GridEstimation</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">prior</span><span class="p">,</span> <span class="n">likelihood</span><span class="p">)</span> +<span class="n">posterior</span><span class="p">,</span> <span class="n">x_ndim</span> <span class="o">=</span> <span class="n">grid_estimator</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">nbins</span><span class="o">=</span><span class="p">[</span><span class="mi">50</span><span class="p">,</span><span class="mi">40</span><span class="p">])</span> +</pre></div> +</div> +<p>The following figure plots the estimated posterior.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="c1"># mask insignificant values</span> +<span class="n">posterior</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">posterior</span> <span class="o"><</span> <span class="mf">1e-10</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">posterior</span><span class="p">)</span> + +<span class="n">contour</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">contour</span><span class="p">(</span><span class="n">x_ndim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">x_ndim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">posterior</span><span class="p">),</span> <span class="n">levels</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">contour</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Grid estimation'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x1'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'x2'</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_bayes_inference_001.png" srcset="../../_images/sphx_glr_plot_bayes_inference_001.png" alt="Grid estimation" class = "sphx-glr-single-img"/><p>To estimate the posterior using Metropolis Hastings estimation, we need to import +the <a class="reference internal" href="../../inference/bayes_inference.html#psimpy.inference.bayes_inference.MetropolisHastingsEstimation" title="psimpy.inference.bayes_inference.MetropolisHastingsEstimation"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetropolisHastingsEstimation</span></code></a> class, create an instance, and call the +<a class="reference internal" href="../../inference/bayes_inference.html#psimpy.inference.bayes_inference.MetropolisHastingsEstimation.run" title="psimpy.inference.bayes_inference.MetropolisHastingsEstimation.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MetropolisHastingsEstimation.run()</span></code></a> method. The +<a class="reference internal" href="../../inference/bayes_inference.html#psimpy.inference.bayes_inference.MetropolisHastingsEstimation.run" title="psimpy.inference.bayes_inference.MetropolisHastingsEstimation.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MetropolisHastingsEstimation.run()</span></code></a> method has a parameter, <code class="docutils literal notranslate"><span class="pre">mh_sampler</span></code>, +which takes an instance of <a class="reference internal" href="../../sampler/metropolis_hastings.html#psimpy.sampler.metropolis_hastings.MetropolisHastings" title="psimpy.sampler.metropolis_hastings.MetropolisHastings"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetropolisHastings</span></code></a> as argument.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.inference.bayes_inference</span> <span class="kn">import</span> <span class="n">MetropolisHastingsEstimation</span> + +<span class="n">mh_estimator</span> <span class="o">=</span> <span class="n">MetropolisHastingsEstimation</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">prior</span><span class="p">,</span> <span class="n">likelihood</span><span class="p">)</span> + +<span class="c1"># create a mh_sampler</span> +<span class="kn">from</span> <span class="nn">psimpy.sampler.metropolis_hastings</span> <span class="kn">import</span> <span class="n">MetropolisHastings</span> +<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">multivariate_normal</span> + +<span class="n">init_state</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">])</span> +<span class="n">f_sample</span> <span class="o">=</span> <span class="n">multivariate_normal</span><span class="o">.</span><span class="n">rvs</span> +<span class="n">nburn</span> <span class="o">=</span> <span class="mi">100</span> +<span class="n">nthin</span> <span class="o">=</span> <span class="mi">10</span> +<span class="n">seed</span> <span class="o">=</span> <span class="mi">1</span> +<span class="n">kwgs_f_sample</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'random_state'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">default_rng</span><span class="p">(</span><span class="n">seed</span><span class="p">)}</span> + +<span class="n">mh_sampler</span> <span class="o">=</span> <span class="n">MetropolisHastings</span><span class="p">(</span><span class="n">ndim</span><span class="o">=</span><span class="n">ndim</span><span class="p">,</span> <span class="n">init_state</span><span class="o">=</span><span class="n">init_state</span><span class="p">,</span> + <span class="n">f_sample</span><span class="o">=</span><span class="n">f_sample</span><span class="p">,</span> <span class="n">bounds</span><span class="o">=</span><span class="n">bounds</span><span class="p">,</span> <span class="n">nburn</span><span class="o">=</span><span class="n">nburn</span><span class="p">,</span> <span class="n">nthin</span><span class="o">=</span><span class="n">nthin</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="n">seed</span><span class="p">,</span> + <span class="n">kwgs_f_sample</span><span class="o">=</span><span class="n">kwgs_f_sample</span><span class="p">)</span> + +<span class="n">nsamples</span> <span class="o">=</span> <span class="mi">5000</span> +<span class="n">mh_samples</span><span class="p">,</span> <span class="n">mh_accept</span> <span class="o">=</span> <span class="n">mh_estimator</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">nsamples</span><span class="p">,</span> <span class="n">mh_sampler</span><span class="p">)</span> +</pre></div> +</div> +<p>The following figure plots the samples drawn from the unnormalized posterior, +which can be used to estimate the posterior and its poperties.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">mh_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">mh_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'r'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'MH estimation'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x1'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'x2'</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_bayes_inference_002.png" srcset="../../_images/sphx_glr_plot_bayes_inference_002.png" alt="MH estimation" class = "sphx-glr-single-img"/><div class="admonition note"> +<p class="admonition-title">Note</p> +<p>Besides <code class="docutils literal notranslate"><span class="pre">prior</span></code> and <code class="docutils literal notranslate"><span class="pre">likelihood</span></code>, one can also instantiate +the <a class="reference internal" href="../../inference/bayes_inference.html#psimpy.inference.bayes_inference.MetropolisHastingsEstimation" title="psimpy.inference.bayes_inference.MetropolisHastingsEstimation"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetropolisHastingsEstimation</span></code></a> class with</p> +<blockquote> +<div><ul class="simple"> +<li><p><code class="docutils literal notranslate"><span class="pre">ln_prior</span></code> and <code class="docutils literal notranslate"><span class="pre">ln_likelihood</span></code>: Natural logarithm of <code class="docutils literal notranslate"><span class="pre">prior</span></code> and <code class="docutils literal notranslate"><span class="pre">likelihood</span></code>.</p></li> +<li><p><code class="docutils literal notranslate"><span class="pre">ln_pxl</span></code>: Natural logarithm of the product of <code class="docutils literal notranslate"><span class="pre">prior</span></code> and <code class="docutils literal notranslate"><span class="pre">likelihood</span></code>.</p></li> +</ul> +</div></blockquote> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 9.739 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-inference-plot-bayes-inference-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/44f0f511484d9bfd5f8d212c8f287e9e/plot_bayes_inference.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_bayes_inference.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/2d9fc590bc1edb11501b144674a0a949/plot_bayes_inference.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_bayes_inference.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="index.html" class="btn btn-neutral float-left" title="Inference" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_active_learning.html" class="btn btn-neutral float-right" title="Active learning" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/inference/sg_execution_times.html b/docs/source/_build/html/auto_examples/inference/sg_execution_times.html new file mode 100644 index 0000000000000000000000000000000000000000..f396b9ae29cce9a79d5b928df42a3f962fa23b50 --- /dev/null +++ b/docs/source/_build/html/auto_examples/inference/sg_execution_times.html @@ -0,0 +1,131 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Computation times — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../examples.html">Example Gallery</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item active">Computation times</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/inference/sg_execution_times.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="computation-times"> +<span id="sphx-glr-auto-examples-inference-sg-execution-times"></span><h1>Computation times<a class="headerlink" href="#computation-times" title="Permalink to this heading"></a></h1> +<p><strong>02:22.392</strong> total execution time for <strong>auto_examples_inference</strong> files:</p> +<table class="docutils align-default"> +<colgroup> +<col style="width: 83%" /> +<col style="width: 10%" /> +<col style="width: 7%" /> +</colgroup> +<tbody> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_active_learning.html#sphx-glr-auto-examples-inference-plot-active-learning-py"><span class="std std-ref">Active learning</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_active_learning.py</span></code>)</p></td> +<td><p>02:12.653</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-even"><td><p><a class="reference internal" href="plot_bayes_inference.html#sphx-glr-auto-examples-inference-plot-bayes-inference-py"><span class="std std-ref">Bayesian inference</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_bayes_inference.py</span></code>)</p></td> +<td><p>00:09.739</p></td> +<td><p>0.0 MB</p></td> +</tr> +</tbody> +</table> +</section> + + + </div> + </div> + <footer> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sampler/index.html b/docs/source/_build/html/auto_examples/sampler/index.html new file mode 100644 index 0000000000000000000000000000000000000000..221c96f942be161440243e6a7bfcd0e67f40e346 --- /dev/null +++ b/docs/source/_build/html/auto_examples/sampler/index.html @@ -0,0 +1,151 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Sampler — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Saltelli sampling" href="plot_saltelli.html" /> + <link rel="prev" title="Active learning" href="../inference/plot_active_learning.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2 current"><a class="current reference internal" href="#">Sampler</a><ul> +<li class="toctree-l3"><a class="reference internal" href="plot_saltelli.html">Saltelli sampling</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_latin.html">Latin hypercube sampling</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_metropolis_hastings.html">Metropolis Hastings sampling</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item active">Sampler</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sampler/index.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="sampler"> +<h1>Sampler<a class="headerlink" href="#sampler" title="Permalink to this heading"></a></h1> +<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="Saltelli sampling"><img alt="Saltelli sampling" src="../../_images/sphx_glr_plot_saltelli_thumb.png" /> +<p><a class="reference internal" href="plot_saltelli.html#sphx-glr-auto-examples-sampler-plot-saltelli-py"><span class="std std-ref">Saltelli sampling</span></a></p> + <div class="sphx-glr-thumbnail-title">Saltelli sampling</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="Latin hypercube sampling"><img alt="Latin hypercube sampling" src="../../_images/sphx_glr_plot_latin_thumb.png" /> +<p><a class="reference internal" href="plot_latin.html#sphx-glr-auto-examples-sampler-plot-latin-py"><span class="std std-ref">Latin hypercube sampling</span></a></p> + <div class="sphx-glr-thumbnail-title">Latin hypercube sampling</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="Metropolis Hastings sampling"><img alt="Metropolis Hastings sampling" src="../../_images/sphx_glr_plot_metropolis_hastings_thumb.png" /> +<p><a class="reference internal" href="plot_metropolis_hastings.html#sphx-glr-auto-examples-sampler-plot-metropolis-hastings-py"><span class="std std-ref">Metropolis Hastings sampling</span></a></p> + <div class="sphx-glr-thumbnail-title">Metropolis Hastings sampling</div> +</div></div><div class="toctree-wrapper compound"> +</div> +<div class="sphx-glr-footer sphx-glr-footer-gallery docutils container"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/79d68b726b379b22e24e81ddc36bf480/sampler_python.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">sampler_python.zip</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/9be10f28a70b43dfd67c8234c21c2052/sampler_jupyter.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Jupyter</span> <span class="pre">notebooks:</span> <span class="pre">sampler_jupyter.zip</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="../inference/plot_active_learning.html" class="btn btn-neutral float-left" title="Active learning" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_saltelli.html" class="btn btn-neutral float-right" title="Saltelli sampling" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sampler/plot_latin.html b/docs/source/_build/html/auto_examples/sampler/plot_latin.html new file mode 100644 index 0000000000000000000000000000000000000000..119f626e9f5f64bd87847aedf6b3364c1fd230d9 --- /dev/null +++ b/docs/source/_build/html/auto_examples/sampler/plot_latin.html @@ -0,0 +1,217 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Latin hypercube sampling — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Metropolis Hastings sampling" href="plot_metropolis_hastings.html" /> + <link rel="prev" title="Saltelli sampling" href="plot_saltelli.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Sampler</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_saltelli.html">Saltelli sampling</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Latin hypercube sampling</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_metropolis_hastings.html">Metropolis Hastings sampling</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Sampler</a></li> + <li class="breadcrumb-item active">Latin hypercube sampling</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sampler/plot_latin.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-sampler-plot-latin-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="latin-hypercube-sampling"> +<span id="sphx-glr-auto-examples-sampler-plot-latin-py"></span><h1>Latin hypercube sampling<a class="headerlink" href="#latin-hypercube-sampling" title="Permalink to this heading"></a></h1> +<p>This example shows how to draw samples using Latin hypercube sampling.</p> +<p>For the illustration purpose, let’s have a look at a two-dimensional example +where we have two random variables X and Y. Each is uniformly distributed in its +range.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="n">ndim</span> <span class="o">=</span> <span class="mi">2</span> +<span class="c1"># range of X is 10 to 20, range of Y is -10 to 0</span> +<span class="n">bounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">10</span><span class="p">,</span><span class="mi">20</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="mi">0</span><span class="p">]])</span> +</pre></div> +</div> +<p>Given this setting, we can import <code class="xref py py-class docutils literal notranslate"><span class="pre">Latin</span></code>, create an instance, and +call the <code class="xref py py-meth docutils literal notranslate"><span class="pre">Latin.sample()</span></code> method to draw required number of samples</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.sampler</span> <span class="kn">import</span> <span class="n">LHS</span> + +<span class="c1"># setting seed leads to same samples every time when the codes are run</span> +<span class="n">lhs_sampler</span> <span class="o">=</span> <span class="n">LHS</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> +<span class="n">lhs_samples</span> <span class="o">=</span> <span class="n">lhs_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nsamples</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> +</pre></div> +</div> +<p>The samples are plotted in the following figure.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span> <span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">lhs_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">lhs_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'blue'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'X'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"Latin hypercube samples (criterion='random')"</span><span class="p">)</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="n">visible</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">)</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_latin_001.png" srcset="../../_images/sphx_glr_plot_latin_001.png" alt="Latin hypercube samples (criterion='random')" class = "sphx-glr-single-img"/><p>There are different criterions to pick samples in each hypercube. The default +is <cite>random</cite>, as used above. Other options are <cite>center</cite> and <cite>maximin</cite>. For instance, +we can use the <cite>center</cite> criterion to draw <span class="math notranslate nohighlight">\(5\)</span> samples as follows:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">lhs_sampler</span> <span class="o">=</span> <span class="n">LHS</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="s1">'center'</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> +<span class="n">lhs_samples</span> <span class="o">=</span> <span class="n">lhs_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nsamples</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> + +<span class="n">fig</span> <span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">lhs_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">lhs_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'blue'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'X'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"Latin hypercube samples (criterion='center')"</span><span class="p">)</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="n">visible</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">)</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_latin_002.png" srcset="../../_images/sphx_glr_plot_latin_002.png" alt="Latin hypercube samples (criterion='center')" class = "sphx-glr-single-img"/><p>And we can use the <cite>maximin</cite> criterion as follows:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">lhs_sampler</span> <span class="o">=</span> <span class="n">LHS</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="s1">'maximin'</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">iteration</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span> +<span class="n">lhs_samples</span> <span class="o">=</span> <span class="n">lhs_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nsamples</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> + +<span class="n">fig</span> <span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">lhs_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">lhs_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'blue'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'X'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"Latin hypercube samples (criterion='maximin')"</span><span class="p">)</span> +<span class="n">_</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="n">visible</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">)</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_latin_003.png" srcset="../../_images/sphx_glr_plot_latin_003.png" alt="Latin hypercube samples (criterion='maximin')" class = "sphx-glr-single-img"/><p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 0.270 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-sampler-plot-latin-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/213f7cd5e82a62f8d1da8c3af9caab35/plot_latin.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_latin.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/3072e3885ecdb1bbb3b34893dcfd8def/plot_latin.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_latin.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_saltelli.html" class="btn btn-neutral float-left" title="Saltelli sampling" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_metropolis_hastings.html" class="btn btn-neutral float-right" title="Metropolis Hastings sampling" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sampler/plot_metropolis_hastings.html b/docs/source/_build/html/auto_examples/sampler/plot_metropolis_hastings.html new file mode 100644 index 0000000000000000000000000000000000000000..516f10a855ea336be2fc79030c4d6617a9979557 --- /dev/null +++ b/docs/source/_build/html/auto_examples/sampler/plot_metropolis_hastings.html @@ -0,0 +1,239 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Metropolis Hastings sampling — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Sensitivity" href="../sensitivity/index.html" /> + <link rel="prev" title="Latin hypercube sampling" href="plot_latin.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Sampler</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_saltelli.html">Saltelli sampling</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_latin.html">Latin hypercube sampling</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Metropolis Hastings sampling</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Sampler</a></li> + <li class="breadcrumb-item active">Metropolis Hastings sampling</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sampler/plot_metropolis_hastings.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-sampler-plot-metropolis-hastings-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="metropolis-hastings-sampling"> +<span id="sphx-glr-auto-examples-sampler-plot-metropolis-hastings-py"></span><h1>Metropolis Hastings sampling<a class="headerlink" href="#metropolis-hastings-sampling" title="Permalink to this heading"></a></h1> +<p>This example shows how to draw samples using Metropolis Hastings sampling. +The target probability distribution is</p> +<p><span class="math notranslate nohighlight">\(p(\mathbf{x})=p(x_1, x_2) \propto \exp \left(-\frac{1}{100}\left(x_1-1\right)^2-\left(x_1^2-x_2\right)^2\right)\)</span></p> +<p>where <span class="math notranslate nohighlight">\(x_1 \in [-5,5]\)</span> and <span class="math notranslate nohighlight">\(x_2 \in [-5,5]\)</span>.</p> +<p>It should be noted that the right hand side of the equation is an unnormalized +probability density function since its integral is not equal to <span class="math notranslate nohighlight">\(1\)</span>. +This can happen, for example, when the normalization constant is unknown or difficult +to compute.</p> +<p>We can define the target probability distribution in Python as follows:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="k">def</span> <span class="nf">target_dist</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> + <span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">>=-</span><span class="mi">5</span> <span class="ow">and</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o"><=</span><span class="mi">5</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">>=-</span><span class="mi">5</span> <span class="ow">and</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o"><=</span><span class="mi">5</span><span class="p">):</span> + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">0.01</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="o">-</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">return</span> <span class="mi">0</span> +</pre></div> +</div> +<p>The figure below shows how the target distribution looks like.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> +<span class="kn">import</span> <span class="nn">itertools</span> + +<span class="n">x1_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mf">5.1</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span> +<span class="n">x2_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mf">5.1</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span> + +<span class="n">target_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">))</span> +<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">100</span><span class="p">),</span> <span class="nb">range</span><span class="p">(</span><span class="mi">100</span><span class="p">)):</span> + <span class="n">x1</span> <span class="o">=</span> <span class="n">x1_values</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> + <span class="n">x2</span> <span class="o">=</span> <span class="n">x2_values</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> + <span class="n">target_values</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">target_dist</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">]))</span> + +<span class="n">fig</span> <span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">contourf</span><span class="p">(</span><span class="n">x1_values</span><span class="p">,</span> <span class="n">x2_values</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">target_values</span><span class="p">),</span> <span class="n">levels</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'Blues'</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'(unnormalized) target distribution'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="sa">r</span><span class="s1">'$x_1$'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="sa">r</span><span class="s1">'$x_2$'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_metropolis_hastings_001.png" srcset="../../_images/sphx_glr_plot_metropolis_hastings_001.png" alt="(unnormalized) target distribution" class = "sphx-glr-single-img"/><p>To perform Metropolis Hastings sampling, we need to choose a proposal distribution +which can be used to determine a new state <code class="docutils literal notranslate"><span class="pre">x'</span></code> given a current state <code class="docutils literal notranslate"><span class="pre">x</span></code> at +each iteration. This is defined by the parameter <code class="docutils literal notranslate"><span class="pre">f_sample</span></code> which should be a +function. A usual choice is to choose the new state from a Gaussian distribution +centered at the current state.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">multivariate_normal</span> + +<span class="n">f_sample</span> <span class="o">=</span> <span class="n">multivariate_normal</span><span class="o">.</span><span class="n">rvs</span> +<span class="c1"># make the samples reproducible</span> +<span class="n">kwgs_f_sample</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'random_state'</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">default_rng</span><span class="p">(</span><span class="n">seed</span><span class="o">=</span><span class="mi">1</span><span class="p">)}</span> +</pre></div> +</div> +<p>Then, we create an instance of <a class="reference internal" href="../../sampler/metropolis_hastings.html#psimpy.sampler.metropolis_hastings.MetropolisHastings" title="psimpy.sampler.metropolis_hastings.MetropolisHastings"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetropolisHastings</span></code></a> class.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.sampler.metropolis_hastings</span> <span class="kn">import</span> <span class="n">MetropolisHastings</span> + +<span class="n">mh_sampler</span> <span class="o">=</span> <span class="n">MetropolisHastings</span><span class="p">(</span><span class="n">ndim</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">init_state</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">]),</span> + <span class="n">f_sample</span><span class="o">=</span><span class="n">f_sample</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="n">target_dist</span><span class="p">,</span> <span class="n">nburn</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">nthin</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> + <span class="n">seed</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">kwgs_f_sample</span><span class="o">=</span><span class="n">kwgs_f_sample</span><span class="p">)</span> +</pre></div> +</div> +<p>Next, we call the <a class="reference internal" href="../../sampler/metropolis_hastings.html#psimpy.sampler.metropolis_hastings.MetropolisHastings.sample" title="psimpy.sampler.metropolis_hastings.MetropolisHastings.sample"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MetropolisHastings.sample()</span></code></a> method to draw required +number of samples.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mh_samples</span><span class="p">,</span> <span class="n">mh_accept</span> <span class="o">=</span> <span class="n">mh_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nsamples</span><span class="o">=</span><span class="mi">5000</span><span class="p">)</span> + +<span class="nb">print</span><span class="p">(</span><span class="s2">"Acceptance ratio: "</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">mh_accept</span><span class="p">))</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Acceptance ratio: 0.3712 +</pre></div> +</div> +<p>The following figure shows how the samples look like.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> +<span class="kn">import</span> <span class="nn">itertools</span> + +<span class="c1"># sphinx_gallery_thumbnail_number = 2</span> +<span class="n">fig</span> <span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">contourf</span><span class="p">(</span><span class="n">x1_values</span><span class="p">,</span> <span class="n">x2_values</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">target_values</span><span class="p">),</span> <span class="n">levels</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'Blues'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">mh_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">mh_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'r'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">,</span><span class="n">alpha</span><span class="o">=</span><span class="mf">0.05</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Metropolis Hastings samples'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="sa">r</span><span class="s1">'$x_1$'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="sa">r</span><span class="s1">'$x_2$'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span> +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_metropolis_hastings_002.png" srcset="../../_images/sphx_glr_plot_metropolis_hastings_002.png" alt="Metropolis Hastings samples" class = "sphx-glr-single-img"/><p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 4.769 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-sampler-plot-metropolis-hastings-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/50d02379952730d4e961434a77e23a62/plot_metropolis_hastings.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_metropolis_hastings.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/72c9aa931cd2028d7edb96ceb292a4a2/plot_metropolis_hastings.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_metropolis_hastings.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_latin.html" class="btn btn-neutral float-left" title="Latin hypercube sampling" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="../sensitivity/index.html" class="btn btn-neutral float-right" title="Sensitivity" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sampler/plot_saltelli.html b/docs/source/_build/html/auto_examples/sampler/plot_saltelli.html new file mode 100644 index 0000000000000000000000000000000000000000..617eaaaa6492da3d869c11b5c0bca4bbf8e65eef --- /dev/null +++ b/docs/source/_build/html/auto_examples/sampler/plot_saltelli.html @@ -0,0 +1,217 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Saltelli sampling — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Latin hypercube sampling" href="plot_latin.html" /> + <link rel="prev" title="Sampler" href="index.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Sampler</a><ul class="current"> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Saltelli sampling</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_latin.html">Latin hypercube sampling</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_metropolis_hastings.html">Metropolis Hastings sampling</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Sampler</a></li> + <li class="breadcrumb-item active">Saltelli sampling</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sampler/plot_saltelli.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-sampler-plot-saltelli-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="saltelli-sampling"> +<span id="sphx-glr-auto-examples-sampler-plot-saltelli-py"></span><h1>Saltelli sampling<a class="headerlink" href="#saltelli-sampling" title="Permalink to this heading"></a></h1> +<p>This example shows how to draw samples using Saltelli sampling. +Assume that there is a three-dimensional problem where X, Y, and Z are the +three random variables.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="n">ndim</span> <span class="o">=</span> <span class="mi">3</span> +<span class="c1"># range of X is 10 to 20, range of Y is 100 to 200, range of Z is 1000 to 2000</span> +<span class="n">bounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">10</span><span class="p">,</span><span class="mi">20</span><span class="p">],</span> <span class="p">[</span><span class="mi">100</span><span class="p">,</span><span class="mi">200</span><span class="p">],</span> <span class="p">[</span><span class="mi">1000</span><span class="p">,</span><span class="mi">2000</span><span class="p">]])</span> +</pre></div> +</div> +<p>Given this setting, we can import <a class="reference internal" href="../../sampler/saltelli.html#psimpy.sampler.saltelli.Saltelli" title="psimpy.sampler.saltelli.Saltelli"><code class="xref py py-class docutils literal notranslate"><span class="pre">Saltelli</span></code></a>, create an instance, and +call the <a class="reference internal" href="../../sampler/saltelli.html#psimpy.sampler.saltelli.Saltelli.sample" title="psimpy.sampler.saltelli.Saltelli.sample"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Saltelli.sample()</span></code></a> method to draw required number of samples.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.sampler</span> <span class="kn">import</span> <span class="n">Saltelli</span> + +<span class="n">saltelli_sampler</span> <span class="o">=</span> <span class="n">Saltelli</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">calc_second_order</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +<span class="n">saltelli_samples</span> <span class="o">=</span> <span class="n">saltelli_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nbase</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span> +</pre></div> +</div> +<p>In above codes, we set <code class="docutils literal notranslate"><span class="pre">calc_second_order</span></code> to <cite>False</cite>. It means that picked +samples can be used in following Sobol’ analysis to compute first-order and +total-effect Sobol’ indices but not second-order Sobol’ indices. It leads to +<span class="math notranslate nohighlight">\(nbase*(ndim+2)\)</span> samples as shown below</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span> +<span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="n">projection</span><span class="o">=</span><span class="s1">'3d'</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">2</span><span class="p">],</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'X'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_zlabel</span><span class="p">(</span><span class="s1">'Z'</span><span class="p">)</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> + +<span class="nb">print</span><span class="p">(</span><span class="s1">'Number of samples: '</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">saltelli_samples</span><span class="p">)</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_saltelli_001.png" srcset="../../_images/sphx_glr_plot_saltelli_001.png" alt="plot saltelli" class = "sphx-glr-single-img"/><div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Number of samples: 640 +</pre></div> +</div> +<p>If we want to draw samples which can also be used to compute second-order +Sobol’ indices, we need to set <code class="docutils literal notranslate"><span class="pre">calc_second_order</span></code> to <cite>True</cite>. +It leads to <span class="math notranslate nohighlight">\(nbase*(2*ndim+2)\)</span> samples.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">saltelli_sampler</span> <span class="o">=</span> <span class="n">Saltelli</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">calc_second_order</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +<span class="n">saltelli_samples</span> <span class="o">=</span> <span class="n">saltelli_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nbase</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span> + +<span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span> +<span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="n">projection</span><span class="o">=</span><span class="s1">'3d'</span><span class="p">)</span> + +<span class="n">ax</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">2</span><span class="p">],</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'X'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Y'</span><span class="p">)</span> +<span class="n">ax</span><span class="o">.</span><span class="n">set_zlabel</span><span class="p">(</span><span class="s1">'Z'</span><span class="p">)</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> + +<span class="nb">print</span><span class="p">(</span><span class="s1">'Number of samples: '</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">saltelli_samples</span><span class="p">)</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_saltelli_002.png" srcset="../../_images/sphx_glr_plot_saltelli_002.png" alt="plot saltelli" class = "sphx-glr-single-img"/><div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Number of samples: 1024 +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>If one has a two-dimensional problem, there is no need to set +<code class="docutils literal notranslate"><span class="pre">calc_second_order</span></code> to <cite>True</cite>. The reason is that the second-order Sobol’ +index can be directly computed based on the first-order and total-effect +Sobol’ index in that case.</p> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 0.309 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-sampler-plot-saltelli-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/6dd07bf8f59ed369971c33b38f420079/plot_saltelli.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_saltelli.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/e0b3048771af654ea83c8bb3f5bf6c0c/plot_saltelli.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_saltelli.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="index.html" class="btn btn-neutral float-left" title="Sampler" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_latin.html" class="btn btn-neutral float-right" title="Latin hypercube sampling" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sampler/sg_execution_times.html b/docs/source/_build/html/auto_examples/sampler/sg_execution_times.html new file mode 100644 index 0000000000000000000000000000000000000000..1b6bcef19bf166e4d9334eeb56c43a3b18203005 --- /dev/null +++ b/docs/source/_build/html/auto_examples/sampler/sg_execution_times.html @@ -0,0 +1,135 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Computation times — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../examples.html">Example Gallery</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item active">Computation times</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sampler/sg_execution_times.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="computation-times"> +<span id="sphx-glr-auto-examples-sampler-sg-execution-times"></span><h1>Computation times<a class="headerlink" href="#computation-times" title="Permalink to this heading"></a></h1> +<p><strong>00:05.348</strong> total execution time for <strong>auto_examples_sampler</strong> files:</p> +<table class="docutils align-default"> +<colgroup> +<col style="width: 84%" /> +<col style="width: 9%" /> +<col style="width: 7%" /> +</colgroup> +<tbody> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_metropolis_hastings.html#sphx-glr-auto-examples-sampler-plot-metropolis-hastings-py"><span class="std std-ref">Metropolis Hastings sampling</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_metropolis_hastings.py</span></code>)</p></td> +<td><p>00:04.769</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-even"><td><p><a class="reference internal" href="plot_saltelli.html#sphx-glr-auto-examples-sampler-plot-saltelli-py"><span class="std std-ref">Saltelli sampling</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_saltelli.py</span></code>)</p></td> +<td><p>00:00.309</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_latin.html#sphx-glr-auto-examples-sampler-plot-latin-py"><span class="std std-ref">Latin hypercube sampling</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_latin.py</span></code>)</p></td> +<td><p>00:00.270</p></td> +<td><p>0.0 MB</p></td> +</tr> +</tbody> +</table> +</section> + + + </div> + </div> + <footer> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sensitivity/index.html b/docs/source/_build/html/auto_examples/sensitivity/index.html new file mode 100644 index 0000000000000000000000000000000000000000..3ef3a6d204443431d212275fa27d461fdb38c5df --- /dev/null +++ b/docs/source/_build/html/auto_examples/sensitivity/index.html @@ -0,0 +1,143 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Sensitivity — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Sobol’ analysis" href="plot_sobol_analyze.html" /> + <link rel="prev" title="Metropolis Hastings sampling" href="../sampler/plot_metropolis_hastings.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2 current"><a class="current reference internal" href="#">Sensitivity</a><ul> +<li class="toctree-l3"><a class="reference internal" href="plot_sobol_analyze.html">Sobol’ analysis</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item active">Sensitivity</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sensitivity/index.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="sensitivity"> +<h1>Sensitivity<a class="headerlink" href="#sensitivity" title="Permalink to this heading"></a></h1> +<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="Sobol' analysis"><img alt="Sobol' analysis" src="../../_images/sphx_glr_plot_sobol_analyze_thumb.png" /> +<p><a class="reference internal" href="plot_sobol_analyze.html#sphx-glr-auto-examples-sensitivity-plot-sobol-analyze-py"><span class="std std-ref">Sobol’ analysis</span></a></p> + <div class="sphx-glr-thumbnail-title">Sobol' analysis</div> +</div></div><div class="toctree-wrapper compound"> +</div> +<div class="sphx-glr-footer sphx-glr-footer-gallery docutils container"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/b20b8a8616a1c41193e9b38a6dd88919/sensitivity_python.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">sensitivity_python.zip</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/ffaeb9b8df9af697043ca5a2a8c636a3/sensitivity_jupyter.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Jupyter</span> <span class="pre">notebooks:</span> <span class="pre">sensitivity_jupyter.zip</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="../sampler/plot_metropolis_hastings.html" class="btn btn-neutral float-left" title="Metropolis Hastings sampling" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_sobol_analyze.html" class="btn btn-neutral float-right" title="Sobol’ analysis" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sensitivity/plot_sobol_analyze.html b/docs/source/_build/html/auto_examples/sensitivity/plot_sobol_analyze.html new file mode 100644 index 0000000000000000000000000000000000000000..b8970fd9e2d8890bd6a11bbe5975ec16513ce4d8 --- /dev/null +++ b/docs/source/_build/html/auto_examples/sensitivity/plot_sobol_analyze.html @@ -0,0 +1,363 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Sobol’ analysis — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Simulator" href="../simulator/index.html" /> + <link rel="prev" title="Sensitivity" href="index.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Sensitivity</a><ul class="current"> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Sobol’ analysis</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="../simulator/index.html">Simulator</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Sensitivity</a></li> + <li class="breadcrumb-item active">Sobol’ analysis</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sensitivity/plot_sobol_analyze.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-sensitivity-plot-sobol-analyze-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="sobol-analysis"> +<span id="sphx-glr-auto-examples-sensitivity-plot-sobol-analyze-py"></span><h1>Sobol’ analysis<a class="headerlink" href="#sobol-analysis" title="Permalink to this heading"></a></h1> +<p>This example shows how to compute Sobol’ sensitivity indices using +the <a class="reference internal" href="../../sensitivity/sobol.html#psimpy.sensitivity.sobol.SobolAnalyze" title="psimpy.sensitivity.sobol.SobolAnalyze"><code class="xref py py-class docutils literal notranslate"><span class="pre">SobolAnalyze</span></code></a> class.</p> +<p>Let us consider the Ishigami function <span id="id1">[<a class="reference internal" href="../../refs.html#id9" title="Loic Le Gratiet, Claire Cannamela, and Bertrand Iooss. A Bayesian approach for global sensitivity analysis of (multifidelity) computer codes. SIAM/ASA Journal on Uncertainty Quantification, 2(1):336–363, 2014. doi:10.1137/130926869.">Le Gratiet <em>et al.</em>, 2014</a>]</span></p> +<p><span class="math notranslate nohighlight">\(y=f\left(x_1, x_2, x_3\right)=\sin \left(x_1\right)+7 \sin \left(\mathrm{x}_2\right)^2+0.1 x_3^4 \sin \left(x_1\right)\)</span></p> +<p>where <span class="math notranslate nohighlight">\(x_i\)</span> is uniformly distributed on <span class="math notranslate nohighlight">\([-\pi, \pi]\)</span> for <span class="math notranslate nohighlight">\(i \in [1,2,3]\)</span>. We define the function as follows:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="p">,</span><span class="n">x3</span><span class="p">):</span> + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">7</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x2</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mf">0.1</span><span class="o">*</span><span class="n">x3</span><span class="o">**</span><span class="mi">4</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x1</span><span class="p">)</span> +</pre></div> +</div> +<p>The variation of each <span class="math notranslate nohighlight">\(x_i\)</span> leads to the variation of <span class="math notranslate nohighlight">\(y\)</span>. Sobol’ analysis is used to quantify the contribution +of each <span class="math notranslate nohighlight">\(x_i\)</span> and their interactions to the variation of <span class="math notranslate nohighlight">\(y\)</span>. Steps of a Sobol’ analysis are:</p> +<blockquote> +<div><ol class="arabic simple"> +<li><p>Draw samples of input.</p></li> +<li><p>Evaluate the model at each input sample to obtain model output.</p></li> +<li><p>Compute Sobol’ indices based on model outputs.</p></li> +</ol> +</div></blockquote> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.sampler</span> <span class="kn">import</span> <span class="n">Saltelli</span> +<span class="kn">from</span> <span class="nn">psimpy.sensitivity</span> <span class="kn">import</span> <span class="n">SobolAnalyze</span> + +<span class="n">ndim</span> <span class="o">=</span> <span class="mi">3</span> +<span class="n">bounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">]])</span> +<span class="n">calc_second_order</span> <span class="o">=</span> <span class="kc">False</span> +<span class="n">nbase</span> <span class="o">=</span> <span class="mi">1024</span> + +<span class="c1"># draw Saltelli samples</span> +<span class="n">saltelli_sampler</span> <span class="o">=</span> <span class="n">Saltelli</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">calc_second_order</span><span class="p">)</span> +<span class="n">saltelli_samples</span> <span class="o">=</span> <span class="n">saltelli_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nbase</span><span class="p">)</span> + +<span class="c1"># Evaluate the model to obtain model outputs</span> +<span class="n">Y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">saltelli_samples</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">saltelli_samples</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">])</span> + +<span class="c1"># Compute Sobol' indices</span> +<span class="n">sobol_analyzer</span> <span class="o">=</span> <span class="n">SobolAnalyze</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">calc_second_order</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span> +<span class="n">S_res</span> <span class="o">=</span> <span class="n">sobol_analyzer</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> + +<span class="nb">print</span><span class="p">(</span><span class="s2">"Estimated first-order Sobol' index: "</span><span class="p">,</span> <span class="n">S_res</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">][:,</span><span class="mi">0</span><span class="p">])</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Analytical solution: [0.314, 0.442, 0]"</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Estimated first-order Sobol' index: [0.31430871 0.44545644 0.01325799] +Analytical solution: [0.314, 0.442, 0] +</pre></div> +</div> +<p>Figure below shows the results. The bar plots represent estimated first-order +and total-effect Sobol’ indices, as well as their 95% confidence interval. The +red stars represent true values of the first-order Sobol’ indices.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">name_vars</span> <span class="o">=</span> <span class="p">[</span><span class="sa">r</span><span class="s1">'$x_1$'</span><span class="p">,</span><span class="sa">r</span><span class="s1">'$x_2$'</span><span class="p">,</span><span class="sa">r</span><span class="s1">'$x_3$'</span><span class="p">]</span> +<span class="n">x</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'S1'</span><span class="p">:[</span><span class="mi">1</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">7</span><span class="p">],</span> <span class="s1">'ST'</span><span class="p">:[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">8</span><span class="p">]}</span> +<span class="n">color</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'S1'</span><span class="p">:</span><span class="s1">'#69b3a2'</span><span class="p">,</span> <span class="s1">'ST'</span><span class="p">:</span><span class="s1">'#3399e6'</span><span class="p">}</span> +<span class="n">width</span><span class="o">=</span><span class="mf">0.8</span> +<span class="n">capsize</span><span class="o">=</span><span class="mi">3</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> + +<span class="c1"># estimated first-order Sobol' indices and their confidence interval</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">],</span> <span class="n">S_res</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">][:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">yerr</span><span class="o">=</span><span class="n">S_res</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">][:,</span><span class="mi">2</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">],</span> <span class="n">capsize</span><span class="o">=</span><span class="n">capsize</span><span class="p">)</span> + +<span class="n">ax1</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mf">0.7</span><span class="p">])</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([</span><span class="mf">1.5</span><span class="p">,</span><span class="mf">4.5</span><span class="p">,</span><span class="mf">7.5</span><span class="p">])</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">name_vars</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">,</span><span class="n">bottom</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s2">"y"</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">])</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">'--'</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'grey'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">.25</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'First-order index'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">])</span> + +<span class="c1"># analytical solution for first-order indices</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.314</span><span class="p">,</span> <span class="mf">0.442</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'red'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'*'</span><span class="p">)</span> + + +<span class="c1"># estimated total-effect Sobol' indices and their confidence interval</span> +<span class="n">ax2</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">twinx</span><span class="p">()</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">],</span> <span class="n">S_res</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">][:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">yerr</span><span class="o">=</span><span class="n">S_res</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">][:,</span><span class="mi">2</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">],</span> <span class="n">capsize</span><span class="o">=</span><span class="n">capsize</span><span class="p">)</span> + +<span class="n">ax2</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mf">0.7</span><span class="p">])</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([</span><span class="mf">1.5</span><span class="p">,</span><span class="mf">4.5</span><span class="p">,</span><span class="mf">7.5</span><span class="p">])</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">,</span><span class="n">bottom</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s2">"y"</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">])</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">'--'</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'grey'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">.25</span><span class="p">)</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Total-effect index'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">])</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_sobol_analyze_001.png" srcset="../../_images/sphx_glr_plot_sobol_analyze_001.png" alt="plot sobol analyze" class = "sphx-glr-single-img"/><div class="admonition note"> +<p class="admonition-title">Note</p> +<p>The interaction between one parameter and all other parameters can be +quantified by the difference between its first-order and total-effet Sobol’ +indices. If detailed information on interaction between any two parameters +is needed, one can set <code class="docutils literal notranslate"><span class="pre">calc_second_order</span></code> to <cite>True</cite>.</p> +</div> +<p><strong>Many models of interest in real-world applications are very computationally +expensive. In that case, we resort to emulation techniques in order to efficiently +conduct Sobol’ analysis.</strong> See <span id="id2">Zhao <em>et al.</em> [<a class="reference internal" href="../../refs.html#id14" title="H. Zhao, F. Amann, and J. Kowalski. Emulator-based global sensitivity analysis for flow-like landslide run-out models. Landslides, ():, 2021. doi:https://doi.org/10.1007/s10346-021-01690-w.">2021</a>]</span> for the detailed theory.</p> +<p>Steps of such an analysis are:</p> +<blockquote> +<div><ol class="arabic simple"> +<li><p>Draw input samples for emulator training.</p></li> +<li><p>Evaluate the model at each training input point to obtain training data.</p></li> +<li><p>Train an emulator for the computationally expensive model of interest.</p></li> +<li><p>Draw samples of input for Sobol’ analysis.</p></li> +<li><p>Evaluate the emulator at each input sample at step 3 to obtain approximated model outputs.</p></li> +<li><p>Compute Sobol’ indices based on approximated model outputs.</p></li> +</ol> +</div></blockquote> +<p>Assume that the above Ishigami function is computationally expensive, an emulator-based +Sobol’ analysis can be conducted as follows:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> +<span class="kn">from</span> <span class="nn">psimpy.sampler</span> <span class="kn">import</span> <span class="n">LHS</span> +<span class="kn">from</span> <span class="nn">psimpy.emulator</span> <span class="kn">import</span> <span class="n">ScalarGaSP</span> +<span class="kn">from</span> <span class="nn">psimpy.sampler</span> <span class="kn">import</span> <span class="n">Saltelli</span> +<span class="kn">from</span> <span class="nn">psimpy.sensitivity</span> <span class="kn">import</span> <span class="n">SobolAnalyze</span> + +<span class="c1"># define the model</span> +<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="p">,</span><span class="n">x3</span><span class="p">):</span> + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">7</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x2</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mf">0.1</span><span class="o">*</span><span class="n">x3</span><span class="o">**</span><span class="mi">4</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x1</span><span class="p">)</span> + +<span class="n">ndim</span> <span class="o">=</span> <span class="mi">3</span> +<span class="n">bounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">]])</span> +<span class="n">seed</span> <span class="o">=</span> <span class="mi">2</span> + +<span class="c1"># draw 100 input samples for emulator training using Latin hypercube sampling</span> +<span class="n">lhs_sampler</span> <span class="o">=</span> <span class="n">LHS</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">criterion</span><span class="o">=</span><span class="s1">'maximin'</span><span class="p">,</span> <span class="n">iteration</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span> +<span class="n">design</span> <span class="o">=</span> <span class="n">lhs_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nsamples</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> + +<span class="c1"># evaluate the model at each training input point</span> +<span class="n">response</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">design</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">design</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">design</span><span class="p">[:,</span><span class="mi">2</span><span class="p">])</span> + +<span class="c1"># train an emulator</span> +<span class="n">scalar_gasp</span> <span class="o">=</span> <span class="n">ScalarGaSP</span><span class="p">(</span><span class="n">ndim</span><span class="p">)</span> +<span class="n">scalar_gasp</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">design</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span> + +<span class="c1"># the trained emulator needs to be validated before moving on</span> +<span class="c1"># here we leave out this step for simplicity...</span> + +<span class="c1"># draw samples of input for Sobol' analysis</span> +<span class="n">calc_second_order</span> <span class="o">=</span> <span class="kc">False</span> +<span class="n">nbase</span> <span class="o">=</span> <span class="mi">1024</span> + +<span class="n">saltelli_sampler</span> <span class="o">=</span> <span class="n">Saltelli</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">calc_second_order</span><span class="p">)</span> +<span class="n">saltelli_samples</span> <span class="o">=</span> <span class="n">saltelli_sampler</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">nbase</span><span class="p">)</span> + +<span class="c1"># evaluate the emulator to obtain approximated model output.</span> +<span class="c1"># in order to take emulator-induced uncertainty into account, we draw 50 realizations</span> +<span class="c1"># from the emulator</span> +<span class="n">Y</span> <span class="o">=</span> <span class="n">scalar_gasp</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">saltelli_samples</span><span class="p">,</span> <span class="mi">50</span><span class="p">)</span> + +<span class="c1"># Compute Sobol' indices based on approximated model outputs</span> +<span class="n">sobol_analyzer</span> <span class="o">=</span> <span class="n">SobolAnalyze</span><span class="p">(</span><span class="n">ndim</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">calc_second_order</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="n">seed</span><span class="p">)</span> +<span class="n">S_res</span> <span class="o">=</span> <span class="n">sobol_analyzer</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">'parallel'</span><span class="p">,</span> <span class="n">max_workers</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> + +<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Emulator-based first-order Sobol' index: "</span><span class="p">,</span> <span class="n">S_res</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">][:,</span><span class="mi">0</span><span class="p">])</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Analytical solution: [0.314, 0.442, 0]"</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>The upper bounds of the range parameters are 173,6849 174,6991 174,3157 +The initial values of range parameters are 3,473697 3,493981 3,486314 +Start of the optimization 1 : +The number of iterations is 14 + The value of the marginal posterior function is -284,0714 + Optimized range parameters are 3,183999 2,786247 4,315419 + Optimized nugget parameter is 0 + Convergence: TRUE +The initial values of range parameters are 1,721972 1,732027 1,728226 +Start of the optimization 2 : +The number of iterations is 14 + The value of the marginal posterior function is -284,0714 + Optimized range parameters are 3,183999 2,786247 4,315419 + Optimized nugget parameter is 0 + Convergence: TRUE + + +Emulator-based first-order Sobol' index: [0.29064086 0.46853437 0.01096656] +Analytical solution: [0.314, 0.442, 0] +</pre></div> +</div> +<p>The following figure shows how the results of emulator-based Sobol’ analysis +look like.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">name_vars</span> <span class="o">=</span> <span class="p">[</span><span class="sa">r</span><span class="s1">'$x_1$'</span><span class="p">,</span><span class="sa">r</span><span class="s1">'$x_2$'</span><span class="p">,</span><span class="sa">r</span><span class="s1">'$x_3$'</span><span class="p">]</span> +<span class="n">x</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'S1'</span><span class="p">:[</span><span class="mi">1</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">7</span><span class="p">],</span> <span class="s1">'ST'</span><span class="p">:[</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">8</span><span class="p">]}</span> +<span class="n">color</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'S1'</span><span class="p">:</span><span class="s1">'#69b3a2'</span><span class="p">,</span> <span class="s1">'ST'</span><span class="p">:</span><span class="s1">'#3399e6'</span><span class="p">}</span> +<span class="n">width</span><span class="o">=</span><span class="mf">0.8</span> +<span class="n">capsize</span><span class="o">=</span><span class="mi">3</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span> + +<span class="n">ax1</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">],</span> <span class="n">S_res</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">][:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">yerr</span><span class="o">=</span><span class="n">S_res</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">][:,</span><span class="mi">2</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">],</span> <span class="n">capsize</span><span class="o">=</span><span class="n">capsize</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mf">0.7</span><span class="p">])</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([</span><span class="mf">1.5</span><span class="p">,</span><span class="mf">4.5</span><span class="p">,</span><span class="mf">7.5</span><span class="p">])</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">(</span><span class="n">name_vars</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">,</span><span class="n">bottom</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s2">"y"</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">])</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">'--'</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'grey'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">.25</span><span class="p">)</span> +<span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'First-order index'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">])</span> + +<span class="n">ax1</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">'S1'</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.314</span><span class="p">,</span> <span class="mf">0.442</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">s</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'red'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'*'</span><span class="p">)</span> + +<span class="n">ax2</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">twinx</span><span class="p">()</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">],</span> <span class="n">S_res</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">][:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">yerr</span><span class="o">=</span><span class="n">S_res</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">][:,</span><span class="mi">2</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">],</span> <span class="n">capsize</span><span class="o">=</span><span class="n">capsize</span><span class="p">)</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mf">0.7</span><span class="p">])</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([</span><span class="mf">1.5</span><span class="p">,</span><span class="mf">4.5</span><span class="p">,</span><span class="mf">7.5</span><span class="p">])</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">'both'</span><span class="p">,</span><span class="n">bottom</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s2">"y"</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">])</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">'--'</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'major'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'grey'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">.25</span><span class="p">)</span> +<span class="n">ax2</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'Total-effect index'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">[</span><span class="s1">'ST'</span><span class="p">])</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_sobol_analyze_002.png" srcset="../../_images/sphx_glr_plot_sobol_analyze_002.png" alt="plot sobol analyze" class = "sphx-glr-single-img"/><p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 16.499 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-sensitivity-plot-sobol-analyze-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/d3e17d759872695d3b37be8319e77dbf/plot_sobol_analyze.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_sobol_analyze.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/e6e32deb84b9140224f7120b34bdafda/plot_sobol_analyze.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_sobol_analyze.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="index.html" class="btn btn-neutral float-left" title="Sensitivity" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="../simulator/index.html" class="btn btn-neutral float-right" title="Simulator" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/sensitivity/sg_execution_times.html b/docs/source/_build/html/auto_examples/sensitivity/sg_execution_times.html new file mode 100644 index 0000000000000000000000000000000000000000..125fa533e73ca183647fd86bc11e87806544ccfd --- /dev/null +++ b/docs/source/_build/html/auto_examples/sensitivity/sg_execution_times.html @@ -0,0 +1,127 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Computation times — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../examples.html">Example Gallery</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item active">Computation times</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/sensitivity/sg_execution_times.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="computation-times"> +<span id="sphx-glr-auto-examples-sensitivity-sg-execution-times"></span><h1>Computation times<a class="headerlink" href="#computation-times" title="Permalink to this heading"></a></h1> +<p><strong>00:16.499</strong> total execution time for <strong>auto_examples_sensitivity</strong> files:</p> +<table class="docutils align-default"> +<colgroup> +<col style="width: 83%" /> +<col style="width: 10%" /> +<col style="width: 7%" /> +</colgroup> +<tbody> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_sobol_analyze.html#sphx-glr-auto-examples-sensitivity-plot-sobol-analyze-py"><span class="std std-ref">Sobol’ analysis</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_sobol_analyze.py</span></code>)</p></td> +<td><p>00:16.499</p></td> +<td><p>0.0 MB</p></td> +</tr> +</tbody> +</table> +</section> + + + </div> + </div> + <footer> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/simulator/index.html b/docs/source/_build/html/auto_examples/simulator/index.html new file mode 100644 index 0000000000000000000000000000000000000000..f58554f1103833233f32e5cbda9406e36783a157 --- /dev/null +++ b/docs/source/_build/html/auto_examples/simulator/index.html @@ -0,0 +1,155 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Simulator — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Mass Point Model" href="plot_mass_point_model.html" /> + <link rel="prev" title="Sobol’ analysis" href="../sensitivity/plot_sobol_analyze.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2 current"><a class="current reference internal" href="#">Simulator</a><ul> +<li class="toctree-l3"><a class="reference internal" href="plot_mass_point_model.html">Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_mass_point_model.html">RunSimulator: Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_ravaflow24.html">Ravaflow24 Mixture Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_ravaflow24.html">RunSimulator: Ravaflow24 Mixture Model</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item active">Simulator</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/simulator/index.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="simulator"> +<h1>Simulator<a class="headerlink" href="#simulator" title="Permalink to this heading"></a></h1> +<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="Mass Point Model"><img alt="Mass Point Model" src="../../_images/sphx_glr_plot_mass_point_model_thumb.png" /> +<p><a class="reference internal" href="plot_mass_point_model.html#sphx-glr-auto-examples-simulator-plot-mass-point-model-py"><span class="std std-ref">Mass Point Model</span></a></p> + <div class="sphx-glr-thumbnail-title">Mass Point Model</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="RunSimulator: Mass Point Model"><img alt="RunSimulator: Mass Point Model" src="../../_images/sphx_glr_plot_run_mass_point_model_thumb.png" /> +<p><a class="reference internal" href="plot_run_mass_point_model.html#sphx-glr-auto-examples-simulator-plot-run-mass-point-model-py"><span class="std std-ref">RunSimulator: Mass Point Model</span></a></p> + <div class="sphx-glr-thumbnail-title">RunSimulator: Mass Point Model</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="Ravaflow24 Mixture Model"><img alt="Ravaflow24 Mixture Model" src="../../_images/sphx_glr_plot_ravaflow24_thumb.png" /> +<p><a class="reference internal" href="plot_ravaflow24.html#sphx-glr-auto-examples-simulator-plot-ravaflow24-py"><span class="std std-ref">Ravaflow24 Mixture Model</span></a></p> + <div class="sphx-glr-thumbnail-title">Ravaflow24 Mixture Model</div> +</div><div class="sphx-glr-thumbcontainer" tooltip="RunSimulator: Ravaflow24 Mixture Model"><img alt="RunSimulator: Ravaflow24 Mixture Model" src="../../_images/sphx_glr_plot_run_ravaflow24_thumb.png" /> +<p><a class="reference internal" href="plot_run_ravaflow24.html#sphx-glr-auto-examples-simulator-plot-run-ravaflow24-py"><span class="std std-ref">RunSimulator: Ravaflow24 Mixture Model</span></a></p> + <div class="sphx-glr-thumbnail-title">RunSimulator: Ravaflow24 Mixture Model</div> +</div></div><div class="toctree-wrapper compound"> +</div> +<div class="sphx-glr-footer sphx-glr-footer-gallery docutils container"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/31c796c77470b56d8b117051a799e0b5/simulator_python.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">simulator_python.zip</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/6601ba25871fd56fd9acfef62ca40570/simulator_jupyter.zip"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">all</span> <span class="pre">examples</span> <span class="pre">in</span> <span class="pre">Jupyter</span> <span class="pre">notebooks:</span> <span class="pre">simulator_jupyter.zip</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="../sensitivity/plot_sobol_analyze.html" class="btn btn-neutral float-left" title="Sobol’ analysis" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_mass_point_model.html" class="btn btn-neutral float-right" title="Mass Point Model" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/simulator/plot_mass_point_model.html b/docs/source/_build/html/auto_examples/simulator/plot_mass_point_model.html new file mode 100644 index 0000000000000000000000000000000000000000..df8c3e60879f0a57fc8f08b414828594f6bcdffb --- /dev/null +++ b/docs/source/_build/html/auto_examples/simulator/plot_mass_point_model.html @@ -0,0 +1,261 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Mass Point Model — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="RunSimulator: Mass Point Model" href="plot_run_mass_point_model.html" /> + <link rel="prev" title="Simulator" href="index.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Simulator</a><ul class="current"> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_mass_point_model.html">RunSimulator: Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_ravaflow24.html">Ravaflow24 Mixture Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_ravaflow24.html">RunSimulator: Ravaflow24 Mixture Model</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Simulator</a></li> + <li class="breadcrumb-item active">Mass Point Model</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/simulator/plot_mass_point_model.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-simulator-plot-mass-point-model-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="mass-point-model"> +<span id="sphx-glr-auto-examples-simulator-plot-mass-point-model-py"></span><h1>Mass Point Model<a class="headerlink" href="#mass-point-model" title="Permalink to this heading"></a></h1> +<p>This example shows how to simulate the movement of a masspoint on a topography +using <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel" title="psimpy.simulator.mass_point_model.MassPointModel"><code class="xref py py-class docutils literal notranslate"><span class="pre">MassPointModel</span></code></a>.</p> +<p>First, import the class <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel" title="psimpy.simulator.mass_point_model.MassPointModel"><code class="xref py py-class docutils literal notranslate"><span class="pre">MassPointModel</span></code></a> and create an instance by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">MassPointModel</span> + +<span class="n">mpm</span> <span class="o">=</span> <span class="n">MassPointModel</span><span class="p">()</span> +</pre></div> +</div> +<dl class="simple"> +<dt>Required inputs for a simulation using <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel" title="psimpy.simulator.mass_point_model.MassPointModel"><code class="xref py py-class docutils literal notranslate"><span class="pre">MassPointModel</span></code></a> include:</dt><dd><ol class="arabic simple"> +<li><p>topographic data: digital elevation model (in <cite>ESRI ascii</cite> format)</p></li> +<li><p>friction coefficients: coulomb friction and turbulent friction coefficients</p></li> +<li><p>initial state: initial location and initial velocity of the masspoint</p></li> +<li><p>computational parameters: such as time step, end time, etc.</p></li> +</ol> +</dd> +</dl> +<p>The synthetic topography <code class="docutils literal notranslate"><span class="pre">synthetic_topo.asc</span></code> is used here for illustration. +It is located at the <cite>tests/data/</cite> folder.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> +<span class="kn">import</span> <span class="nn">linecache</span> +<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="n">dir_data</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s1">'../../../tests/data/'</span><span class="p">)</span> +<span class="n">elevation</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'synthetic_topo.asc'</span><span class="p">)</span> +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>You may need to modify <code class="docutils literal notranslate"><span class="pre">dir_data</span></code> according to where you save +<code class="docutils literal notranslate"><span class="pre">synthetic_topo.asc</span></code> on your local machine.</p> +</div> +<p>We can load the elevation data and visulize it. The figure below shows how +the topography looks like, as well as the initial location of the masspoint +(noted by the red dot).</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">header</span> <span class="o">=</span> <span class="p">[</span><span class="n">linecache</span><span class="o">.</span><span class="n">getline</span><span class="p">(</span><span class="n">elevation</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">)]</span> +<span class="n">header_values</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">header</span><span class="p">]</span> +<span class="n">ncols</span><span class="p">,</span> <span class="n">nrows</span><span class="p">,</span> <span class="n">xll</span><span class="p">,</span> <span class="n">yll</span><span class="p">,</span> <span class="n">cellsize</span> <span class="o">=</span> <span class="n">header_values</span> +<span class="n">ncols</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">ncols</span><span class="p">)</span> +<span class="n">nrows</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">nrows</span><span class="p">)</span> + +<span class="n">x_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">xll</span><span class="p">,</span> <span class="n">xll</span><span class="o">+</span><span class="p">(</span><span class="n">cellsize</span><span class="o">*</span><span class="n">ncols</span><span class="p">),</span> <span class="n">cellsize</span><span class="p">)</span> +<span class="n">y_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">yll</span><span class="p">,</span> <span class="n">yll</span><span class="o">+</span><span class="p">(</span><span class="n">cellsize</span><span class="o">*</span><span class="n">nrows</span><span class="p">),</span> <span class="n">cellsize</span><span class="p">)</span> + +<span class="n">z_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">loadtxt</span><span class="p">(</span><span class="n">elevation</span><span class="p">,</span> <span class="n">skiprows</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span> +<span class="n">z_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">rot90</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">z_values</span><span class="p">))</span> + +<span class="c1"># initial location</span> +<span class="n">x0</span> <span class="o">=</span> <span class="mi">200</span> +<span class="n">y0</span> <span class="o">=</span> <span class="mi">2000</span> +<span class="n">z0</span> <span class="o">=</span> <span class="n">z_values</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">x0</span><span class="o">/</span><span class="n">cellsize</span><span class="p">)]</span> + +<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">6</span><span class="p">),</span> <span class="n">height_ratios</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span> + +<span class="n">fig0</span> <span class="o">=</span> <span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">contourf</span><span class="p">(</span><span class="n">x_values</span><span class="p">,</span> <span class="n">y_values</span><span class="p">,</span> <span class="n">z_values</span><span class="p">,</span> <span class="n">levels</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'y'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'synthetic topography'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'r'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> +<span class="n">cbar</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">fig0</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">orientation</span><span class="o">=</span><span class="s1">'horizontal'</span><span class="p">,</span> + <span class="n">fraction</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mf">0.2</span><span class="p">)</span> +<span class="n">cbar</span><span class="o">.</span><span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'z'</span><span class="p">)</span> + + +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x_values</span><span class="p">,</span> <span class="n">z_values</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:])</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x0</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="s1">'r'</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="s1">'o'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'z'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5000</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'cross section at any y'</span><span class="p">)</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_mass_point_model_001.png" srcset="../../_images/sphx_glr_plot_mass_point_model_001.png" alt="synthetic topography, cross section at any y" class = "sphx-glr-single-img"/><p>We set the friction coefficients as</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mu</span> <span class="o">=</span> <span class="mf">0.15</span> +<span class="n">xi</span> <span class="o">=</span> <span class="mi">1000</span> +</pre></div> +</div> +<p>Given above topography, initial location, and friction coefficients, we can +call the <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel.run" title="psimpy.simulator.mass_point_model.MassPointModel.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MassPointModel.run()</span></code></a> method to perform a simulation. Other +parameters are set to their default values. (we suppress raised warnings ) +(other parameters are set to their default values).</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">warnings</span> + +<span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">"ignore"</span><span class="p">)</span> +<span class="n">output</span> <span class="o">=</span> <span class="n">mpm</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">elevation</span><span class="o">=</span><span class="n">elevation</span><span class="p">,</span> <span class="n">coulomb_friction</span><span class="o">=</span><span class="n">mu</span><span class="p">,</span> <span class="n">turbulent_friction</span><span class="o">=</span><span class="n">xi</span><span class="p">,</span> <span class="n">x0</span><span class="o">=</span><span class="n">x0</span><span class="p">,</span> <span class="n">y0</span><span class="o">=</span><span class="n">y0</span><span class="p">)</span> +</pre></div> +</div> +<p>The simulation returns time history of the mass point’s location and velocity. +Following plots show the simulation results.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span> + +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time (s)'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"x-t plot"</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">output</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">output</span><span class="p">[:,</span><span class="mi">1</span><span class="p">])</span> + +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time (s)'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'velocity'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"v-t plot"</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">output</span><span class="p">[:,</span><span class="mi">0</span><span class="p">],</span> <span class="n">output</span><span class="p">[:,</span><span class="mi">5</span><span class="p">])</span> + +<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'velocity'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"x-v plot"</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">output</span><span class="p">[:,</span><span class="mi">1</span><span class="p">],</span> <span class="n">output</span><span class="p">[:,</span><span class="mi">5</span><span class="p">])</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_mass_point_model_002.png" srcset="../../_images/sphx_glr_plot_mass_point_model_002.png" alt="x-t plot, v-t plot, x-v plot" class = "sphx-glr-single-img"/><p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 1.550 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-simulator-plot-mass-point-model-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/98a9fafc5e8001527da7060b5766f5b2/plot_mass_point_model.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_mass_point_model.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/201f9a51be1f2378acae03891235a84e/plot_mass_point_model.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_mass_point_model.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="index.html" class="btn btn-neutral float-left" title="Simulator" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_run_mass_point_model.html" class="btn btn-neutral float-right" title="RunSimulator: Mass Point Model" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/simulator/plot_ravaflow24.html b/docs/source/_build/html/auto_examples/simulator/plot_ravaflow24.html new file mode 100644 index 0000000000000000000000000000000000000000..a13248c691b2cc4d3bd30a2d384540d0080cdea5 --- /dev/null +++ b/docs/source/_build/html/auto_examples/simulator/plot_ravaflow24.html @@ -0,0 +1,280 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Ravaflow24 Mixture Model — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="RunSimulator: Ravaflow24 Mixture Model" href="plot_run_ravaflow24.html" /> + <link rel="prev" title="RunSimulator: Mass Point Model" href="plot_run_mass_point_model.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Simulator</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_mass_point_model.html">Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_mass_point_model.html">RunSimulator: Mass Point Model</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">Ravaflow24 Mixture Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_ravaflow24.html">RunSimulator: Ravaflow24 Mixture Model</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Simulator</a></li> + <li class="breadcrumb-item active">Ravaflow24 Mixture Model</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/simulator/plot_ravaflow24.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-simulator-plot-ravaflow24-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="ravaflow24-mixture-model"> +<span id="sphx-glr-auto-examples-simulator-plot-ravaflow24-py"></span><h1>Ravaflow24 Mixture Model<a class="headerlink" href="#ravaflow24-mixture-model" title="Permalink to this heading"></a></h1> +<p>This example shows how to simulate mass flow on a topography using +<a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a>.</p> +<p>First, import the class <a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a> by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">Ravaflow24Mixture</span> +</pre></div> +</div> +<p>To create an instance of this class, we must specify the parameter <code class="docutils literal notranslate"><span class="pre">dir_sim</span></code>. +It represents the directory in which output files generated by r.avaflow will be +saved.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> + +<span class="c1"># Here we create a folder called `temp_Ravaflow24Mixture_example` to save output</span> +<span class="c1"># files generated by r.avaflow</span> +<span class="n">cwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span> +<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="s1">'temp_Ravaflow24Mixture_example'</span><span class="p">):</span> + <span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="s1">'temp_Ravaflow24Mixture_example'</span><span class="p">)</span> +<span class="n">dir_sim</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s1">'temp_Ravaflow24Mixture_example'</span><span class="p">)</span> +</pre></div> +</div> +<p>Now, we can create an instance of <a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a> by given +<code class="docutils literal notranslate"><span class="pre">dir_sim</span></code> and leaving other parameters to their default values +(Other parameters include <code class="docutils literal notranslate"><span class="pre">time_step</span></code>, <code class="docutils literal notranslate"><span class="pre">time_end</span></code>, <code class="docutils literal notranslate"><span class="pre">curvature_control</span></code>, +<code class="docutils literal notranslate"><span class="pre">entrainment_control</span></code>, <code class="docutils literal notranslate"><span class="pre">stopping_control</span></code>, etc.)</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">voellmy_model</span> <span class="o">=</span> <span class="n">Ravaflow24Mixture</span><span class="p">(</span><span class="n">dir_sim</span><span class="p">)</span> +</pre></div> +</div> +<dl class="simple"> +<dt>To run a simulation using above <cite>voellmy_model</cite>, one needs to specify</dt><dd><ol class="arabic simple"> +<li><p><code class="docutils literal notranslate"><span class="pre">elevation</span></code> – Name of elevation raster file (including its path).</p></li> +<li><p><code class="docutils literal notranslate"><span class="pre">hrelease</span></code> – Name of release height raster file (including its path).</p></li> +<li><p><code class="docutils literal notranslate"><span class="pre">prefix</span></code> – Prefix required by r.avaflow to name output files.</p></li> +<li><p>If <code class="docutils literal notranslate"><span class="pre">elevation</span></code> is not a georeferenced file which can be used to create +a <cite>GRASS Location</cite>, <code class="docutils literal notranslate"><span class="pre">EPSG</span></code> must be provided.</p></li> +</ol> +</dd> +</dl> +<p>Other optional parameters include <code class="docutils literal notranslate"><span class="pre">internal_friction</span></code>, <code class="docutils literal notranslate"><span class="pre">basal_friction</span></code>, +<code class="docutils literal notranslate"><span class="pre">turbulent_friction</span></code>, <code class="docutils literal notranslate"><span class="pre">entrainment_coef</span></code> etc.</p> +<p>The synthetic topography <code class="docutils literal notranslate"><span class="pre">synthetic_topo.tif</span></code> and release mass <code class="docutils literal notranslate"><span class="pre">synthetic_rel.tif</span></code> +are used here for illustration. They are located at the <cite>/tests/data/</cite> folder.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">dir_data</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s1">'../../../tests/data/'</span><span class="p">)</span> +<span class="n">elevation</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'synthetic_topo.tif'</span><span class="p">)</span> +<span class="n">hrelease</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'synthetic_rel.tif'</span><span class="p">)</span> +<span class="n">prefix</span> <span class="o">=</span> <span class="s1">'synthetic'</span> +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>You may need to modify <code class="docutils literal notranslate"><span class="pre">dir_data</span></code> according to where you save them +on your local machine.</p> +</div> +<p>Given above inputs, we can create a <cite>GRASS Location</cite> and a shell file by calling +<a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture.preprocess" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture.preprocess"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Ravaflow24Mixture.preprocess()</span></code></a> method, and run the simulation using +<a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture.run" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Ravaflow24Mixture.run()</span></code></a> method</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">grass_location</span><span class="p">,</span> <span class="n">sh_file</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> + <span class="n">prefix</span><span class="o">=</span><span class="n">prefix</span><span class="p">,</span> <span class="n">elevation</span><span class="o">=</span><span class="n">elevation</span><span class="p">,</span> <span class="n">hrelease</span><span class="o">=</span><span class="n">hrelease</span><span class="p">,</span> <span class="n">EPSG</span><span class="o">=</span><span class="s1">'2326'</span><span class="p">)</span> +<span class="n">voellmy_model</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">grass_location</span><span class="p">,</span> <span class="n">sh_file</span><span class="p">)</span> +</pre></div> +</div> +<p>Once the simulation is finished, the results are located in the folder +<cite>/dir_sim/your_prefix_results</cite>. In this case, they are located in +<cite>/temp_Ravaflow24Mixture_example/synthetic_results</cite>. We can extract desired +outputs using respective method and visualize them. +For example, we can extract the overall impact area, maximum flow velocity, or +maximum flow velocity at specific locations:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="c1"># overall impact area</span> +<span class="n">impact_area</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">extract_impact_area</span><span class="p">(</span><span class="n">prefix</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Impact_area is </span><span class="si">{</span><span class="n">impact_area</span><span class="si">}</span><span class="s2"> m^2"</span><span class="p">)</span> + +<span class="c1"># overall maximum flow velocity</span> +<span class="n">v_mmax</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">extract_qoi_max</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="s1">'v'</span><span class="p">,</span> <span class="n">aggregate</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Maximum flow velocity is </span><span class="si">{</span><span class="n">v_mmax</span><span class="si">}</span><span class="s2"> m/s^2"</span><span class="p">)</span> + +<span class="c1"># maximum flow velocity at specific locations</span> +<span class="n">loc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">500</span><span class="p">,</span> <span class="mi">2000</span><span class="p">],</span> <span class="p">[</span><span class="mi">1500</span><span class="p">,</span> <span class="mi">2000</span><span class="p">]])</span> +<span class="n">v_max_loc</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">extract_qoi_max_loc</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">loc</span><span class="p">,</span> <span class="s1">'v'</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Maximum flow velocity at location </span><span class="si">{</span><span class="n">loc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s2"> is </span><span class="si">{</span><span class="n">v_max_loc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s2"> m/s^2"</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Maximum flow velocity at location </span><span class="si">{</span><span class="n">loc</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="si">}</span><span class="s2"> is </span><span class="si">{</span><span class="n">v_max_loc</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="si">}</span><span class="s2"> m/s^2"</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Impact_area is 1394800.0 m^2 +Maximum flow velocity is 41.39 m/s^2 +Maximum flow velocity at location [ 500 2000] is 34.264 m/s^2 +Maximum flow velocity at location [1500 2000] is 36.689 m/s^2 +</pre></div> +</div> +<p>We can visulize point-wise maximum flow height and velocity using heatmaps:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> +<span class="kn">import</span> <span class="nn">linecache</span> + +<span class="c1"># extract head information of result ascii files and compute x and y coordinates</span> +<span class="n">hmax_asc</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_sim</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">prefix</span><span class="si">}</span><span class="s1">_results'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">prefix</span><span class="si">}</span><span class="s1">_ascii'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">prefix</span><span class="si">}</span><span class="s1">_hflow_max.asc'</span><span class="p">)</span> + +<span class="n">header</span> <span class="o">=</span> <span class="p">[</span><span class="n">linecache</span><span class="o">.</span><span class="n">getline</span><span class="p">(</span><span class="n">hmax_asc</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">)]</span> +<span class="n">header_values</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">header</span><span class="p">]</span> +<span class="n">ncols</span><span class="p">,</span> <span class="n">nrows</span><span class="p">,</span> <span class="n">xll</span><span class="p">,</span> <span class="n">yll</span><span class="p">,</span> <span class="n">cellsize</span> <span class="o">=</span> <span class="n">header_values</span> +<span class="n">ncols</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">ncols</span><span class="p">)</span> +<span class="n">nrows</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">nrows</span><span class="p">)</span> + +<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">xll</span><span class="p">,</span> <span class="n">xll</span><span class="o">+</span><span class="p">(</span><span class="n">cellsize</span><span class="o">*</span><span class="n">ncols</span><span class="p">),</span> <span class="n">cellsize</span><span class="p">)</span> +<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">yll</span><span class="p">,</span> <span class="n">yll</span><span class="o">+</span><span class="p">(</span><span class="n">cellsize</span><span class="o">*</span><span class="n">nrows</span><span class="p">),</span> <span class="n">cellsize</span><span class="p">)</span> + +<span class="c1"># point-wise maximum flow height</span> +<span class="n">h_max</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">extract_qoi_max</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="s1">'h'</span><span class="p">,</span> <span class="n">aggregate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +<span class="c1"># point-wise maximum flow velocity</span> +<span class="n">v_max</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">extract_qoi_max</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="s1">'v'</span><span class="p">,</span> <span class="n">aggregate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> + +<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span> + +<span class="n">fig0</span> <span class="o">=</span> <span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">contourf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">h_max</span><span class="p">,</span> <span class="n">levels</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'y'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'maximum flow height'</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">' $(m/s)$'</span><span class="p">)</span> +<span class="n">cbar0</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">fig0</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'</span><span class="si">%.1f</span><span class="s1">'</span><span class="p">,</span> <span class="n">orientation</span><span class="o">=</span><span class="s1">'vertical'</span><span class="p">,</span> <span class="n">fraction</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span> + +<span class="n">fig1</span> <span class="o">=</span> <span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">contourf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">v_max</span><span class="p">,</span> <span class="n">levels</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'x'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'y'</span><span class="p">)</span> +<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'maximum flow velocity'</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">' ($m/s^2$)'</span><span class="p">)</span> +<span class="n">cbar1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">fig1</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'</span><span class="si">%.1f</span><span class="s1">'</span><span class="p">,</span> <span class="n">orientation</span><span class="o">=</span><span class="s1">'vertical'</span><span class="p">,</span> <span class="n">fraction</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span> + +<span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> +</pre></div> +</div> +<img src="../../_images/sphx_glr_plot_ravaflow24_001.png" srcset="../../_images/sphx_glr_plot_ravaflow24_001.png" alt="maximum flow height $(m/s)$, maximum flow velocity ($m/s^2$)" class = "sphx-glr-single-img"/><p>Here we delete the folder <cite>temp_Ravaflow24Mixture_example</cite> and all files therein.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">shutil</span> + +<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">dir_sim</span><span class="p">)</span> +</pre></div> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 5 minutes 56.157 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-simulator-plot-ravaflow24-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/70f25099189c12416e6ef5e4aa3ed8b4/plot_ravaflow24.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_ravaflow24.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/9847b46a66214926039e571c42505921/plot_ravaflow24.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_ravaflow24.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_run_mass_point_model.html" class="btn btn-neutral float-left" title="RunSimulator: Mass Point Model" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_run_ravaflow24.html" class="btn btn-neutral float-right" title="RunSimulator: Ravaflow24 Mixture Model" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/simulator/plot_run_mass_point_model.html b/docs/source/_build/html/auto_examples/simulator/plot_run_mass_point_model.html new file mode 100644 index 0000000000000000000000000000000000000000..b628dce800c1c185a933cf800521ee5c87eaa791 --- /dev/null +++ b/docs/source/_build/html/auto_examples/simulator/plot_run_mass_point_model.html @@ -0,0 +1,304 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>RunSimulator: Mass Point Model — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Ravaflow24 Mixture Model" href="plot_ravaflow24.html" /> + <link rel="prev" title="Mass Point Model" href="plot_mass_point_model.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Simulator</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_mass_point_model.html">Mass Point Model</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">RunSimulator: Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_ravaflow24.html">Ravaflow24 Mixture Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_ravaflow24.html">RunSimulator: Ravaflow24 Mixture Model</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Simulator</a></li> + <li class="breadcrumb-item active">RunSimulator: Mass Point Model</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/simulator/plot_run_mass_point_model.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-simulator-plot-run-mass-point-model-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="runsimulator-mass-point-model"> +<span id="sphx-glr-auto-examples-simulator-plot-run-mass-point-model-py"></span><h1>RunSimulator: Mass Point Model<a class="headerlink" href="#runsimulator-mass-point-model" title="Permalink to this heading"></a></h1> +<p>This example shows how to run multiple MassPointModel simulations in serial +and parallelly using <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a>.</p> +<p>First, we import the class <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel" title="psimpy.simulator.mass_point_model.MassPointModel"><code class="xref py py-class docutils literal notranslate"><span class="pre">MassPointModel</span></code></a> and define a <cite>simulator</cite> +based on <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel.run" title="psimpy.simulator.mass_point_model.MassPointModel.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MassPointModel.run()</span></code></a> method.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">MassPointModel</span> + +<span class="n">mpm</span> <span class="o">=</span> <span class="n">MassPointModel</span><span class="p">()</span> +<span class="n">mpm_simulator</span> <span class="o">=</span> <span class="n">mpm</span><span class="o">.</span><span class="n">run</span> +</pre></div> +</div> +<p>This simulator takes required input data, solves the mass point model, and +returns time history of the mass point’s location and velocity +(see <a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel.run" title="psimpy.simulator.mass_point_model.MassPointModel.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MassPointModel.run()</span></code></a>).</p> +<dl class="simple"> +<dt>Required inputs for <cite>mpm_simulator</cite> include:</dt><dd><ol class="arabic simple"> +<li><p>topographic data: digital elevation model (in <cite>ESRI ascii</cite> format)</p></li> +<li><p>friction coefficients: coulomb friction and turbulent friction coefficients</p></li> +<li><p>initial state: initial location and initial velocity of the masspoint</p></li> +<li><p>computational parameters: such as time step, end time, etc.</p></li> +</ol> +</dd> +</dl> +<p>The synthetic topography <code class="docutils literal notranslate"><span class="pre">synthetic_topo.asc</span></code> is used here for illustration. +It is located at the <cite>/tests/data/</cite> folder.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> + +<span class="n">dir_data</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s1">'../../../tests/data/'</span><span class="p">)</span> +<span class="n">elevation</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'synthetic_topo.asc'</span><span class="p">)</span> +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>You may need to modify <code class="docutils literal notranslate"><span class="pre">dir_data</span></code> according to where you save +<code class="docutils literal notranslate"><span class="pre">synthetic_topo.asc</span></code> on your local machine.</p> +</div> +<p>For this example, we are going to run multiple simulations at different values +of coulomb friction coefficient (<code class="docutils literal notranslate"><span class="pre">coulomb_friction</span></code>) and turbulent friction +coefficient (<code class="docutils literal notranslate"><span class="pre">turbulent_friction</span></code>) while keep other inputs fixed. Namely, +<code class="docutils literal notranslate"><span class="pre">coulomb_friction</span></code> and <code class="docutils literal notranslate"><span class="pre">turbulent_friction</span></code> are variable input parameters. +All other inputs are fixed input parameters.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> +<span class="kn">import</span> <span class="nn">itertools</span> + +<span class="c1"># Variable iput parameters are defined as a list of strings. Their values will be</span> +<span class="c1"># passed as a numpy array (var_samples) when run simulations.</span> +<span class="n">var_inp_parameter</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'coulomb_friction'</span><span class="p">,</span> <span class="s1">'turbulent_friction'</span><span class="p">]</span> +<span class="n">coulomb_friction</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.31</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span> +<span class="n">turbulent_friction</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">500</span><span class="p">,</span> <span class="mi">2001</span><span class="p">,</span> <span class="mi">400</span><span class="p">)</span> +<span class="n">var_samples</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span> + <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="n">coulomb_friction</span><span class="p">,</span> <span class="n">turbulent_friction</span><span class="p">)])</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Number of variable input samples are: "</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">var_samples</span><span class="p">))</span> + +<span class="c1"># Fixed input parameters are defined as a dictionary. Their values are given.</span> +<span class="n">fix_inp</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'elevation'</span><span class="p">:</span> <span class="n">elevation</span><span class="p">,</span> <span class="s1">'x0'</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span> <span class="s1">'y0'</span><span class="p">:</span> <span class="mi">2000</span><span class="p">,</span> <span class="s1">'tend'</span><span class="p">:</span> <span class="mi">50</span><span class="p">}</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Number of variable input samples are: 12 +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>Parameters of <cite>mpm_simulator</cite> which are not included in +<code class="docutils literal notranslate"><span class="pre">var_inp_parameter</span></code> and <code class="docutils literal notranslate"><span class="pre">fix_inp</span></code>, such as <code class="docutils literal notranslate"><span class="pre">ux0</span></code>, <code class="docutils literal notranslate"><span class="pre">uy0</span></code> and +<code class="docutils literal notranslate"><span class="pre">curvature</span></code>, will automatically take their default values.</p> +</div> +<p>We may want to save outputs returned by <cite>mpm_simulator</cite> at each simulation for +later inspection or processing. In that case, we need to define <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> and +set <code class="docutils literal notranslate"><span class="pre">save_out</span></code> as <cite>True</cite>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> + +<span class="c1"># Here we create a folder called `temp_run_MassPointModel_example` to save outputs</span> +<span class="c1"># returned at each simulation.</span> +<span class="n">cwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span> +<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="s1">'temp_run_MassPointModel_example'</span><span class="p">):</span> + <span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="s1">'temp_run_MassPointModel_example'</span><span class="p">)</span> +<span class="n">dir_out</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s1">'temp_run_MassPointModel_example'</span><span class="p">)</span> +</pre></div> +</div> +<p>Now we can define an object of <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a> by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">RunSimulator</span> + +<span class="n">run_mpm_simulator</span> <span class="o">=</span> <span class="n">RunSimulator</span><span class="p">(</span><span class="n">mpm_simulator</span><span class="p">,</span> <span class="n">var_inp_parameter</span><span class="p">,</span> <span class="n">fix_inp</span><span class="p">,</span> + <span class="n">dir_out</span><span class="o">=</span><span class="n">dir_out</span><span class="p">,</span> <span class="n">save_out</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>Since outputs of each simulation are saved in the same folder <code class="docutils literal notranslate"><span class="pre">dir_out</span></code>, +we need to give each file a unique name in order to avoid conflict. This is +realized by defining <code class="docutils literal notranslate"><span class="pre">prefixes</span></code>.</p> +</div> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">serial_prefixes</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"serial"</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">var_samples</span><span class="p">))]</span> +<span class="n">parallel_prefixes</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"parallel"</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">var_samples</span><span class="p">))]</span> +</pre></div> +</div> +<p>Using <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.serial_run" title="psimpy.simulator.run_simulator.RunSimulator.serial_run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RunSimulator.serial_run()</span></code></a> method or +<a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.parallel_run" title="psimpy.simulator.run_simulator.RunSimulator.parallel_run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RunSimulator.parallel_run()</span></code></a> method, we can run the simulations +in serial or parallelly.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span> + +<span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +<span class="n">run_mpm_simulator</span><span class="o">.</span><span class="n">serial_run</span><span class="p">(</span><span class="n">var_samples</span><span class="o">=</span><span class="n">var_samples</span><span class="p">,</span> <span class="n">prefixes</span><span class="o">=</span><span class="n">serial_prefixes</span><span class="p">)</span> +<span class="n">serial_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> +<span class="n">serial_output</span> <span class="o">=</span> <span class="n">run_mpm_simulator</span><span class="o">.</span><span class="n">outputs</span> + +<span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +<span class="c1"># max_workers controls maximum number of tasks running in parallel</span> +<span class="n">run_mpm_simulator</span><span class="o">.</span><span class="n">parallel_run</span><span class="p">(</span><span class="n">var_samples</span><span class="p">,</span> <span class="n">prefixes</span><span class="o">=</span><span class="n">parallel_prefixes</span><span class="p">,</span> <span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> +<span class="n">parallel_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> +<span class="n">parallel_output</span> <span class="o">=</span> <span class="n">run_mpm_simulator</span><span class="o">.</span><span class="n">outputs</span> + +<span class="nb">print</span><span class="p">(</span><span class="s2">"Serial run time: "</span><span class="p">,</span> <span class="n">serial_time</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Parallel run time: "</span><span class="p">,</span> <span class="n">parallel_time</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Serial run time: 1.1941184997558594 +Parallel run time: 0.4859800338745117 +</pre></div> +</div> +<p>Once a simulation is done, its output is saved to <code class="docutils literal notranslate"><span class="pre">dir_out</span></code>. All output files +generated by above simulations are as follows:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">dir_out</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>['serial0_output.npy', 'serial9_output.npy', 'serial11_output.npy', 'parallel10_output.npy', 'parallel0_output.npy', 'parallel5_output.npy', 'parallel11_output.npy', 'serial1_output.npy', 'serial4_output.npy', 'parallel7_output.npy', 'serial5_output.npy', 'serial8_output.npy', 'parallel6_output.npy', 'parallel4_output.npy', 'parallel2_output.npy', 'serial3_output.npy', 'serial6_output.npy', 'parallel3_output.npy', 'serial2_output.npy', 'parallel9_output.npy', 'serial7_output.npy', 'parallel1_output.npy', 'parallel8_output.npy', 'serial10_output.npy'] +</pre></div> +</div> +<p>Once all simulations are done, their outputs can also be accessed by +<a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.outputs" title="psimpy.simulator.run_simulator.RunSimulator.outputs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RunSimulator.outputs</span></code></a> attribute, which is a list.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Here we print the maximum velocity of each simulation in the parallel run.</span> +<span class="n">max_v</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">output</span><span class="p">[:,</span><span class="mi">5</span><span class="p">])</span> <span class="k">for</span> <span class="n">output</span> <span class="ow">in</span> <span class="n">parallel_output</span><span class="p">]</span> +<span class="nb">print</span><span class="p">(</span> + <span class="sa">f</span><span class="s2">"Maximum velocity of </span><span class="si">{</span><span class="n">parallel_prefixes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s2"> to </span><span class="si">{</span><span class="n">parallel_prefixes</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="si">}</span><span class="s2"> are: "</span><span class="p">,</span> + <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> + <span class="n">max_v</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>Maximum velocity of parallel0 to parallel11 are: + [16.55505557211892, 22.014114896121015, 26.245546886730782, 29.78487303612985, 15.34198274528081, 20.371864007499866, 24.249957243412815, 27.485487855011687, 14.031665649204944, 18.589324449452967, 22.092803891476187, 24.99727320816709] +</pre></div> +</div> +<div class="admonition warning"> +<p class="admonition-title">Warning</p> +<p>If one simulation failed due to whatever reason, the error massage +will be printed to the screen but other simulations will continue. In that +case, the output file of failed simulation will not be writted to <code class="docutils literal notranslate"><span class="pre">dir_out</span></code>. +Also, the element of <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.outputs" title="psimpy.simulator.run_simulator.RunSimulator.outputs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RunSimulator.outputs</span></code></a> corresponding to that +simulation will be a string representing the error message, instead of a +numpy array.</p> +</div> +<p>Here we delete the folder <cite>temp_run_MassPointModel_example</cite> and all files therein.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">shutil</span> + +<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">dir_out</span><span class="p">)</span> +</pre></div> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 1.687 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-simulator-plot-run-mass-point-model-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/4d495ff630306dd98ca342f01931251c/plot_run_mass_point_model.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_run_mass_point_model.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/39558f3ab53d6f797e2208e7c89063a5/plot_run_mass_point_model.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_run_mass_point_model.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_mass_point_model.html" class="btn btn-neutral float-left" title="Mass Point Model" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="plot_ravaflow24.html" class="btn btn-neutral float-right" title="Ravaflow24 Mixture Model" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/simulator/plot_run_ravaflow24.html b/docs/source/_build/html/auto_examples/simulator/plot_run_ravaflow24.html new file mode 100644 index 0000000000000000000000000000000000000000..9827818b6a3a926ec4784e143f28e135eb42171a --- /dev/null +++ b/docs/source/_build/html/auto_examples/simulator/plot_run_ravaflow24.html @@ -0,0 +1,333 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>RunSimulator: Ravaflow24 Mixture Model — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="Changes" href="../../changelog.html" /> + <link rel="prev" title="Ravaflow24 Mixture Model" href="plot_ravaflow24.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../../examples.html">Example Gallery</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../emulator/index.html">Emulator</a></li> +<li class="toctree-l2"><a class="reference internal" href="../inference/index.html">Inference</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sampler/index.html">Sampler</a></li> +<li class="toctree-l2"><a class="reference internal" href="../sensitivity/index.html">Sensitivity</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="index.html">Simulator</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="plot_mass_point_model.html">Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_run_mass_point_model.html">RunSimulator: Mass Point Model</a></li> +<li class="toctree-l3"><a class="reference internal" href="plot_ravaflow24.html">Ravaflow24 Mixture Model</a></li> +<li class="toctree-l3 current"><a class="current reference internal" href="#">RunSimulator: Ravaflow24 Mixture Model</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item"><a href="../../examples.html">Example Gallery</a></li> + <li class="breadcrumb-item"><a href="index.html">Simulator</a></li> + <li class="breadcrumb-item active">RunSimulator: Ravaflow24 Mixture Model</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/simulator/plot_run_ravaflow24.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <div class="sphx-glr-download-link-note admonition note"> +<p class="admonition-title">Note</p> +<p>Click <a class="reference internal" href="#sphx-glr-download-auto-examples-simulator-plot-run-ravaflow24-py"><span class="std std-ref">here</span></a> +to download the full example code</p> +</div> +<section class="sphx-glr-example-title" id="runsimulator-ravaflow24-mixture-model"> +<span id="sphx-glr-auto-examples-simulator-plot-run-ravaflow24-py"></span><h1>RunSimulator: Ravaflow24 Mixture Model<a class="headerlink" href="#runsimulator-ravaflow24-mixture-model" title="Permalink to this heading"></a></h1> +<p>This example shows how to run multiple Ravaflow24Mixture simulations in serial +and parallelly using <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a>.</p> +<p>First, we import the class <a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">Ravaflow24Mixture</span> +</pre></div> +</div> +<p>To create an instance of this class, we must specify the parameter <code class="docutils literal notranslate"><span class="pre">dir_sim</span></code>. +It represents the directory in which output files generated by r.avaflow will be +saved.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> + +<span class="c1"># Here we create a folder called `temp1_run_Ravaflow24Mixture_example` to save</span> +<span class="c1"># output files generated by r.avaflow</span> +<span class="n">cwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span> +<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="s1">'temp1_run_Ravaflow24Mixture_example'</span><span class="p">):</span> + <span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="s1">'temp1_run_Ravaflow24Mixture_example'</span><span class="p">)</span> +<span class="n">dir_sim</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s1">'temp1_run_Ravaflow24Mixture_example'</span><span class="p">)</span> +</pre></div> +</div> +<p>Given <code class="docutils literal notranslate"><span class="pre">dir_sim</span></code>, we can create an instance of <a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a>. +To reduce simulation time, we set <code class="docutils literal notranslate"><span class="pre">time_end</span></code> to <span class="math notranslate nohighlight">\(50\)</span>. Other parameters +are set to their default values.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">voellmy_model</span> <span class="o">=</span> <span class="n">Ravaflow24Mixture</span><span class="p">(</span><span class="n">dir_sim</span><span class="p">,</span> <span class="n">time_end</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span> +</pre></div> +</div> +<p>The <cite>simulator</cite> in this example is defined based on <code class="docutils literal notranslate"><span class="pre">voellmy_model</span></code> as follows. +It takes required inputs and returns the overall impact area.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> + +<span class="k">def</span> <span class="nf">simulator</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">elevation</span><span class="p">,</span> <span class="n">hrelease</span><span class="p">,</span> <span class="n">basal_friction</span><span class="p">,</span> <span class="n">turbulent_friction</span><span class="p">,</span> <span class="n">EPSG</span><span class="p">):</span> + <span class="sd">"""Preprocess required inputs, run simulation, and return output as a numpy array."""</span> + <span class="n">grass_location</span><span class="p">,</span> <span class="n">sh_file</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="n">prefix</span><span class="p">,</span> <span class="n">elevation</span><span class="o">=</span><span class="n">elevation</span><span class="p">,</span> + <span class="n">hrelease</span><span class="o">=</span><span class="n">hrelease</span><span class="p">,</span> <span class="n">basal_friction</span><span class="o">=</span><span class="n">basal_friction</span><span class="p">,</span> <span class="n">turbulent_friction</span><span class="o">=</span><span class="n">turbulent_friction</span><span class="p">,</span> <span class="n">EPSG</span><span class="o">=</span><span class="n">EPSG</span><span class="p">)</span> + <span class="n">voellmy_model</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">grass_location</span><span class="p">,</span> <span class="n">sh_file</span><span class="p">)</span> <span class="c1"># run this line, r.avaflow will write outputs to dir_sim</span> + <span class="n">impact_area</span> <span class="o">=</span> <span class="n">voellmy_model</span><span class="o">.</span><span class="n">extract_impact_area</span><span class="p">(</span><span class="n">prefix</span><span class="p">)</span> + + <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">impact_area</span><span class="p">])</span> <span class="c1"># define dir_out and set save_out to True, returned numpy array will be saved to dir_out</span> +</pre></div> +</div> +<p>To demonstrate how to run multiple simulations using <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a>, +we choose <code class="docutils literal notranslate"><span class="pre">basal_friction</span></code> and <code class="docutils literal notranslate"><span class="pre">turbulent_friction</span></code> as variable input +parameters. Each has two different values, leading to four simulations.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">itertools</span> + +<span class="n">var_inp_parameter</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'basal_friction'</span><span class="p">,</span> <span class="s1">'turbulent_friction'</span><span class="p">]</span> +<span class="n">basal_friction</span> <span class="o">=</span> <span class="p">[</span><span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">]</span> +<span class="n">turbulent_friction</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span> +<span class="n">var_samples</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span> + <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="n">basal_friction</span><span class="p">,</span> <span class="n">turbulent_friction</span><span class="p">)])</span> +</pre></div> +</div> +<p>Other parameters of the <cite>simulator</cite>, including <code class="docutils literal notranslate"><span class="pre">elevation</span></code>, <code class="docutils literal notranslate"><span class="pre">hrelease</span></code>, and +<code class="docutils literal notranslate"><span class="pre">EPSG</span></code> are treated as fixed input. It means that their values are the same in +all simulations.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">dir_data</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s1">'../../../tests/data/'</span><span class="p">)</span> +<span class="n">elevation</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'synthetic_topo.tif'</span><span class="p">)</span> +<span class="n">hrelease</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_data</span><span class="p">,</span> <span class="s1">'synthetic_rel.tif'</span><span class="p">)</span> +<span class="n">fix_inp</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'elevation'</span><span class="p">:</span> <span class="n">elevation</span><span class="p">,</span> <span class="s1">'hrelease'</span><span class="p">:</span> <span class="n">hrelease</span><span class="p">,</span> <span class="s1">'EPSG'</span><span class="p">:</span> <span class="s1">'2326'</span><span class="p">}</span> +</pre></div> +</div> +<p>The parameter <code class="docutils literal notranslate"><span class="pre">prefix</span></code> of the <cite>simulator</cite> is special. It is not involved in +the computational model, but only used to name output files generated by r.avaflow. +Such parameter is not defined in <code class="docutils literal notranslate"><span class="pre">var_inp_parameter</span></code> or <code class="docutils literal notranslate"><span class="pre">fix_inp</span></code> of +<a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a>. Instead, we use a seperate parameter, called <code class="docutils literal notranslate"><span class="pre">o_parameter</span></code> +for this purpose.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">o_parameter</span> <span class="o">=</span> <span class="s1">'prefix'</span> +</pre></div> +</div> +<p>We may want to save outputs returned by the <cite>simulator</cite> at each simulation for +later inspection or processing. In that case, we need to define <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> and +set <code class="docutils literal notranslate"><span class="pre">save_out</span></code> as <cite>True</cite>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> + +<span class="n">cwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span> +<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="s1">'temp2_run_Ravaflow24Mixture_example'</span><span class="p">):</span> + <span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="s1">'temp2_run_Ravaflow24Mixture_example'</span><span class="p">)</span> +<span class="n">dir_out</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s1">'temp2_run_Ravaflow24Mixture_example'</span><span class="p">)</span> +</pre></div> +</div> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p>Please note that <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> and <code class="docutils literal notranslate"><span class="pre">dir_sim</span></code> are two different +parameters for different purposes.</p> +<blockquote> +<div><ul class="simple"> +<li><p><code class="docutils literal notranslate"><span class="pre">dir_out</span></code> is a parameter of <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a>. The <cite>simulator</cite> +returns output of interest as a numpy array for each simulation. If +we want to save this returned output of interest (here impact area) +to our local machine, we need to specify the value of <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> which +represents the directory in which output of interest will be saved and +set <code class="docutils literal notranslate"><span class="pre">save_out</span></code> to <cite>True</cite>. Otherwise, we do not need <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> and +leave <code class="docutils literal notranslate"><span class="pre">save_out</span></code> to <cite>False</cite>.</p></li> +<li><p><code class="docutils literal notranslate"><span class="pre">dir_sim</span></code> is a parameter of <a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a>. <a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ravaflow24Mixture</span></code></a> +relies on the third party software r.avaflow 2.4. When we call +<a class="reference internal" href="../../simulator/ravaflow24.html#psimpy.simulator.ravaflow24.Ravaflow24Mixture.run" title="psimpy.simulator.ravaflow24.Ravaflow24Mixture.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Ravaflow24Mixture.run()</span></code></a> in the function body of above <cite>simulator</cite>, +r.avaflow 2.4 will be run and it generates output files. The value of +<code class="docutils literal notranslate"><span class="pre">dir_sim</span></code> specifies the directory in which output files generated by +r.avaflow 2.4 are going to be saved.</p></li> +</ul> +</div></blockquote> +<p>The value of <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> and <code class="docutils literal notranslate"><span class="pre">dir_sim</span></code> can be the same if file names +have no conflict. We recommend to keep them seperate. In addition, if the function +body of the <cite>simulator</cite> does not write files to disk, <code class="docutils literal notranslate"><span class="pre">dir_sim</span></code> is not required. Our +<a class="reference internal" href="../../simulator/mass_point_model.html#psimpy.simulator.mass_point_model.MassPointModel" title="psimpy.simulator.mass_point_model.MassPointModel"><code class="xref py py-class docutils literal notranslate"><span class="pre">MassPointModel</span></code></a> is an example. Similarly, if we do not want to save +returned numpy array of the <cite>simulator</cite>, <code class="docutils literal notranslate"><span class="pre">dir_out</span></code> is not needed.</p> +</div> +<p>Now we can define an object of <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator" title="psimpy.simulator.run_simulator.RunSimulator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunSimulator</span></code></a> by</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">psimpy.simulator</span> <span class="kn">import</span> <span class="n">RunSimulator</span> + +<span class="n">run_simulator</span> <span class="o">=</span> <span class="n">RunSimulator</span><span class="p">(</span><span class="n">simulator</span><span class="p">,</span> <span class="n">var_inp_parameter</span><span class="p">,</span> <span class="n">fix_inp</span><span class="p">,</span> <span class="n">o_parameter</span><span class="p">,</span> + <span class="n">dir_out</span><span class="p">,</span> <span class="n">save_out</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</pre></div> +</div> +<p>Before running simulations, we need to specify values of <code class="docutils literal notranslate"><span class="pre">prefixes</span></code> which +will be used to name files generated by each r.avaflow simulation and +each returned numpy array of <cite>simulator</cite>.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">serial_prefixes</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"serial"</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">var_samples</span><span class="p">))]</span> +<span class="n">parallel_prefixes</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"parallel"</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">var_samples</span><span class="p">))]</span> +</pre></div> +</div> +<p>Now we can use <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.serial_run" title="psimpy.simulator.run_simulator.RunSimulator.serial_run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RunSimulator.serial_run()</span></code></a> method or +<a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.parallel_run" title="psimpy.simulator.run_simulator.RunSimulator.parallel_run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RunSimulator.parallel_run()</span></code></a> method to run the simulations +in serial or parallelly.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span> + +<span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +<span class="n">run_simulator</span><span class="o">.</span><span class="n">serial_run</span><span class="p">(</span><span class="n">var_samples</span><span class="o">=</span><span class="n">var_samples</span><span class="p">,</span> <span class="n">prefixes</span><span class="o">=</span><span class="n">serial_prefixes</span><span class="p">)</span> +<span class="n">serial_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> +<span class="n">serial_output</span> <span class="o">=</span> <span class="n">run_simulator</span><span class="o">.</span><span class="n">outputs</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"serial_output: </span><span class="si">{</span><span class="n">serial_output</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> + +<span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +<span class="c1"># append setting to True means that simulation outputs of parallel run will be</span> +<span class="c1"># appended to above serial run outputs</span> +<span class="n">run_simulator</span><span class="o">.</span><span class="n">parallel_run</span><span class="p">(</span><span class="n">var_samples</span><span class="p">,</span> <span class="n">prefixes</span><span class="o">=</span><span class="n">parallel_prefixes</span><span class="p">,</span> + <span class="n">max_workers</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +<span class="n">parallel_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> + +<span class="n">parallel_output</span> <span class="o">=</span> <span class="n">run_simulator</span><span class="o">.</span><span class="n">outputs</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">var_samples</span><span class="p">):]</span> +<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"parallel_output: </span><span class="si">{</span><span class="n">parallel_output</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> + + +<span class="nb">print</span><span class="p">(</span><span class="s2">"Serial run time: "</span><span class="p">,</span> <span class="n">serial_time</span><span class="p">)</span> +<span class="nb">print</span><span class="p">(</span><span class="s2">"Parallel run time: "</span><span class="p">,</span> <span class="n">parallel_time</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>serial_output: [array([1008000.]), array([1520800.]), array([674000.]), array([869600.])] +parallel_output: [array([1008000.]), array([1520800.]), array([674000.]), array([869600.])] +Serial run time: 110.85352993011475 +Parallel run time: 62.39644193649292 +</pre></div> +</div> +<p>All output files returned by the <cite>simulator</cite> are</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">dir_out</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>['serial0_output.npy', 'parallel0_output.npy', 'serial1_output.npy', 'parallel2_output.npy', 'serial3_output.npy', 'parallel3_output.npy', 'serial2_output.npy', 'parallel1_output.npy'] +</pre></div> +</div> +<p>All output files/directories generated by r.avaflow simulations +(including files/directories generated during preprocessing) are</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">dir_sim</span><span class="p">)</span> +</pre></div> +</div> +<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span>['serial0_glocation', 'parallel3_results', 'parallel2_glocation', 'serial3_shell.sh', 'parallel1_results', 'serial3_glocation', 'serial1_shell.sh', 'parallel2_results', 'serial0_shell.sh', 'parallel1_glocation', 'parallel3_shell.sh', 'parallel0_shell.sh', 'serial1_glocation', 'parallel1_shell.sh', 'parallel2_shell.sh', 'serial0_results', 'serial1_results', 'serial2_shell.sh', 'serial2_glocation', 'serial2_results', 'parallel3_glocation', 'parallel0_glocation', 'serial3_results', 'parallel0_results'] +</pre></div> +</div> +<div class="admonition warning"> +<p class="admonition-title">Warning</p> +<p>If one simulation failed due to whatever reason, the error massage +will be printed to the screen but other simulations will continue. In that +case, the output file of failed simulation will not be writted to <code class="docutils literal notranslate"><span class="pre">dir_out</span></code>. +Also, the element of <a class="reference internal" href="../../simulator/run_simulator.html#psimpy.simulator.run_simulator.RunSimulator.outputs" title="psimpy.simulator.run_simulator.RunSimulator.outputs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RunSimulator.outputs</span></code></a> corresponding to that +simulation will be a string representing the error message, instead of a +numpy array.</p> +</div> +<p>In the end, we delete the folder <cite>temp1_run_Ravaflow24Mixture_example</cite> and +<cite>temp2_run_Ravaflow24Mixture_example</cite> and all files therein.</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">shutil</span> + +<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">dir_sim</span><span class="p">)</span> +<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">dir_out</span><span class="p">)</span> +</pre></div> +</div> +<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 2 minutes 53.318 seconds)</p> +<div class="sphx-glr-footer sphx-glr-footer-example docutils container" id="sphx-glr-download-auto-examples-simulator-plot-run-ravaflow24-py"> +<div class="sphx-glr-download sphx-glr-download-python docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/06e1d1c67d64bdd5612e33cffc1295c5/plot_run_ravaflow24.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">plot_run_ravaflow24.py</span></code></a></p> +</div> +<div class="sphx-glr-download sphx-glr-download-jupyter docutils container"> +<p><a class="reference download internal" download="" href="../../_downloads/ad745ba736a627e1e1bb6fcec00ac417/plot_run_ravaflow24.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">plot_run_ravaflow24.ipynb</span></code></a></p> +</div> +</div> +<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p> +</section> + + + </div> + </div> + <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> + <a href="plot_ravaflow24.html" class="btn btn-neutral float-left" title="Ravaflow24 Mixture Model" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> + <a href="../../changelog.html" class="btn btn-neutral float-right" title="Changes" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> + </div> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file diff --git a/docs/source/_build/html/auto_examples/simulator/sg_execution_times.html b/docs/source/_build/html/auto_examples/simulator/sg_execution_times.html new file mode 100644 index 0000000000000000000000000000000000000000..b84b620fc5bf7683813f6003169b97b1d2d21bae --- /dev/null +++ b/docs/source/_build/html/auto_examples/simulator/sg_execution_times.html @@ -0,0 +1,139 @@ +<!DOCTYPE html> +<html class="writer-html5" lang="en" > +<head> + <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> + + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Computation times — PSimPy's documentation</title> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> + <!--[if lt IE 9]> + <script src="../../_static/js/html5shiv.min.js"></script> + <![endif]--> + + <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> + <script src="../../_static/jquery.js"></script> + <script src="../../_static/underscore.js"></script> + <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> + <script src="../../_static/doctools.js"></script> + <script src="../../_static/sphinx_highlight.js"></script> + <script src="../../_static/js/theme.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> +</head> + +<body class="wy-body-for-nav"> + <div class="wy-grid-for-nav"> + <nav data-toggle="wy-nav-shift" class="wy-nav-side"> + <div class="wy-side-scroll"> + <div class="wy-side-nav-search" > + <a href="../../index.html" class="icon icon-home"> psimpy + </a> + <div class="version"> + 0.1.2 + </div> +<div role="search"> + <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> + <input type="text" name="q" placeholder="Search docs" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> + </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> + <ul> +<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Getting Started</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../api.html">API & Theory</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../examples.html">Example Gallery</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changes</a></li> +<li class="toctree-l1"><a class="reference internal" href="../../refs.html">References</a></li> +</ul> + + </div> + </div> + </nav> + + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> + <a href="../../index.html">psimpy</a> + </nav> + + <div class="wy-nav-content"> + <div class="rst-content"> + <div role="navigation" aria-label="Page navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="../../index.html" class="icon icon-home"></a></li> + <li class="breadcrumb-item active">Computation times</li> + <li class="wy-breadcrumbs-aside"> + <a href="../../_sources/auto_examples/simulator/sg_execution_times.rst.txt" rel="nofollow"> View page source</a> + </li> + </ul> + <hr/> +</div> + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> + <div itemprop="articleBody"> + + <section id="computation-times"> +<span id="sphx-glr-auto-examples-simulator-sg-execution-times"></span><h1>Computation times<a class="headerlink" href="#computation-times" title="Permalink to this heading"></a></h1> +<p><strong>08:52.712</strong> total execution time for <strong>auto_examples_simulator</strong> files:</p> +<table class="docutils align-default"> +<colgroup> +<col style="width: 85%" /> +<col style="width: 9%" /> +<col style="width: 6%" /> +</colgroup> +<tbody> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_ravaflow24.html#sphx-glr-auto-examples-simulator-plot-ravaflow24-py"><span class="std std-ref">Ravaflow24 Mixture Model</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_ravaflow24.py</span></code>)</p></td> +<td><p>05:56.157</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-even"><td><p><a class="reference internal" href="plot_run_ravaflow24.html#sphx-glr-auto-examples-simulator-plot-run-ravaflow24-py"><span class="std std-ref">RunSimulator: Ravaflow24 Mixture Model</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_run_ravaflow24.py</span></code>)</p></td> +<td><p>02:53.318</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-odd"><td><p><a class="reference internal" href="plot_run_mass_point_model.html#sphx-glr-auto-examples-simulator-plot-run-mass-point-model-py"><span class="std std-ref">RunSimulator: Mass Point Model</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_run_mass_point_model.py</span></code>)</p></td> +<td><p>00:01.687</p></td> +<td><p>0.0 MB</p></td> +</tr> +<tr class="row-even"><td><p><a class="reference internal" href="plot_mass_point_model.html#sphx-glr-auto-examples-simulator-plot-mass-point-model-py"><span class="std std-ref">Mass Point Model</span></a> (<code class="docutils literal notranslate"><span class="pre">plot_mass_point_model.py</span></code>)</p></td> +<td><p>00:01.550</p></td> +<td><p>0.0 MB</p></td> +</tr> +</tbody> +</table> +</section> + + + </div> + </div> + <footer> + + <hr/> + + <div role="contentinfo"> + <p>© Copyright 2023, Hu Zhao.</p> + </div> + + Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a + <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> + provided by <a href="https://readthedocs.org">Read the Docs</a>. + + +</footer> + </div> + </div> + </section> + </div> + <script> + jQuery(function () { + SphinxRtdTheme.Navigation.enable(true); + }); + </script> + +</body> +</html> \ No newline at end of file