Created
December 7, 2018 16:11
-
-
Save tupui/0391072ff327cbef2f7ffba8ec47f430 to your computer and use it in GitHub Desktop.
Visual explanation of Moment independent sensitivity analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r"""Visual explanation of Moment independent sensitivity analysis. | |
Moment-based method are based on the whole PDF to mitigate these | |
issues (Borgonovo2007). Based on the unconditional PDF, a conditional PDF per | |
parameter is computed. The more the conditional PDF deviates from the | |
unconditional PDF, the more the parameter has an impact on the quantity of | |
interest. The same procedure can be done using the Empirical Cumulative | |
Density Function (ECDF), respectively with the unconditional ECDF. | |
This visually shows this procedure. Bins of samples (red circles) are used to | |
compute a conditional PDF of the output. This PDF is compared to the | |
unconditional PDF (black). | |
Reference: | |
Borgonovo. A new uncertainty importance measure. RESS, 2007. DOI: 10.1016/j.ress.2006.04 | |
--------------------------- | |
MIT License | |
Copyright (c) 2018 Pamphile Tupui ROY | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
""" | |
import numpy as np | |
from scipy.stats import gaussian_kde | |
from batman.functions import Ishigami | |
from batman.space import Space | |
import matplotlib.pyplot as plt | |
p_labels = ['$x_1$', '$x_2$', '$x_3$'] | |
sample = Space([[-np.pi, -np.pi, -np.pi], [np.pi, np.pi, np.pi]]) | |
sample.sampling(1000) | |
n_dim = sample.shape[1] | |
func = Ishigami() | |
output = func(sample).flatten() | |
mini = np.min(output) | |
maxi = np.max(output) | |
n_bins = 10 | |
bins = np.linspace(-np.pi, np.pi, num=n_bins, endpoint=False) | |
dx = bins[1] - bins[0] | |
# Moment explanation | |
# Unconditional PDF | |
xs = np.linspace(mini, maxi, 100) | |
pdf_u = gaussian_kde(output, bw_method="silverman")(xs) | |
fig, ax = plt.subplots(2, n_dim) | |
for i in range(n_dim): | |
xi = sample[:, i] | |
ax[0][i].scatter(xi, output, marker='+') | |
ax[0][i].set_xlabel(p_labels[i]) | |
ax[1][i].plot(xs, pdf_u, c='k') | |
for bin_ in bins[:1]: | |
idx = np.where((bin_ <= xi) & (xi <= bin_ + dx)) | |
xi_ = xi[idx] | |
y_ = output[idx] | |
ax[0][i].scatter(xi_, y_, c='r') | |
pdf_c = gaussian_kde(y_, bw_method="silverman")(xs) | |
ax[1][i].plot(xs, pdf_c, ls='--') | |
ax[0][0].set_ylabel('Y') | |
ax[1][0].set_ylabel('PDF') | |
ax[1][1].set_xlabel('Y') | |
plt.tight_layout() | |
plt.show() |
Author
tupui
commented
Dec 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment