Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lrhgit committed Jan 17, 2017
1 parent 4e8c48f commit 2e0416c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions sensitivity_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"<!-- dom:AUTHOR: Leif Rune Hellevik at Department of Structural Engineering, NTNU -->\n",
"<!-- Author: --> **Leif Rune Hellevik**, Department of Structural Engineering, NTNU\n",
"\n",
"Date: **Jan 16, 2017**"
"Date: **Jan 17, 2017**"
]
},
{
Expand All @@ -27,7 +27,7 @@
"%autoreload 2\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import chaospy as pc\n",
"import chaospy as cp\n",
"from numpy import linalg as LA"
]
},
Expand Down Expand Up @@ -315,7 +315,7 @@
"Z=np.zeros(shape=(r,N))\n",
"pdf=[]\n",
"for i, z in enumerate(zm):\n",
" pdf.append(pc.Normal(z[0],z[1]))\n",
" pdf.append(cp.Normal(z[0],z[1]))\n",
" Z[i,:]=pdf[i].sample(N)\n",
"\n",
"Y = linear_model(w,Z,N)\n",
Expand Down Expand Up @@ -558,7 +558,7 @@
"outputs": [],
"source": [
"# Sensitivity indices based on sampled values\n",
"print 'std(Y)=',pc.std(Y, 0), ' rel.err=', (pc.std(Y, 0)-s_y)/s_y\n",
"print 'std(Y)=',np.std(Y, 0), ' rel.err=', (np.std(Y, 0)-s_y)/s_y\n",
"print np.mean(Y,0), np.sqrt(np.var(Y,0))"
]
},
Expand Down Expand Up @@ -902,15 +902,15 @@
"source": [
"# Polychaos computations\n",
"Npc=80\n",
"jpdf = pc.J(pc.Normal(zm[0,0],zm[0,1]),pc.Normal(zm[1,0],zm[1,1]),pc.Normal(zm[2,0],zm[2,1]),pc.Normal(zm[3,0],zm[3,1]))\n",
"jpdf = cp.J(cp.Normal(zm[0,0],zm[0,1]),cp.Normal(zm[1,0],zm[1,1]),cp.Normal(zm[2,0],zm[2,1]),cp.Normal(zm[3,0],zm[3,1]))\n",
"Zpc=jpdf.sample(Npc)\n",
"Ypc=linear_model(w, Zpc, Npc)\n",
"Npol=4\n",
"poly = pc.orth_chol(Npol, jpdf)\n",
"approx = pc.fit_regression(poly, Zpc, Ypc, rule=\"T\")\n",
"poly = cp.orth_chol(Npol, jpdf)\n",
"approx = cp.fit_regression(poly, Zpc, Ypc, rule=\"T\")\n",
"\n",
"print 'Expected value from pc=', pc.E(approx,jpdf), ' std=',pc.Std(approx,jpdf)\n",
"s_pc= pc.Sens_m(approx,jpdf)\n",
"print 'Expected value from cp=', cp.E(approx,jpdf), ' std=',cp.Std(approx,jpdf)\n",
"s_pc= cp.Sens_m(approx,jpdf)\n",
"print 'Sensitivity indices from polychaos', s_pc\n",
"print 'rel err', (s_pc-s**2)/s**2"
]
Expand All @@ -931,9 +931,9 @@
" Zpc=jpdf.sample(Npc)\n",
" Ypc=linear_model(w, Zpc, Npc)\n",
" Npol=4\n",
" poly = pc.orth_chol(Npol, jpdf)\n",
" approx = pc.fit_regression(poly, Zpc, Ypc, rule=\"T\")\n",
" s_pc= pc.Sens_m(approx,jpdf)\n",
" poly = cp.orth_chol(Npol, jpdf)\n",
" approx = cp.fit_regression(poly, Zpc, Ypc, rule=\"T\")\n",
" s_pc= cp.Sens_m(approx,jpdf)\n",
" error.append(LA.norm((s_pc-s**2)/s**2))\n",
" \n",
"plt.figure()\n",
Expand Down

0 comments on commit 2e0416c

Please sign in to comment.