Skip to content

Commit

Permalink
updated sensitivity intro notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
utsekaj42 committed Jun 27, 2017
1 parent 51a6b4f commit e95ed85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
7 changes: 2 additions & 5 deletions sensitivity_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import pandas as pd
from _operator import index

cp.Sens_m

# start the linear model
def linear_model(w, z):
return np.sum(w*z, axis=1)
Expand Down Expand Up @@ -68,8 +66,7 @@ def evaluate_linear_model(A, B, C, w):
# Set mean (column 0) and standard deviations (column 1) for each factor z. Nrv=nr. rows
Nrv = 4 # number of random variables
zm = np.array([[0., i] for i in range(1, Nrv + 1)])

# TODO: LR decide if the following lines should be kept
# The above "list comprehension" is equivalent to thenext four lines
# zm = np.zeros((Nrv, 2))
# zm[0, 1] = 1
# zm[1, 1] = 2
Expand Down Expand Up @@ -113,7 +110,7 @@ def evaluate_linear_model(A, B, C, w):

print("\nTheoretical sensitivity indices\n")
row_labels= ['S_'+str(idx) for idx in range(1,Nrv+1)]
print(pd.DataFrame(s**2, columns=['S anal'],index=row_labels).round(3))
print(pd.DataFrame(s**2, columns=['S analytic'],index=row_labels).round(3))


# Expectation and variance from sampled values
Expand Down
21 changes: 10 additions & 11 deletions sensitivity_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"plt.style.use(\"ggplot\")\n",
"# import seaborn as sns # sets another style\n",
"matplotlib.rcParams['lines.linewidth'] = 3\n",
"matplotlib.rcParams['figure.figsize'] = (7.0,5.0)\n",
"fig_width, fig_height = (7.0,5.0)\n",
"\n",
"matplotlib.rcParams['figure.figsize'] = (fig_width, fig_height)\n",
"\n",
"# font = {'family' : 'sans-serif',\n",
"# 'weight' : 'normal',\n",
Expand All @@ -66,9 +68,7 @@
"from monte_carlo import generate_sample_matrices_mc\n",
"from monte_carlo import calculate_sensitivity_indices_mc\n",
"import pandas as pd\n",
"from _operator import index\n",
"\n",
"cp.Sens_m"
"from _operator import index"
]
},
{
Expand Down Expand Up @@ -225,8 +225,7 @@
" # Set mean (column 0) and standard deviations (column 1) for each factor z. Nrv=nr. rows\n",
" Nrv = 4 # number of random variables \n",
" zm = np.array([[0., i] for i in range(1, Nrv + 1)])\n",
"\n",
" # TODO: LR decide if the following lines should be kept\n",
" # The above \"list comprehension\" is equivalent to thenext four lines \n",
" # zm = np.zeros((Nrv, 2))\n",
" # zm[0, 1] = 1\n",
" # zm[1, 1] = 2\n",
Expand Down Expand Up @@ -340,8 +339,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the assumption of independent factors $Z_i$, we may sample\n",
"each $Z_i$ independently from their marginal distributions and store\n",
"Note that the assumption of independent factors $Z_i$ allows us to sample\n",
"each $Z_i$ independently from its own marginal distribution. We store\n",
"all the samples for all the factors $Z_i$ in the the numpy array\n",
"`Z[i,:]`, where $i$ corresponds to $Z_i$ as:"
]
Expand Down Expand Up @@ -487,7 +486,7 @@
"\n",
"$$\n",
"\\begin{equation}\n",
" \\sigma_Y^2 = \\sum_{i=1}^{r} \\left(\\Omega_i^2 \\, \\sigma_{Z_i}\\right)^2\n",
" \\sigma_Y^2 = \\sum_{i=1}^{r} \\left(\\Omega_i \\, \\sigma_{Z_i}\\right)^2\n",
" \\label{eq:Ss_model_ded} \\tag{10}\n",
"\\end{equation}\n",
"$$"
Expand Down Expand Up @@ -541,7 +540,7 @@
" \n",
" print(\"\\nTheoretical sensitivity indices\\n\")\n",
" row_labels= ['S_'+str(idx) for idx in range(1,Nrv+1)]\n",
" print(pd.DataFrame(s**2, columns=['S anal'],index=row_labels).round(3))"
" print(pd.DataFrame(s**2, columns=['S analytic'],index=row_labels).round(3))"
]
},
{
Expand Down Expand Up @@ -689,7 +688,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Further, the variance the output $Y$ may be decomposed into:"
"Further, the variance of the output $Y$ may be decomposed into:"
]
},
{
Expand Down

0 comments on commit e95ed85

Please sign in to comment.