Skip to content

Commit

Permalink
manual update to notebook collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcky committed Jul 26, 2019
1 parent aa30b71 commit 0e29c79
Show file tree
Hide file tree
Showing 90 changed files with 17,221 additions and 33,542 deletions.
334 changes: 98 additions & 236 deletions about_py.ipynb

Large diffs are not rendered by default.

356 changes: 130 additions & 226 deletions additive_functionals.ipynb

Large diffs are not rendered by default.

143 changes: 57 additions & 86 deletions aiyagari.ipynb

Large diffs are not rendered by default.

1,151 changes: 144 additions & 1,007 deletions amss.ipynb

Large diffs are not rendered by default.

1,589 changes: 181 additions & 1,408 deletions amss2.ipynb

Large diffs are not rendered by default.

1,632 changes: 156 additions & 1,476 deletions amss3.ipynb

Large diffs are not rendered by default.

374 changes: 102 additions & 272 deletions arellano.ipynb

Large diffs are not rendered by default.

534 changes: 160 additions & 374 deletions arma.ipynb

Large diffs are not rendered by default.

435 changes: 166 additions & 269 deletions black_litterman.ipynb

Large diffs are not rendered by default.

567 changes: 212 additions & 355 deletions calvo.ipynb

Large diffs are not rendered by default.

212 changes: 62 additions & 150 deletions career.ipynb

Large diffs are not rendered by default.

836 changes: 261 additions & 575 deletions cass_koopmans.ipynb

Large diffs are not rendered by default.

210 changes: 71 additions & 139 deletions cattle_cycles.ipynb

Large diffs are not rendered by default.

871 changes: 181 additions & 690 deletions chang_credible.ipynb

Large diffs are not rendered by default.

1,088 changes: 230 additions & 858 deletions chang_ramsey.ipynb

Large diffs are not rendered by default.

493 changes: 170 additions & 323 deletions classical_filtering.ipynb

Large diffs are not rendered by default.

870 changes: 870 additions & 0 deletions coase.ipynb

Large diffs are not rendered by default.

389 changes: 138 additions & 251 deletions coleman_policy_iter.ipynb

Large diffs are not rendered by default.

227 changes: 54 additions & 173 deletions complex_and_trig.ipynb

Large diffs are not rendered by default.

149 changes: 31 additions & 118 deletions debugging.ipynb

Large diffs are not rendered by default.

746 changes: 211 additions & 535 deletions discrete_dp.ipynb

Large diffs are not rendered by default.

764 changes: 228 additions & 536 deletions dyn_stack.ipynb

Large diffs are not rendered by default.

228 changes: 73 additions & 155 deletions egm_policy_iter.ipynb

Large diffs are not rendered by default.

296 changes: 104 additions & 192 deletions estspec.ipynb

Large diffs are not rendered by default.

736 changes: 232 additions & 504 deletions finite_markov.ipynb

Large diffs are not rendered by default.

1,169 changes: 1,169 additions & 0 deletions geom_series.ipynb

Large diffs are not rendered by default.

349 changes: 156 additions & 193 deletions getting_started.ipynb

Large diffs are not rendered by default.

347 changes: 96 additions & 251 deletions growth_in_dles.ipynb

Large diffs are not rendered by default.

317 changes: 117 additions & 200 deletions harrison_kreps.ipynb

Large diffs are not rendered by default.

209 changes: 85 additions & 124 deletions hs_invertibility_example.ipynb

Large diffs are not rendered by default.

767 changes: 369 additions & 398 deletions hs_recursive_models.ipynb

Large diffs are not rendered by default.

294 changes: 97 additions & 197 deletions ifp.ipynb

Large diffs are not rendered by default.

217 changes: 54 additions & 163 deletions irfs_in_hall_model.ipynb

Large diffs are not rendered by default.

255 changes: 73 additions & 182 deletions jv.ipynb

Large diffs are not rendered by default.

402 changes: 148 additions & 254 deletions kalman.ipynb

Large diffs are not rendered by default.

477 changes: 146 additions & 331 deletions lake_model.ipynb

Large diffs are not rendered by default.

856 changes: 276 additions & 580 deletions linear_algebra.ipynb

Large diffs are not rendered by default.

438 changes: 187 additions & 251 deletions linear_models.ipynb

Large diffs are not rendered by default.

393 changes: 138 additions & 255 deletions lln_clt.ipynb

