Skip to content

Commit

Permalink
various fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
utsekaj42 committed Sep 7, 2017
1 parent 43376d9 commit 39bf99e
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 202 deletions.
25 changes: 22 additions & 3 deletions exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto1\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"Y = \\sum_i^r \\Omega_i \\; \\mathbf{Z}_i\n",
"\\begin{equation} Y = \\sum_i^r \\Omega_i \\; \\mathbf{Z}_i\n",
" \\tag{1}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -33,9 +36,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto2\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"Z_i \\sim N(0, \\sigma_{Z_i}), \\qquad i=1,2, \\ldots, r \n",
" \\tag{2}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -44,9 +51,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto3\"></div>\n",
"\n",
"$$\n",
"\\begin{equation} \n",
"\\Omega_i = \\textsf{constant} \n",
" \\tag{3}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -62,9 +73,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto4\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"Z_i \\sim N(0, \\sigma_{Z_i}), \\qquad i=1,2, \\ldots, r \n",
" \\tag{4}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -73,9 +88,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto5\"></div>\n",
"\n",
"$$\n",
"\\begin{equation} \n",
"\\Omega_i \\sim N(\\mu_{\\Omega_i}, \\sigma_{\\Omega_i})\n",
" \\tag{5}\n",
"\\end{equation}\n",
"$$"
]
Expand Down Expand Up @@ -105,7 +124,7 @@
"$$\n",
"\\begin{equation}\n",
"S_i = \\frac{\\text{V}_{Z_i}(E_{Z_{\\sim i}} (Y\\;|\\;Z_i))}{\\text{V}(Y)}\n",
"\\label{exeq:Si} \\tag{1}\n",
" \\tag{6}\n",
"\\end{equation}\n",
"$$"
]
Expand Down
5 changes: 3 additions & 2 deletions introduction_chaospy.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
joint_distribution = cp.J(u1, u2)

order = 2
# sparse grid has exponential growth, thus a smaller order results in more points
nodes_clenshaw, weights_clenshaw = cp.generate_quadrature(order=order, domain=joint_distribution, rule='C')
nodes_clenshaw_sparse, weights_clenshaw_sparse = cp.generate_quadrature(order=order, domain=joint_distribution, rule='C', sparse=True)

Expand Down Expand Up @@ -145,7 +146,7 @@
_=plt.xticks([])

poly = cp.orth_ttr(polynomial_order, n, normed=True)
print('Discretized Stieltjes / Thre terms reccursion {}'.format(poly))
print('Discretized Stieltjes / Three terms reccursion {}'.format(poly))
ax = plt.subplot(132)
ax.set_title('Discretized Stieltjes ')
_=plt.plot(x, poly(x).T)
Expand Down Expand Up @@ -174,7 +175,7 @@
poly = cp.orth_ttr(polynomial_order, joint_distribution)

# 3.1 generate samples
number_of_samples = 2*cp.bertran.terms(polynomial_order, len(joint_distribution))
number_of_samples = cp.bertran.terms(polynomial_order, len(joint_distribution))
samples = joint_distribution.sample(size=number_of_samples, rule='R')

