diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a2091c51..de36617a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -152,18 +152,18 @@ jobs: displayName: Install Anaconda packages condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') - - bash: | - source activate myEnvironment - conda build . recipe --variants "{'version': ['$(GitVersion.SemVer)']}" - displayName: Build Noarch conda packages - condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') - - - bash: | - source activate myEnvironment - anaconda login --username $(ANACONDAUSER) --password $(ANACONDAPW) - anaconda upload /usr/local/miniconda/envs/myEnvironment/conda-bld/noarch/*.tar.bz2 - displayName: Upload conda packages - condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') +# - bash: | +# source activate myEnvironment +# conda build . recipe --variants "{'version': ['$(GitVersion.SemVer)']}" +# displayName: Build Noarch conda packages +# condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') +# +# - bash: | +# source activate myEnvironment +# anaconda login --username $(ANACONDAUSER) --password $(ANACONDAPW) +# anaconda upload /usr/local/miniconda/envs/myEnvironment/conda-bld/noarch/*.tar.bz2 +# displayName: Upload conda packages +# condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') - job: "Create_Docker_images" dependsOn: Build_UQpy_and_run_tests diff --git a/docs/code/sensitivity/chatterjee/plot_chatterjee_exponential.py b/docs/code/sensitivity/chatterjee/chatterjee_exponential.py similarity index 94% rename from docs/code/sensitivity/chatterjee/plot_chatterjee_exponential.py rename to docs/code/sensitivity/chatterjee/chatterjee_exponential.py index 04cf4cf0..d824a885 100644 --- a/docs/code/sensitivity/chatterjee/plot_chatterjee_exponential.py +++ b/docs/code/sensitivity/chatterjee/chatterjee_exponential.py @@ -52,7 +52,7 @@ SA = ChatterjeeSensitivity(runmodel_obj, dist_object) # Compute Chatterjee indices using the pick and freeze algorithm -computed_indices = SA.run(n_samples=1_000_000) +SA.run(n_samples=1_000_000) # %% [markdown] # **Chattererjee indices** @@ -66,11 +66,11 @@ # :math:`S^2_{CVM} = \frac{6}{\pi} \operatorname{arctan}(\sqrt{19}) - 2 \approx 0.5693` # %% -computed_indices["chatterjee_i"] +SA.first_order_chatterjee_indices # **Plot the Chatterjee indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["chatterjee_i"][:, 0], + SA.first_order_chatterjee_indices[:, 0], plot_title="Chatterjee indices", color="C2", ) diff --git a/docs/code/sensitivity/chatterjee/plot_chatterjee_ishigami.py b/docs/code/sensitivity/chatterjee/chatterjee_ishigami.py similarity index 85% rename from docs/code/sensitivity/chatterjee/plot_chatterjee_ishigami.py rename to docs/code/sensitivity/chatterjee/chatterjee_ishigami.py index 696a07fe..16807e1e 100644 --- a/docs/code/sensitivity/chatterjee/plot_chatterjee_ishigami.py +++ b/docs/code/sensitivity/chatterjee/chatterjee_ishigami.py @@ -4,7 +4,7 @@ ============================================== The ishigami function is a non-linear, non-monotonic function that is commonly used to -benchmark uncertainty and senstivity analysis methods. +benchmark uncertainty and sensitivity analysis methods. .. math:: f(x_1, x_2, x_3) = sin(x_1) + a \cdot sin^2(x_2) + b \cdot x_3^4 sin(x_1) @@ -49,7 +49,7 @@ # %% [markdown] SA = ChatterjeeSensitivity(runmodel_obj, dist_object) -computed_indices = SA.run( +SA.run( n_samples=100_000, estimate_sobol_indices=True, n_bootstrap_samples=100, @@ -60,18 +60,18 @@ # **Chattererjee indices** # %% -computed_indices["chatterjee_i"] +SA.first_order_chatterjee_indices # %% [markdown] # **Confidence intervals for the Chatterjee indices** # %% -computed_indices["confidence_interval_chatterjee_i"] +SA.confidence_interval_chatterjee # **Plot the Chatterjee indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["chatterjee_i"][:, 0], - computed_indices["confidence_interval_chatterjee_i"], + SA.first_order_chatterjee_indices[:, 0], + SA.confidence_interval_chatterjee, plot_title="Chatterjee indices", color="C2", ) @@ -88,11 +88,11 @@ # :math:`S_3`: 0.0 # %% -computed_indices["sobol_i"] +SA.first_order_sobol_indices # **Plot the first order Sobol indices** fig2, ax2 = plot_sensitivity_index( - computed_indices["sobol_i"][:, 0], + SA.first_order_sobol_indices[:, 0], plot_title="First order Sobol indices", color="C0", ) diff --git a/docs/code/sensitivity/chatterjee/plot_chatterjee_sobol_func.py b/docs/code/sensitivity/chatterjee/chatterjee_sobol_func.py similarity index 91% rename from docs/code/sensitivity/chatterjee/plot_chatterjee_sobol_func.py rename to docs/code/sensitivity/chatterjee/chatterjee_sobol_func.py index 3d54ad38..293b2b88 100644 --- a/docs/code/sensitivity/chatterjee/plot_chatterjee_sobol_func.py +++ b/docs/code/sensitivity/chatterjee/chatterjee_sobol_func.py @@ -68,17 +68,17 @@ SA = ChatterjeeSensitivity(runmodel_obj, dist_object) # Compute Chatterjee indices using rank statistics -computed_indices = SA.run(n_samples=500_000, estimate_sobol_indices=True) +SA.run(n_samples=500_000, estimate_sobol_indices=True) # %% [markdown] # **Chatterjee indices** # %% -computed_indices["chatterjee_i"] +SA.first_order_chatterjee_indices # **Plot the Chatterjee indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["chatterjee_i"][:, 0], + SA.first_order_chatterjee_indices[:, 0], plot_title="Chatterjee indices", color="C2", ) @@ -101,11 +101,11 @@ # :math:`S_6` = 0.03760626 # %% -computed_indices["sobol_i"] +SA.first_order_sobol_indices # **Plot the first order Sobol indices** fig2, ax2 = plot_sensitivity_index( - computed_indices["sobol_i"][:, 0], + SA.first_order_sobol_indices[:, 0], plot_title="First order Sobol indices", color="C0", ) @@ -143,12 +143,12 @@ for i, sample_size in enumerate(sample_sizes): # Estimate using rank statistics - _indices = SA_chatterjee.run(n_samples=sample_size*7, estimate_sobol_indices=True) - store_rank_stats[:, i] = _indices["sobol_i"].ravel() + SA_chatterjee.run(n_samples=sample_size*7, estimate_sobol_indices=True) + store_rank_stats[:, i] = SA_chatterjee.first_order_sobol_indices.ravel() # Estimate using Pick and Freeze approach - _indices = SA_sobol.run(n_samples=sample_size) - store_pick_freeze[:, i] = _indices["sobol_i"].ravel() + SA_sobol.run(n_samples=sample_size) + store_pick_freeze[:, i] = SA_sobol.first_order_indices.ravel() # %% diff --git a/docs/code/sensitivity/comparison/plot_additive.py b/docs/code/sensitivity/comparison/additive.py similarity index 88% rename from docs/code/sensitivity/comparison/plot_additive.py rename to docs/code/sensitivity/comparison/additive.py index 8dd101a1..1a533edd 100644 --- a/docs/code/sensitivity/comparison/plot_additive.py +++ b/docs/code/sensitivity/comparison/additive.py @@ -64,7 +64,7 @@ # %% [markdown] SA_sobol = SobolSensitivity(runmodel_obj, dist_object) -computed_indices_sobol = SA_sobol.run(n_samples=50_000) +SA_sobol.run(n_samples=50_000) # %% [markdown] # **First order Sobol indices** @@ -76,7 +76,7 @@ # :math:`\mathrm{S}_2 = \frac{b^2 \cdot \mathbb{V}[X_2]}{a^2 \cdot \mathbb{V}[X_1] + b^2 \cdot \mathbb{V}[X_2]} = \frac{2^2 \cdot 1}{1^2 \cdot 1 + 2^2 \cdot 1} = 0.8` # %% -computed_indices_sobol["sobol_i"] +SA_sobol.first_order_indices # %% [markdown] # **Compute Chatterjee indices** @@ -84,19 +84,19 @@ # %% [markdown] SA_chatterjee = ChatterjeeSensitivity(runmodel_obj, dist_object) -computed_indices_chatterjee = SA_chatterjee.run(n_samples=50_000) +SA_chatterjee.run(n_samples=50_000) # %% -computed_indices_chatterjee["chatterjee_i"] +SA_chatterjee.first_order_chatterjee_indices # %% SA_cvm = cvm(runmodel_obj, dist_object) # Compute CVM indices using the pick and freeze algorithm -computed_indices_cvm = SA_cvm.run(n_samples=20_000, estimate_sobol_indices=True) +SA_cvm.run(n_samples=20_000, estimate_sobol_indices=True) # %% -computed_indices_cvm["CVM_i"] +SA_cvm.first_order_CramerVonMises_indices # %% # **Plot all indices** @@ -106,9 +106,9 @@ variable_names = [r"$X_{}$".format(i + 1) for i in range(num_vars)] # round to 2 decimal places -indices_1 = np.around(computed_indices_sobol["sobol_i"][:, 0], decimals=2) -indices_2 = np.around(computed_indices_chatterjee["chatterjee_i"][:, 0], decimals=2) -indices_3 = np.around(computed_indices_cvm["CVM_i"][:, 0], decimals=2) +indices_1 = np.around(SA_sobol.first_order_indices[:, 0], decimals=2) +indices_2 = np.around(SA_chatterjee.first_order_chatterjee_indices[:, 0], decimals=2) +indices_3 = np.around(SA_cvm.first_order_CramerVonMises_indices[:, 0], decimals=2) fig, ax = plt.subplots() width = 0.3 diff --git a/docs/code/sensitivity/comparison/plot_ishigami.py b/docs/code/sensitivity/comparison/ishigami.py similarity index 86% rename from docs/code/sensitivity/comparison/plot_ishigami.py rename to docs/code/sensitivity/comparison/ishigami.py index 958cd582..9d8d95a8 100644 --- a/docs/code/sensitivity/comparison/plot_ishigami.py +++ b/docs/code/sensitivity/comparison/ishigami.py @@ -52,7 +52,7 @@ # %% SA_sobol = SobolSensitivity(runmodel_obj, dist_object) -computed_indices_sobol = SA_sobol.run(n_samples=100_000) +SA_sobol.run(n_samples=100_000) # %% [markdown] # **First order Sobol indices** @@ -66,7 +66,7 @@ # :math:`S_3` = 0.0 # %% -computed_indices_sobol["sobol_i"] +SA_sobol.first_order_indices # %% [markdown] # **Total order Sobol indices** @@ -80,7 +80,7 @@ # :math:`S_{T_3}` = 0.24368366 # %% -computed_indices_sobol["sobol_total_i"] +SA_sobol.total_order_indices # %% [markdown] # **Compute Chatterjee indices** @@ -88,20 +88,20 @@ # %% [markdown] SA_chatterjee = ChatterjeeSensitivity(runmodel_obj, dist_object) -computed_indices_chatterjee = SA_chatterjee.run(n_samples=50_000) +SA_chatterjee.run(n_samples=50_000) # %% -computed_indices_chatterjee["chatterjee_i"] +SA_chatterjee.first_order_chatterjee_indices # %% [markdown] # **Compute Cramér-von Mises indices** SA_cvm = cvm(runmodel_obj, dist_object) # Compute CVM indices using the pick and freeze algorithm -computed_indices_cvm = SA_cvm.run(n_samples=20_000, estimate_sobol_indices=True) +SA_cvm.run(n_samples=20_000, estimate_sobol_indices=True) # %% -computed_indices_cvm["CVM_i"] +SA_cvm.first_order_CramerVonMises_indices # %% # **Plot all indices** @@ -111,9 +111,9 @@ variable_names = [r"$X_{}$".format(i + 1) for i in range(num_vars)] # round to 2 decimal places -indices_1 = np.around(computed_indices_sobol["sobol_i"][:, 0], decimals=2) -indices_2 = np.around(computed_indices_chatterjee["chatterjee_i"][:, 0], decimals=2) -indices_3 = np.around(computed_indices_cvm["CVM_i"][:, 0], decimals=2) +indices_1 = np.around(SA_sobol.first_order_indices[:, 0], decimals=2) +indices_2 = np.around(SA_chatterjee.first_order_chatterjee_indices[:, 0], decimals=2) +indices_3 = np.around(SA_cvm.first_order_CramerVonMises_indices[:, 0], decimals=2) fig, ax = plt.subplots() width = 0.3 diff --git a/docs/code/sensitivity/cramer_von_mises/plot_cvm_exponential.py b/docs/code/sensitivity/cramer_von_mises/cvm_exponential.py similarity index 88% rename from docs/code/sensitivity/cramer_von_mises/plot_cvm_exponential.py rename to docs/code/sensitivity/cramer_von_mises/cvm_exponential.py index 81b258bf..8b1e2377 100644 --- a/docs/code/sensitivity/cramer_von_mises/plot_cvm_exponential.py +++ b/docs/code/sensitivity/cramer_von_mises/cvm_exponential.py @@ -48,7 +48,7 @@ SA = cvm(runmodel_obj, dist_object) # Compute CVM indices using the pick and freeze algorithm -computed_indices = SA.run(n_samples=20_000, estimate_sobol_indices=True) +SA.run(n_samples=20_000, estimate_sobol_indices=True) # %% [markdown] # **Cramér-von Mises indices** @@ -60,11 +60,11 @@ # :math:`S^2_{CVM} = \frac{6}{\pi} \operatorname{arctan}(\sqrt{19}) - 2 \approx 0.5693` # %% -computed_indices["CVM_i"] +SA.first_order_CramerVonMises_indices # **Plot the CVM indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["CVM_i"][:, 0], + SA.first_order_CramerVonMises_indices[:, 0], plot_title="Cramér-von Mises indices", color="C4", ) @@ -79,11 +79,11 @@ # :math:`S_2` = 0.3738 # %% -computed_indices["sobol_i"] +SA.first_order_sobol_indices # **Plot the first order Sobol indices** fig2, ax2 = plot_sensitivity_index( - computed_indices["sobol_i"][:, 0], + SA.first_order_sobol_indices[:, 0], plot_title="First order Sobol indices", color="C0", ) @@ -92,12 +92,12 @@ # **Estimated total order Sobol indices** # %% -computed_indices["sobol_total_i"] +SA.total_order_sobol_indices # **Plot the first and total order sensitivity indices** fig3, ax3 = plot_index_comparison( - computed_indices["sobol_i"][:, 0], - computed_indices["sobol_total_i"][:, 0], + SA.first_order_sobol_indices[:, 0], + SA.total_order_sobol_indices[:, 0], label_1="First order Sobol indices", label_2="Total order Sobol indices", plot_title="First and Total order Sobol indices", diff --git a/docs/code/sensitivity/cramer_von_mises/plot_cvm_sobol_func.py b/docs/code/sensitivity/cramer_von_mises/cvm_sobol_func.py similarity index 91% rename from docs/code/sensitivity/cramer_von_mises/plot_cvm_sobol_func.py rename to docs/code/sensitivity/cramer_von_mises/cvm_sobol_func.py index a69ab0e9..cf99040c 100644 --- a/docs/code/sensitivity/cramer_von_mises/plot_cvm_sobol_func.py +++ b/docs/code/sensitivity/cramer_von_mises/cvm_sobol_func.py @@ -62,17 +62,17 @@ SA = cvm(runmodel_obj, dist_object) # Compute Sobol indices using rank statistics -computed_indices = SA.run(n_samples=50_000, estimate_sobol_indices=True) +SA.run(n_samples=50_000, estimate_sobol_indices=True) # %% [markdown] # **Cramér-von Mises indices** # %% -computed_indices["CVM_i"] +SA.first_order_CramerVonMises_indices # **Plot the CVM indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["CVM_i"][:, 0], + SA.first_order_CramerVonMises_indices[:, 0], plot_title="Cramér-von Mises indices", color="C4", ) @@ -95,11 +95,11 @@ # :math:`S_6` = 0.03760626 # %% -computed_indices["sobol_i"] +SA.total_order_sobol_indices # **Plot the first order Sobol indices** fig2, ax2 = plot_sensitivity_index( - computed_indices["sobol_i"][:, 0], + SA.total_order_sobol_indices[:, 0], plot_title="First order Sobol indices", color="C0", ) diff --git a/docs/code/sensitivity/generalised_sobol/plot_generalised_sobol_mechanical_oscillator_ODE.py b/docs/code/sensitivity/generalised_sobol/generalised_sobol_mechanical_oscillator_ODE.py similarity index 91% rename from docs/code/sensitivity/generalised_sobol/plot_generalised_sobol_mechanical_oscillator_ODE.py rename to docs/code/sensitivity/generalised_sobol/generalised_sobol_mechanical_oscillator_ODE.py index e9900578..8ce86328 100644 --- a/docs/code/sensitivity/generalised_sobol/plot_generalised_sobol_mechanical_oscillator_ODE.py +++ b/docs/code/sensitivity/generalised_sobol/generalised_sobol_mechanical_oscillator_ODE.py @@ -63,7 +63,7 @@ # %% [markdown] SA = GeneralisedSobolSensitivity(runmodel_obj, dist_object) -computed_indices = SA.run(n_samples=500) +SA.run(n_samples=500) # %% [markdown] # **First order Generalised Sobol indices** @@ -79,11 +79,11 @@ # :math:`GS_{\ell}` = 0.0561 # %% -computed_indices["gen_sobol_i"] +SA.generalized_first_order_indices # **Plot the first order sensitivity indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["gen_sobol_i"][:, 0], + SA.generalized_first_order_indices[:, 0], plot_title="First order Generalised Sobol indices", variable_names=[r"$m$", "$c$", "$k$", "$\ell$"], color="C0", @@ -93,12 +93,12 @@ # **Total order Generalised Sobol indices** # %% -computed_indices["gen_sobol_total_i"] +SA.generalized_total_order_indices # **Plot the first and total order sensitivity indices** fig2, ax2 = plot_index_comparison( - computed_indices["gen_sobol_i"][:, 0], - computed_indices["gen_sobol_total_i"][:, 0], + SA.generalized_first_order_indices[:, 0], + SA.generalized_total_order_indices[:, 0], label_1="First order", label_2="Total order", plot_title="First and Total order Generalised Sobol indices", diff --git a/docs/code/sensitivity/generalised_sobol/plot_generalised_sobol_multioutput.py b/docs/code/sensitivity/generalised_sobol/generalised_sobol_multioutput.py similarity index 76% rename from docs/code/sensitivity/generalised_sobol/plot_generalised_sobol_multioutput.py rename to docs/code/sensitivity/generalised_sobol/generalised_sobol_multioutput.py index f4347d84..f17f6265 100644 --- a/docs/code/sensitivity/generalised_sobol/plot_generalised_sobol_multioutput.py +++ b/docs/code/sensitivity/generalised_sobol/generalised_sobol_multioutput.py @@ -54,7 +54,7 @@ # %% [markdown] SA = GeneralisedSobolSensitivity(runmodel_obj, dist_object_1) -computed_indices = SA.run( +SA.run( n_samples=20_000, confidence_level=0.95, n_bootstrap_samples=5_00 ) @@ -70,25 +70,25 @@ # :math:`GS_2` = 0.1179 # %% -computed_indices["gen_sobol_i"] +SA.generalized_first_order_indices # **Plot the first order sensitivity indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["gen_sobol_i"][:, 0], - confidence_interval=computed_indices["confidence_interval_gen_sobol_i"], + SA.generalized_first_order_indices[:, 0], + confidence_interval=SA.first_order_confidence_interval, plot_title="First order Generalised Sobol indices", color="C0", ) # %% -computed_indices["gen_sobol_total_i"] +SA.generalized_total_order_indices # **Plot the first and total order sensitivity indices** fig2, ax2 = plot_index_comparison( - computed_indices["gen_sobol_i"][:, 0], - computed_indices["gen_sobol_total_i"][:, 0], - confidence_interval_1=computed_indices["confidence_interval_gen_sobol_i"], - confidence_interval_2=computed_indices["confidence_interval_gen_sobol_total_i"], + SA.generalized_first_order_indices[:, 0], + SA.generalized_total_order_indices[:, 0], + confidence_interval_1=SA.first_order_confidence_interval, + confidence_interval_2=SA.total_order_confidence_interval, label_1="First order", label_2="Total order", plot_title="First and Total order Generalised Sobol indices", @@ -102,7 +102,7 @@ SA = GeneralisedSobolSensitivity(runmodel_obj, dist_object_2) -computed_indices = SA.run( +SA.run( n_samples=20_000, confidence_level=0.95, n_bootstrap_samples=5_00 ) @@ -118,25 +118,25 @@ # :math:`GS_2` = 0.3566 # %% -computed_indices["gen_sobol_i"] +SA.generalized_first_order_indices # **Plot the first order sensitivity indices** fig3, ax3 = plot_sensitivity_index( - computed_indices["gen_sobol_i"][:, 0], - confidence_interval=computed_indices["confidence_interval_gen_sobol_i"], + SA.generalized_first_order_indices[:, 0], + confidence_interval=SA.first_order_confidence_interval, plot_title="First order Generalised Sobol indices", color="C0", ) # %% -computed_indices["gen_sobol_total_i"] +SA.total_order_confidence_interval # **Plot the first and total order sensitivity indices** fig4, ax4 = plot_index_comparison( - computed_indices["gen_sobol_i"][:, 0], - computed_indices["gen_sobol_total_i"][:, 0], - confidence_interval_1=computed_indices["confidence_interval_gen_sobol_i"], - confidence_interval_2=computed_indices["confidence_interval_gen_sobol_total_i"], + SA.generalized_first_order_indices[:, 0], + SA.total_order_confidence_interval[:, 0], + confidence_interval_1=SA.first_order_confidence_interval, + confidence_interval_2=SA.total_order_confidence_interval, label_1="First order", label_2="Total order", plot_title="First and Total order Generalised Sobol indices", diff --git a/docs/code/sensitivity/sobol/plot_mechanical_oscillator_ODE.py b/docs/code/sensitivity/sobol/mechanical_oscillator_ODE.py similarity index 78% rename from docs/code/sensitivity/sobol/plot_mechanical_oscillator_ODE.py rename to docs/code/sensitivity/sobol/mechanical_oscillator_ODE.py index 0403e8a5..5dcbb0ba 100644 --- a/docs/code/sensitivity/sobol/plot_mechanical_oscillator_ODE.py +++ b/docs/code/sensitivity/sobol/mechanical_oscillator_ODE.py @@ -61,7 +61,7 @@ # %% [markdown] SA = SobolSensitivity(runmodel_obj, dist_object) -computed_indices = SA.run(n_samples=500) +SA.run(n_samples=500) # %% # **Plot the Sobol indices** @@ -74,12 +74,10 @@ fig, ax = plt.subplots(1, 2, figsize=(16, 8)) -ax[0].plot(T, computed_indices["sobol_total_i"][0, :], "r", label=r"$m$") -ax[0].plot(T, computed_indices["sobol_total_i"][1, :], "g", label=r"$c$") -ax[0].plot(T, computed_indices["sobol_total_i"][2, :], label=r"$k$", color="royalblue") -ax[0].plot( - T, computed_indices["sobol_total_i"][3, :], label=r"$\ell$", color="aquamarine" -) +ax[0].plot(T, SA.total_order_indices[0, :], "r", label=r"$m$") +ax[0].plot(T, SA.total_order_indices[1, :], "g", label=r"$c$") +ax[0].plot(T, SA.total_order_indices[2, :], label=r"$k$", color="royalblue") +ax[0].plot(T, SA.total_order_indices[3, :], label=r"$\ell$", color="aquamarine") ax[0].set_title("Total order Sobol indices", fontsize=16) ax[0].set_xlabel("time (s)", fontsize=16) @@ -88,10 +86,10 @@ ax[0].set_ybound(-0.2, 1.2) ax[0].legend() -ax[1].plot(T, computed_indices["sobol_i"][0, :], "r", label=r"$m$") -ax[1].plot(T, computed_indices["sobol_i"][1, :], "g", label=r"$c$") -ax[1].plot(T, computed_indices["sobol_i"][2, :], label=r"$k$", color="royalblue") -ax[1].plot(T, computed_indices["sobol_i"][3, :], label=r"$\ell$", color="aquamarine") +ax[1].plot(T, SA.first_order_indices[0, :], "r", label=r"$m$") +ax[1].plot(T, SA.first_order_indices[1, :], "g", label=r"$c$") +ax[1].plot(T, SA.first_order_indices[2, :], label=r"$k$", color="royalblue") +ax[1].plot(T, SA.first_order_indices[3, :], label=r"$\ell$", color="aquamarine") ax[1].set_title("First order Sobol indices", fontsize=16) ax[1].set_xlabel("time (s)", fontsize=16) diff --git a/docs/code/sensitivity/sobol/plot_sobol_additive.py b/docs/code/sensitivity/sobol/sobol_additive.py similarity index 92% rename from docs/code/sensitivity/sobol/plot_sobol_additive.py rename to docs/code/sensitivity/sobol/sobol_additive.py index dca212fe..d3749cad 100644 --- a/docs/code/sensitivity/sobol/plot_sobol_additive.py +++ b/docs/code/sensitivity/sobol/sobol_additive.py @@ -53,7 +53,7 @@ # %% [markdown] SA = SobolSensitivity(runmodel_obj, dist_object) -computed_indices = SA.run(n_samples=50_000) +SA.run(n_samples=50_000) # %% [markdown] # **First order Sobol indices** @@ -65,13 +65,13 @@ # :math:`\mathrm{S}_2 = \frac{b^2 \cdot \mathbb{V}[X_2]}{a^2 \cdot \mathbb{V}[X_1] + b^2 \cdot \mathbb{V}[X_2]} = \frac{2^2 \cdot 1}{1^2 \cdot 1 + 2^2 \cdot 1} = 0.8` # %% -computed_indices["sobol_i"] +SA.first_order_indices # %% # **Plot the first and total order sensitivity indices** fig1, ax1 = plot_index_comparison( - computed_indices["sobol_i"][:, 0], - computed_indices["sobol_total_i"][:, 0], + SA.first_order_indices[:, 0], + SA.total_order_indices[:, 0], label_1="First order Sobol indices", label_2="Total order Sobol indices", plot_title="First and Total order Sobol indices", diff --git a/docs/code/sensitivity/sobol/plot_sobol_func.py b/docs/code/sensitivity/sobol/sobol_func.py similarity index 91% rename from docs/code/sensitivity/sobol/plot_sobol_func.py rename to docs/code/sensitivity/sobol/sobol_func.py index ba28d3e7..5dfdf1dc 100644 --- a/docs/code/sensitivity/sobol/plot_sobol_func.py +++ b/docs/code/sensitivity/sobol/sobol_func.py @@ -62,7 +62,7 @@ SA = SobolSensitivity(runmodel_obj, dist_object) # Compute Sobol indices using the pick and freeze algorithm -computed_indices = SA.run(n_samples=50_000, estimate_second_order=True) +SA.run(n_samples=50_000, estimate_second_order=True) # %% [markdown] # **First order Sobol indices** @@ -82,12 +82,12 @@ # :math:`S_6` = 5.86781190e-05 # %% -computed_indices["sobol_i"] +SA.first_order_indices # %% # **Plot the first order sensitivity indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["sobol_i"][:, 0], + SA.first_order_indices[:, 0], plot_title="First order Sobol indices", color="C0", ) @@ -111,13 +111,13 @@ # # %% -computed_indices["sobol_total_i"] +SA.total_order_indices # %% # **Plot the first and total order sensitivity indices** fig2, ax2 = plot_index_comparison( - computed_indices["sobol_i"][:, 0], - computed_indices["sobol_total_i"][:, 0], + SA.first_order_indices[:, 0], + SA.total_order_indices[:, 0], label_1="First order Sobol indices", label_2="Total order Sobol indices", plot_title="First and Total order Sobol indices", @@ -159,11 +159,11 @@ # :math:`S_{T_{56}}` = 2.0e-9 # %% -computed_indices["sobol_ij"] +SA.second_order_indices # %% # **Plot the second order sensitivity indices** fig3, ax3 = plot_second_order_indices( - computed_indices["sobol_ij"][:, 0], + SA.second_order_indices[:, 0], num_vars=num_vars, ) diff --git a/docs/code/sensitivity/sobol/plot_sobol_ishigami.py b/docs/code/sensitivity/sobol/sobol_ishigami.py similarity index 84% rename from docs/code/sensitivity/sobol/plot_sobol_ishigami.py rename to docs/code/sensitivity/sobol/sobol_ishigami.py index 664bbc0b..5875b8af 100644 --- a/docs/code/sensitivity/sobol/plot_sobol_ishigami.py +++ b/docs/code/sensitivity/sobol/sobol_ishigami.py @@ -74,7 +74,7 @@ # %% SA = SobolSensitivity(runmodel_obj, dist_object) -computed_indices = SA.run(n_samples=100_000, n_bootstrap_samples=100) +SA.run(n_samples=100_000, n_bootstrap_samples=100) # %% [markdown] # **First order Sobol indices** @@ -88,7 +88,7 @@ # :math:`S_3` = 0.0 # %% -computed_indices["sobol_i"] +SA.first_order_indices # %% [markdown] # **Total order Sobol indices** @@ -102,25 +102,25 @@ # :math:`S_{T_3}` = 0.24368366 # %% -computed_indices["sobol_total_i"] +SA.total_order_indices # %% [markdown] # **Confidence intervals for first order Sobol indices** # %% -computed_indices["confidence_interval_sobol_i"] +SA.first_order_confidence_interval # %% [markdown] # **Confidence intervals for total order Sobol indices** # %% -computed_indices["confidence_interval_sobol_total_i"] +SA.total_order_confidence_interval # %% # **Plot the first order sensitivity indices** fig1, ax1 = plot_sensitivity_index( - computed_indices["sobol_i"][:, 0], - confidence_interval=computed_indices["confidence_interval_sobol_i"], + SA.first_order_indices[:, 0], + confidence_interval=SA.first_order_confidence_interval, plot_title="First order Sobol indices", variable_names=["$X_1$", "$X_2$", "$X_3$"], color="C0", @@ -129,10 +129,10 @@ # %% # **Plot the first and total order sensitivity indices** fig2, ax2 = plot_index_comparison( - computed_indices["sobol_i"][:, 0], - computed_indices["sobol_total_i"][:, 0], - confidence_interval_1=computed_indices["confidence_interval_sobol_i"], - confidence_interval_2=computed_indices["confidence_interval_sobol_total_i"], + SA.first_order_indices[:, 0], + SA.total_order_indices[:, 0], + confidence_interval_1=SA.first_order_confidence_interval, + confidence_interval_2=SA.total_order_confidence_interval, label_1="First order Sobol indices", label_2="Total order Sobol indices", plot_title="First and Total order Sobol indices", diff --git a/src/UQpy/sensitivity/SobolSensitivity.py b/src/UQpy/sensitivity/SobolSensitivity.py index 967f8f96..294bc3c5 100644 --- a/src/UQpy/sensitivity/SobolSensitivity.py +++ b/src/UQpy/sensitivity/SobolSensitivity.py @@ -249,10 +249,6 @@ def run( self.logger.info("UQpy: All model evaluations computed successfully.") - ######################### STORAGE ######################## - - # Create dictionary to store the sensitivity indices - computed_indices = {} ################## COMPUTE SOBOL INDICES ################## @@ -267,8 +263,6 @@ def run( self.logger.info("UQpy: First order Sobol indices computed successfully.") - computed_indices["sobol_i"] = self.first_order_indices - # Total order Sobol indices self.total_order_indices = compute_total_order( A_model_evals, @@ -280,8 +274,6 @@ def run( self.logger.info("UQpy: Total order Sobol indices computed successfully.") - computed_indices["sobol_total_i"] = self.total_order_indices - if estimate_second_order: # Second order Sobol indices @@ -290,13 +282,12 @@ def run( B_model_evals, C_i_model_evals, D_i_model_evals, - computed_indices["sobol_i"], + self.first_order_indices, scheme=second_order_scheme, ) self.logger.info("UQpy: Second order Sobol indices computed successfully.") - computed_indices["sobol_ij"] = self.second_order_indices ################## CONFIDENCE INTERVALS #################### @@ -315,7 +306,7 @@ def run( self.first_order_confidence_interval = self.bootstrapping( compute_first_order, estimator_inputs, - computed_indices["sobol_i"], + self.first_order_indices, n_bootstrap_samples, confidence_level, scheme=first_order_scheme, @@ -325,15 +316,11 @@ def run( "UQpy: Confidence intervals for First order Sobol indices computed successfully." ) - computed_indices[ - "confidence_interval_sobol_i" - ] = self.first_order_confidence_interval - # Total order Sobol indices self.total_order_confidence_interval = self.bootstrapping( compute_total_order, estimator_inputs, - computed_indices["sobol_total_i"], + self.total_order_indices, n_bootstrap_samples, confidence_level, scheme=total_order_scheme, @@ -343,19 +330,16 @@ def run( "UQpy: Confidence intervals for Total order Sobol indices computed successfully." ) - computed_indices[ - "confidence_interval_sobol_total_i" - ] = self.total_order_confidence_interval # Second order Sobol indices if estimate_second_order: self.second_order_confidence_interval = self.bootstrapping( compute_second_order, estimator_inputs, - computed_indices["sobol_ij"], + self.second_order_indices, n_bootstrap_samples, confidence_level, - first_order_sobol=computed_indices["sobol_i"], + first_order_sobol=self.first_order_indices, scheme=second_order_scheme, ) @@ -363,12 +347,6 @@ def run( "UQpy: Confidence intervals for Second order Sobol indices computed successfully." ) - computed_indices[ - "confidence_interval_sobol_ij" - ] = self.second_order_confidence_interval - - return computed_indices - ###################### Pick and Freeze Methods #####################