Large diffs are not rendered by default.

546 changes: 236 additions & 310 deletions lqcontrol.ipynb

Large diffs are not rendered by default.

344 changes: 127 additions & 217 deletions lqramsey.ipynb

Large diffs are not rendered by default.

353 changes: 151 additions & 202 deletions lu_tricks.ipynb

Large diffs are not rendered by default.

173 changes: 36 additions & 137 deletions lucas_asset_pricing_dles.ipynb

Large diffs are not rendered by default.

250 changes: 106 additions & 144 deletions lucas_model.ipynb

Large diffs are not rendered by default.

435 changes: 155 additions & 280 deletions markov_asset.ipynb

Large diffs are not rendered by default.

1,293 changes: 1,293 additions & 0 deletions markov_jump_lq.ipynb

Large diffs are not rendered by default.

340 changes: 120 additions & 220 deletions markov_perf.ipynb

Large diffs are not rendered by default.

273 changes: 59 additions & 214 deletions matplotlib.ipynb

Large diffs are not rendered by default.

241 changes: 95 additions & 146 deletions matsuyama.ipynb

Large diffs are not rendered by default.

265 changes: 95 additions & 170 deletions mccall_model.ipynb

Large diffs are not rendered by default.

308 changes: 109 additions & 199 deletions mccall_model_with_separation.ipynb

Large diffs are not rendered by default.

737 changes: 144 additions & 593 deletions mle.ipynb

Large diffs are not rendered by default.

428 changes: 122 additions & 306 deletions multiplicative_functionals.ipynb

Large diffs are not rendered by default.

312 changes: 117 additions & 195 deletions muth_kalman.ipynb

Large diffs are not rendered by default.

558 changes: 153 additions & 405 deletions numba.ipynb

Large diffs are not rendered by default.

1,502 changes: 267 additions & 1,235 deletions numpy.ipynb

Large diffs are not rendered by default.

318 changes: 86 additions & 232 deletions odu.ipynb

Large diffs are not rendered by default.

750 changes: 151 additions & 599 deletions ols.ipynb

Large diffs are not rendered by default.

447 changes: 85 additions & 362 deletions oop_intro.ipynb

Large diffs are not rendered by default.

604 changes: 259 additions & 345 deletions opt_tax_recur.ipynb

Large diffs are not rendered by default.

466 changes: 174 additions & 292 deletions optgrowth.ipynb

Large diffs are not rendered by default.

315 changes: 122 additions & 193 deletions orth_proj.ipynb

Large diffs are not rendered by default.

1,645 changes: 112 additions & 1,533 deletions pandas.ipynb

Large diffs are not rendered by default.

2,809 changes: 140 additions & 2,669 deletions pandas_panel.ipynb

Large diffs are not rendered by default.

373 changes: 146 additions & 227 deletions perm_income.ipynb

Large diffs are not rendered by default.

473 changes: 150 additions & 323 deletions perm_income_cons.ipynb

Large diffs are not rendered by default.

148 changes: 55 additions & 93 deletions permanent_income_dles.ipynb

Large diffs are not rendered by default.

1,940 changes: 411 additions & 1,529 deletions python_advanced_features.ipynb

Large diffs are not rendered by default.

775 changes: 200 additions & 575 deletions python_by_example.ipynb

Large diffs are not rendered by default.

1,312 changes: 262 additions & 1,050 deletions python_essentials.ipynb

Large diffs are not rendered by default.

536 changes: 144 additions & 392 deletions python_oop.ipynb

Large diffs are not rendered by default.

391 changes: 156 additions & 235 deletions rational_expectations.ipynb

Large diffs are not rendered by default.

358 changes: 132 additions & 226 deletions rob_markov_perf.ipynb

Large diffs are not rendered by default.

360 changes: 160 additions & 200 deletions robustness.ipynb

Large diffs are not rendered by default.

191 changes: 71 additions & 120 deletions rosen_schooling_model.ipynb

Large diffs are not rendered by default.

894 changes: 193 additions & 701 deletions samuelson.ipynb

Large diffs are not rendered by default.

188 changes: 46 additions & 142 deletions schelling.ipynb

Large diffs are not rendered by default.

488 changes: 117 additions & 371 deletions sci_libs.ipynb

Large diffs are not rendered by default.

487 changes: 119 additions & 368 deletions scipy.ipynb