# 3.2 evaluate the simple model for all samples
Expand Down
44 changes: 28 additions & 16 deletions introduction_gpc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"<!-- dom:AUTHOR: Jacob Sturdy at Department of Structural Engineering, NTNU -->\n",
"<!-- Author: --> **Jacob Sturdy**, Department of Structural Engineering, NTNU\n",
"\n",
"Date: **Jun 27, 2017**"
"Date: **Sep 7, 2017**"
]
},
{
Expand Down Expand Up @@ -46,7 +46,6 @@
"# import seaborn as sns # sets another style\n",
"matplotlib.rcParams['lines.linewidth'] = 3\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",
Expand Down Expand Up @@ -100,9 +99,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto1\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"Y = y{}(x, t, \\mathbf{Z})\n",
" \\tag{1}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -118,9 +121,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto2\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"Y = y{}(x, t, \\mathbf{Z}) \\approx y_{N} = \\sum_{i=1}^{P} v_i(x, t) \\Phi_i(\\mathbf{Z}),\n",
" \\tag{2}\n",
"\\end{equation}\n",
"$$"
]
Expand Down Expand Up @@ -220,7 +227,7 @@
"y (\\mathbf{z}^{(N)})\n",
"\\end{bmatrix}\n",
"\\end{equation}\n",
"\\label{eq:stochColl} \\tag{1}\n",
" \\tag{3}\n",
"$$"
]
},
Expand All @@ -229,7 +236,7 @@
"metadata": {},
"source": [
"Now we can use regression to achieve the relaxed condition that $y_{N}$ is \"sufficiently close\" to $y$ at $\\left\\{\\mathbf{z}^{(s)}\\right\\}_{s=1}^{P}$.\n",
"This is done by choosing a larger number of samples so that [(1)](#eq:stochColl) is over determined and\n",
"This is done by choosing a larger number of samples so that [(3)](#eq:stochColl) is over determined and\n",
"then minimizing the appropriate error ${\\lvert\\lvert {y_{N} \\rvert\\rvert}-y}_{R}$ over $\\left\\{\\mathbf{z}^{(s)}\\right\\}_{s=1}^{P}$.\n",
"Ordinary least squares, Ridge-Regression, and Tikhonov-Regularization are all regression methods that may be applied to this problem.\n",
"\n",
Expand All @@ -242,9 +249,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto3\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"v_i = \\frac{1}{h_i} \\mathbb{E}(y \\Phi_i) = \\frac{1}{h_i} \\int_{\\Omega} y \\Phi_i dF_z,\n",
" \\tag{4}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -267,8 +278,8 @@
"\n",
"$$\n",
"\\begin{equation}\n",
"{\\lvert\\lvert {y_{N} - y} \\rvert\\rvert} \\leq {\\lvert\\lvert {\\sum_{i=1} \\rvert\\rvert}^{P} v_i \\Phi_i - y{} } + {\\lvert\\lvert {\\sum_{i=1} \\rvert\\rvert}^{P} \\left( v_i - \\tilde{v}_i \\right)\\Phi_i}\n",
"\\label{eq:ps_error} \\tag{2}\n",
"\\lVert{y_{N} - y}\\rVert \\leq \\lVert \\sum_{i=1}^{P} v_i \\Phi_i - y{} \\rVert + \\lVert {\\sum_{i=1}^{P} \\left( v_i - \\tilde{v}_i \\right)\\Phi_i} \\rVert\n",
" \\tag{5}\n",
"\\end{equation}\n",
"$$"
]
Expand Down Expand Up @@ -299,9 +310,9 @@
"$$\n",
"\\begin{equation}\n",
" \\begin{aligned}\n",
" {\\mathbb{E}}(Y) \\approx {\\int_{\\Omega} \\sum_{i=1}^{P} v_i \\Phi_i(\\mathbf{z dF_Z(\\mathbf{z})})} = v_1.\n",
" {\\mathbb{E}}(Y) \\approx \\int_{\\Omega} \\sum_{i=1}^{P} v_i \\Phi_i(\\mathbf{z}{}) dF_Z(\\mathbf{z}) = v_1.\n",
" \\end{aligned}\n",
" \\label{eq:expectedValue_gPCE} \\tag{3}\n",
" \\tag{6}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -327,7 +338,7 @@
" &= \\int_{\\Omega}\\left(\\sum_{i=1}^{P} v_i \\Phi_i(\\mathbf{z}) \\right)^2 dF_Z(\\mathbf{z}) - v_1^2 = \\sum_{i=1}^{P} v_i^2 \\int_{\\Omega}{\\Phi^2_i(\\mathbf{z})}dF_Z(\\mathbf{z}) - v_1^2 \\\\\n",
" &= \\sum_{i=1}^{P} v_i^2 h_i - v_1^2 = \\sum_{i=2}^{P} v_i^2 h_i\n",
" \\end{aligned}\n",
" \\label{eq:variance_gPCE} \\tag{4}\n",
" \\tag{7}\n",
"\\end{equation}\n",
"$$"
]
Expand Down Expand Up @@ -355,7 +366,7 @@
" S_i &= \\frac{1}{\\operatorname{Var}(Y)} \\sum_{k\\in \\mathcal{A}_{i}} \\operatorname{Var}(v_{k} \\Phi_{k}) \\\\\n",
" S_i &= \\frac{1}{\\operatorname{Var}(Y)} \\sum_{k\\in \\mathcal{A}_{i}} v_{k}^2 h_{k} \n",
" \\end{aligned}\n",
" \\label{eq:sensitivity_gPCE} \\tag{5}\n",
" \\tag{8}\n",
"\\end{equation}\n",
"$$"
]
Expand Down Expand Up @@ -622,7 +633,7 @@
"_=plt.xticks([])\n",
"\n",
"poly = cp.orth_ttr(polynomial_order, n, normed=True)\n",
"print('Discretized Stieltjes / Thre terms reccursion {}'.format(poly))\n",
"print('Discretized Stieltjes / Three terms reccursion {}'.format(poly))\n",
"ax = plt.subplot(132)\n",
"ax.set_title('Discretized Stieltjes ')\n",
"_=plt.plot(x, poly(x).T)\n",
Expand Down Expand Up @@ -818,7 +829,7 @@
"$$\n",
"\\begin{equation}\n",
" y(z_1, z_2) = z_1 + z_1 z_2\n",
"\\label{eq:dummy_model} \\tag{6}\n",
" \\tag{9}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -840,7 +851,7 @@
"$$\n",
"\\begin{equation}\n",
"Z_1 = \\mbox{U}(0,1), \\quad Z_2 = \\mbox{U}(0,1)\n",
"\\label{eq:dummy_rv} \\tag{7}\n",
" \\tag{10}\n",
"\\end{equation}\n",
"$$"
]
Expand Down Expand Up @@ -874,7 +885,7 @@
"poly = cp.orth_ttr(polynomial_order, joint_distribution)\n",
"\n",
"# 3.1 generate samples\n",
"number_of_samples = 2*cp.bertran.terms(polynomial_order, len(joint_distribution))\n",
"number_of_samples = cp.bertran.terms(polynomial_order, len(joint_distribution))\n",
"samples = joint_distribution.sample(size=number_of_samples, rule='R')\n",
"\n",
"# 3.2 evaluate the simple model for all samples\n",
Expand Down Expand Up @@ -990,6 +1001,7 @@
"joint_distribution = cp.J(u1, u2)\n",
"\n",
"order = 2\n",
"# sparse grid has exponential growth, thus a smaller order results in more points\n",
"nodes_clenshaw, weights_clenshaw = cp.generate_quadrature(order=order, domain=joint_distribution, rule='C')\n",
"nodes_clenshaw_sparse, weights_clenshaw_sparse = cp.generate_quadrature(order=order, domain=joint_distribution, rule='C', sparse=True)\n",
"\n",
Expand Down Expand Up @@ -1044,7 +1056,7 @@
"$$\n",
"\\begin{equation}\n",
" y(z_1, z_2) = z_1 + z_1 z_2\n",
"\\label{eq:dummy_model_repeat} \\tag{8}\n",
" \\tag{11}\n",
"\\end{equation}\n",
"$$"
]
Expand All @@ -1066,7 +1078,7 @@
"$$\n",
"\\begin{equation}\n",
"Z_1 = \\mbox{U}(0,1), \\quad Z_2 = \\mbox{U}(0,1)\n",
"\\label{eq:dummy_rv_repeat} \\tag{9}\n",
" \\tag{12}\n",
"\\end{equation}\n",
"$$"
]
Expand Down
7 changes: 5 additions & 2 deletions ishigami_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"<!-- dom:AUTHOR: Jacob Sturdy at Department of Structural Engineering, NTNU -->\n",
"<!-- Author: --> **Jacob Sturdy**, Department of Structural Engineering, NTNU\n",
"\n",
"Date: **Jun 27, 2017**"
"Date: **Sep 7, 2017**"
]
},
{
Expand Down Expand Up @@ -43,7 +43,6 @@
"# import seaborn as sns # sets another style\n",
"matplotlib.rcParams['lines.linewidth'] = 3\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",
Expand Down Expand Up @@ -79,9 +78,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- Equation labels as ordinary links -->\n",
"<div id=\"_auto1\"></div>\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"y = \\sin(z_1) + a \\sin^2(z_2) + b z_3^4 \\sin(z_1)\n",
" \\tag{1}\n",
"\\end{equation}\n",
"$$"
]
Expand Down
Loading

0 comments on commit 39bf99e

Please sign in to comment.