Large diffs are not rendered by default.

119 changes: 33 additions & 86 deletions short_path.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
" - [Overview](#Overview) \n",
" - [Outline of the Problem](#Outline-of-the-Problem) \n",
" - [Finding Least-Cost Paths](#Finding-Least-Cost-Paths) \n",
" - [Solving for $ J $](#Solving-for-$-J-$) \n",
" - [Solving for Minimum Cost-to-Go](#Solving-for-Minimum-Cost-to-Go) \n",
" - [Exercises](#Exercises) \n",
" - [Solutions](#Solutions) "
]
Expand All @@ -59,9 +59,9 @@
"- routing packets on the internet \n",
"\n",
"\n",
"For us, the shortest path problem also provides a nice introduction to the logic of **dynamic programming**\n",
"For us, the shortest path problem also provides a nice introduction to the logic of **dynamic programming**.\n",
"\n",
"Dynamic programming is an extremely powerful optimization technique that we apply in many lectures on this site"
"Dynamic programming is an extremely powerful optimization technique that we apply in many lectures on this site."
]
},
{
Expand All @@ -70,23 +70,23 @@
"source": [
"## Outline of the Problem\n",
"\n",
"The shortest path problem is one of finding how to traverse a [graph](https://en.wikipedia.org/wiki/Graph_%28mathematics%29) from one specified node to another at minimum cost\n",
"The shortest path problem is one of finding how to traverse a [graph](https://en.wikipedia.org/wiki/Graph_%28mathematics%29) from one specified node to another at minimum cost.\n",
"\n",
"Consider the following graph\n",
"\n",
"<img src=\"https://s3-ap-southeast-2.amazonaws.com/lectures.quantecon.org/py/_static/figures/graph.png\" style=\"width:100%;height:100%\">\n",
"<img src=\"_static/lecture_specific/short_path/graph.png\" style=\"\">\n",
"\n",
" \n",
"We wish to travel from node (vertex) A to node G at minimum cost\n",
"\n",
"- Arrows (edges) indicate the movements we can take \n",
"- Numbers on edges indicate the cost of traveling that edge \n",
"- Arrows (edges) indicate the movements we can take. \n",
"- Numbers on edges indicate the cost of traveling that edge. \n",
"\n",
"\n",
"Possible interpretations of the graph include\n",
"\n",
"- Minimum cost for supplier to reach a destination \n",
"- Routing of packets on the internet (minimize time) \n",
"- Minimum cost for supplier to reach a destination. \n",
"- Routing of packets on the internet (minimize time). \n",
"- Etc., etc. \n",
"\n",
"\n",
Expand All @@ -95,13 +95,13 @@
"- A, C, F, G at cost 8 \n",
"\n",
"\n",
"<img src=\"https://s3-ap-southeast-2.amazonaws.com/lectures.quantecon.org/py/_static/figures/graph4.png\" style=\"width:100%;height:100%\">\n",
"<img src=\"_static/lecture_specific/short_path/graph4.png\" style=\"\">\n",
"\n",
" \n",
"- A, D, F, G at cost 8 \n",
"\n",
"\n",
"<img src=\"https://s3-ap-southeast-2.amazonaws.com/lectures.quantecon.org/py/_static/figures/graph3.png\" style=\"width:100%;height:100%\">"
"<img src=\"_static/lecture_specific/short_path/graph3.png\" style=\"\">"
]
},
{
Expand All @@ -110,16 +110,16 @@
"source": [
"## Finding Least-Cost Paths\n",
"\n",
"For large graphs we need a systematic solution\n",
"For large graphs, we need a systematic solution.\n",
"\n",
"Let $ J(v) $ denote the minimum cost-to-go from node $ v $, understood as the total cost from $ v $ if we take the best route\n",
"Let $ J(v) $ denote the minimum cost-to-go from node $ v $, understood as the total cost from $ v $ if we take the best route.\n",
"\n",
"Suppose that we know $ J(v) $ for each node $ v $, as shown below for the graph from the preceding example\n",
"\n",
"<img src=\"https://s3-ap-southeast-2.amazonaws.com/lectures.quantecon.org/py/_static/figures/graph2.png\" style=\"width:100%;height:100%\">\n",
"<img src=\"_static/lecture_specific/short_path/graph2.png\" style=\"\">\n",
"\n",
" \n",
"Note that $ J(G) = 0 $\n",
"Note that $ J(G) = 0 $.\n",
"\n",
"The best path can now be found as follows\n",
"\n",
Expand All @@ -135,11 +135,11 @@
"\n",
"where\n",
"\n",
"- $ F_v $ is the set of nodes that can be reached from $ v $ in one step \n",
"- $ c(v, w) $ is the cost of traveling from $ v $ to $ w $ \n",
"- $ F_v $ is the set of nodes that can be reached from $ v $ in one step. \n",
"- $ c(v, w) $ is the cost of traveling from $ v $ to $ w $. \n",
"\n",
"\n",
"Hence, if we know the function $ J $, then finding the best path is almost trivial\n",
"Hence, if we know the function $ J $, then finding the best path is almost trivial.\n",
"\n",
"But how to find $ J $?\n",
"\n",
Expand All @@ -152,14 +152,14 @@
"J(v) = \\min_{w \\in F_v} \\{ c(v, w) + J(w) \\} \\tag{2}\n",
"$$\n",
"\n",
"This is known as the *Bellman equation*, after the mathematician Richard Bellman"
"This is known as the *Bellman equation*, after the mathematician Richard Bellman."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solving for $ J $\n",
"## Solving for Minimum Cost-to-Go\n",
"\n",
"The standard algorithm for finding $ J $ is to start with\n",
"\n",
Expand All @@ -169,7 +169,7 @@
"J_0(v) = M \\text{ if } v \\not= \\text{ destination, else } J_0(v) = 0 \\tag{3}\n",
"$$\n",
"\n",
"where $ M $ is some large number\n",
"where $ M $ is some large number.\n",
"\n",
"Now we use the following algorithm\n",
"\n",
Expand All @@ -178,7 +178,7 @@
"1. If $ J_{n+1} $ and $ J_n $ are not equal then increment $ n $, go to 2 \n",
"\n",
"\n",
"In general, this sequence converges to $ J $—the proof is omitted"
"In general, this sequence converges to $ J $—the proof is omitted."
]
},
{
Expand All @@ -198,27 +198,19 @@
"### Exercise 1\n",
"\n",
"Use the algorithm given above to find the optimal path (and its cost) for the\n",
"following graph\n",
"following graph.\n",
"\n",
"You can put it in a Jupyter notebook cell and hit Shift-Enter — it\n",
"will be saved in the local directory as file graph.txt"
"will be saved in the local directory as file graph.txt."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing graph.txt\n"
]
}
],
"outputs": [],
"source": [
"%%file graph.txt\n",
"node0, node1 0.04, node8 11.11, node14 72.21\n",
Expand Down Expand Up @@ -334,11 +326,11 @@
"- node14 at cost 72.21 \n",
"\n",
"\n",
"and so on\n",
"and so on.\n",
"\n",
"According to our calculations, the optimal path and its cost are like [this](https://github.com/QuantEcon/QuantEcon.lectures.code/blob/master/short_path/graph_out.txt)\n",
"According to our calculations, the optimal path and its cost are like [this](https://github.com/QuantEcon/QuantEcon.lectures.code/blob/master/short_path/graph_out.txt).\n",
"\n",
"Your code should replicate this result"
"Your code should replicate this result."
]
},
{
Expand All @@ -357,48 +349,15 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"node0\n",
"node8\n",
"node11\n",
"node18\n",
"node23\n",
"node33\n",
"node41\n",
"node53\n",
"node56\n",
"node57\n",
"node60\n",
"node67\n",
"node70\n",
"node73\n",
"node76\n",
"node85\n",
"node87\n",
"node88\n",
"node93\n",
"node94\n",
"node96\n",
"node97\n",
"node98\n",
"node99\n",
"\n",
"Cost: 160.55000000000007\n"
]
}
],
"outputs": [],
"source": [
"def read_graph(in_file):\n",
" \"\"\" Read in the graph from the data file. The graph is stored\n",
" as a dictionary, where the keys are the nodes, and the values\n",
" as a dictionary, where the keys are the nodes and the values\n",
" are a list of pairs (d, c), where d is a node and c is a number.\n",
" If (d, c) is in the list for node n, then d can be reached from\n",
" n at cost c.\n",
Expand Down Expand Up @@ -477,20 +436,8 @@
"language": "python3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
},
"title": "Shortest Paths"
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading

0 comments on commit 0e29c79

Please sign in to comment.