├── README.md
├── assignment
├── .ipynb_checkpoints
│ ├── js_python_solution-checkpoint.ipynb
│ └── solution_notebook-checkpoint.ipynb
├── assignment.aux
├── assignment.fdb_latexmk
├── assignment.fls
├── assignment.log
├── assignment.pdf
├── assignment.synctex.gz
└── assignment.tex
├── ch_1.pdf
├── ch_2.pdf
├── ch_3.pdf
├── ch_4.pdf
├── ch_5.pdf
├── ch_6.pdf
├── ch_7.pdf
├── dp.pdf
├── notebooks
├── exit_exercise
│ ├── .ipynb_checkpoints
│ │ ├── firm_exit-checkpoint.ipynb
│ │ └── firm_exit_solution-checkpoint.ipynb
│ ├── firm_exit.ipynb
│ └── firm_exit_solution.ipynb
├── hiring_ex
│ ├── .ipynb_checkpoints
│ │ └── firm_hiring-checkpoint.ipynb
│ ├── firm_hiring.ipynb
│ └── firm_hiring_solution.ipynb
├── intro_to_python
│ ├── 01_getting_started.ipynb
│ ├── 02_python_by_example.ipynb
│ ├── 03_functions.ipynb
│ ├── 04_python_essentials.ipynb
│ ├── 05_need_for_speed.ipynb
│ ├── 06_numpy.ipynb
│ ├── 07_scipy.ipynb
│ ├── 08_writing_good_code.ipynb
│ ├── 09_numba.ipynb
│ ├── 10_parallelization.ipynb
│ ├── 11_ar1_processes.ipynb
│ ├── lecture_1.pdf
│ ├── md_source_files
│ │ ├── 01_getting_started.md
│ │ ├── 02_python_by_example.md
│ │ ├── 03_functions.md
│ │ ├── 04_python_essentials.md
│ │ ├── 05_need_for_speed.md
│ │ ├── 06_numpy.md
│ │ ├── 07_scipy.md
│ │ ├── 08_writing_good_code.md
│ │ ├── 09_numba.md
│ │ ├── 10_parallelization.md
│ │ └── 11_ar1_processes.md
│ └── tex_source_files
│ │ ├── _minted-lecture1
│ │ ├── 2A20D064E5B48BE32BA789F4D5876813C3FF684A43DD05DB942AAFE1D7B2E81C.pygtex
│ │ ├── 338FAB092F754A86073BB22A33F6852138A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex
│ │ ├── 6FB4CCF74C7BDCAEFF65CF0C90E0A25FD0A1E07ECC8EA949162E2D5A763F202A.pygtex
│ │ ├── B2741080E8A5EB900163B849C77D51A838A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex
│ │ ├── C489745F93B72AC9F19D2216C755D0F138A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex
│ │ ├── E96D923064AB1C3D7D66F328B0305D8638A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex
│ │ ├── default-pyg-prefix.pygstyle
│ │ └── friendly.pygstyle
│ │ ├── _minted-lecture_1
│ │ ├── 2A20D064E5B48BE32BA789F4D587681385D0BD28A1E4792CF3121F1259CE2057.pygtex
│ │ ├── 338FAB092F754A86073BB22A33F6852184A9A22770301CD7D1F5723F317C5665.pygtex
│ │ ├── 6FB4CCF74C7BDCAEFF65CF0C90E0A25F0B89A0F046740D7F88D4B07B9BED7A06.pygtex
│ │ ├── B2741080E8A5EB900163B849C77D51A884A9A22770301CD7D1F5723F317C5665.pygtex
│ │ ├── C489745F93B72AC9F19D2216C755D0F184A9A22770301CD7D1F5723F317C5665.pygtex
│ │ ├── E96D923064AB1C3D7D66F328B0305D8684A9A22770301CD7D1F5723F317C5665.pygtex
│ │ ├── default-pyg-prefix.pygstyle
│ │ └── friendly.pygstyle
│ │ ├── brute_force_1.png
│ │ ├── brute_force_2.png
│ │ ├── brute_force_3.png
│ │ ├── brute_force_4.png
│ │ ├── dual_core.png
│ │ ├── gpu.jpg
│ │ ├── lecture_1.aux
│ │ ├── lecture_1.fdb_latexmk
│ │ ├── lecture_1.fls
│ │ ├── lecture_1.log
│ │ ├── lecture_1.nav
│ │ ├── lecture_1.out
│ │ ├── lecture_1.pdf
│ │ ├── lecture_1.snm
│ │ ├── lecture_1.synctex.gz
│ │ ├── lecture_1.tex
│ │ ├── lecture_1.toc
│ │ ├── lecture_1.vrb
│ │ ├── processor_clock.png
│ │ ├── sp1.png
│ │ ├── sp2.png
│ │ ├── tradeoff.fig
│ │ ├── tradeoff.pdf
│ │ ├── tradeoff2.fig
│ │ ├── tradeoff2.fig.bak
│ │ ├── tradeoff2.pdf
│ │ ├── tradeoff3.fig
│ │ ├── tradeoff3.fig.bak
│ │ ├── tradeoff3.pdf
│ │ ├── tradeoff4.fig
│ │ ├── tradeoff4.fig.bak
│ │ └── tradeoff4.pdf
├── js_beta_exercise
│ ├── .ipynb_checkpoints
│ │ ├── js_julia-checkpoint.ipynb
│ │ ├── js_julia_solution-checkpoint.ipynb
│ │ ├── js_python-checkpoint.ipynb
│ │ ├── js_python_exercise-checkpoint.ipynb
│ │ └── js_python_solution-checkpoint.ipynb
│ ├── js_julia_solution.ipynb
│ ├── js_python_exercise.ipynb
│ └── js_python_solution.ipynb
└── sim_ss_ex
│ ├── .ipynb_checkpoints
│ └── inventory_sim-checkpoint.ipynb
│ ├── inventory_sim.ipynb
│ └── inventory_sim_solution.ipynb
└── review.pdf
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # An Introduction to Computational Macroeconomics (Tokyo 2022)
3 |
4 | * Lecturer: John Stachurski
5 | * Lecture times: Wednesdays 3 and 4 periods (13:00-16:40).
6 | * Start date: 8/6/2022
7 |
8 | ## Overview
9 |
10 | This course provides a short but fast-moving introduction to computational
11 | modeling in macroeconomics and finance. Topics include numerical methods and
12 | their application to workhorse models in macroeconomics, such as Markov
13 | chains, asset pricing problems and dynamic programming.
14 |
15 | ## Notifications
16 |
17 | This is the course homepage. Any new information or resources for the course
18 | will be posted below. Please check this page at least once per week.
19 |
20 | ## Topics
21 |
22 | 1. Scientific programming in Python
23 | 2. Foundations of numerical methods
24 | 3. Job search
25 | 4. Fixed point theory in vector space
26 | 5. Finite Markov chains
27 | 6. Finite Markov decision processes
28 | 7. Applications: optimal savings and investment
29 | 8. Recursive decision processes
30 | 9. Recursive preferences
31 | 10. State-dependent dynamic programming
32 | 11. Optimal savings in a general setting
33 | 12. Euler equation methods
34 |
35 | ## Resources
36 |
37 | Primary source material:
38 |
39 | * Dynamic Programming: Volume 1 (John Stachurski and Thomas J. Sargent)
40 | available [here](https://github.com/jstac/tokyo_2022_coursework/raw/main/dp.pdf).
41 |
42 | Warning: These notes are still being edited! Please print sections
43 | sequentially throughout the course, rather than all at once.
44 |
45 | Secondary reading material:
46 |
47 | * [Abstract dynamic programming](https://web.mit.edu/dimitrib/www/AbstractDP_ED3_TEXT_2021.pdf) by Dimitri Bertsekas
48 |
49 | Programming resources:
50 |
51 | * [QuantEcon Python programming lectures](https://python-programming.quantecon.org/intro.html)
52 | * [QuantEcon economics lectures](https://python.quantecon.org/intro.html)
53 | * [Google colab](https://colab.research.google.com/)
54 |
55 | ## Assessment
56 |
57 | 1. One programming assignment
58 | 2. One exam at the end of the course
59 |
60 |
--------------------------------------------------------------------------------
/assignment/assignment.aux:
--------------------------------------------------------------------------------
1 | \relax
2 | \newlabel{eq:dp}{{1}{2}}
3 | \gdef \@abspage@last{3}
4 |
--------------------------------------------------------------------------------
/assignment/assignment.fdb_latexmk:
--------------------------------------------------------------------------------
1 | # Fdb version 3
2 | ["pdflatex"] 1656466410 "assignment.tex" "assignment.pdf" "assignment" 1656466410
3 | "/etc/texmf/web2c/texmf.cnf" 1646895051 475 c0e671620eb5563b2130f56340a5fde8 ""
4 | "/usr/share/texlive/texmf-dist/fonts/map/fontname/texfonts.map" 1577235249 3524 cb3e574dea2d1052e39280babc910dc8 ""
5 | "/usr/share/texlive/texmf-dist/fonts/tfm/adobe/palatino/pplb8t.tfm" 1136768653 3456 16dd534f88eb2bd21ebc7203786b436e ""
6 | "/usr/share/texlive/texmf-dist/fonts/tfm/adobe/palatino/pplr7t.tfm" 1136768653 1804 7b5f73028f6509167f47ace9d69509ed ""
7 | "/usr/share/texlive/texmf-dist/fonts/tfm/adobe/palatino/pplr8c.tfm" 1136768653 1348 0e8eb69b4437626c0f6c9bed4a4e373c ""
8 | "/usr/share/texlive/texmf-dist/fonts/tfm/adobe/palatino/pplr8t.tfm" 1136768653 3820 ee5b9d58608ae328e43c6e2bfd4ff851 ""
9 | "/usr/share/texlive/texmf-dist/fonts/tfm/adobe/palatino/pplrc8t.tfm" 1136768653 6396 8f2d6400481d3b17b3e6693d0adfe2c9 ""
10 | "/usr/share/texlive/texmf-dist/fonts/tfm/adobe/palatino/pplri8t.tfm" 1136768653 3684 929c666381f7272e81481908b735ccba ""
11 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msam10.tfm" 1246382020 916 f87d7c45f9c908e672703b83b72241a3 ""
12 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msbm10.tfm" 1246382020 908 2921f8a10601f252058503cc6570e581 ""
13 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/bbm/bbm12.tfm" 1227036886 556 710091e9bfd7488f1b5667243215698b ""
14 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/bbm/bbm7.tfm" 1227036886 560 ab71d518408103034050efd8ebc8a16a ""
15 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/bbm/bbm9.tfm" 1227036886 564 538e51111886634ef38425dfff2e2694 ""
16 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmss12.tfm" 1136768653 1324 37b971caf729d7edd9cbb9f9b0ea76eb ""
17 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmss8.tfm" 1136768653 1296 d77f431d10d47c8ea2cc18cf45346274 ""
18 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmss9.tfm" 1136768653 1320 49357c421c0d469f88b867dd0c3d10e8 ""
19 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/mathpazo/zplmr7m.tfm" 1136768653 2080 40a71f65088bdd047622ce295520749e ""
20 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/mathpazo/zplmr7t.tfm" 1136768653 1828 bb8add3bd19426549f9267c88b0cb8bd ""
21 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/mathpazo/zplmr7v.tfm" 1136768653 1012 955c4ca523d7827d33db91a33412b048 ""
22 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/mathpazo/zplmr7y.tfm" 1136768653 1316 b4037e9c09961a72f8476628774e1ec1 ""
23 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/rsfs/rsfs10.tfm" 1229303445 688 37338d6ab346c2f1466b29e195316aa4 ""
24 | "/usr/share/texlive/texmf-dist/fonts/tfm/public/rsfs/rsfs7.tfm" 1229303445 692 1b6510779f0f05e9cbf03e0f6c8361e6 ""
25 | "/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty" 1591045760 12594 0d51ac3a545aaaa555021326ff22a6cc ""
26 | "/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty" 1359763108 5949 3f3fd50a8cc94c3d4cbf4fc66cd3df1c ""
27 | "/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty" 1359763108 13829 94730e64147574077f8ecfea9bb69af4 ""
28 | "/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty" 1523134290 2211 ca7ce284ab93c8eecdc6029dc5ccbd73 ""
29 | "/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty" 1523134290 4161 7f6eb9092061a11f87d08ed13515b48d ""
30 | "/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty" 1601675358 87353 2c21ff5f2e32e1bf714e600924d810db ""
31 | "/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty" 1523134290 4116 32e6abd27229755a83a8b7f18e583890 ""
32 | "/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty" 1523134290 2432 8ff93b1137020e8f21930562a874ae66 ""
33 | "/usr/share/texlive/texmf-dist/tex/latex/base/article.cls" 1601675358 20145 aad8c3dd3bc36e260347b84002182bc2 ""
34 | "/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty" 1601675358 4947 8cb7717f0cc771eca0fda15160c7fee9 ""
35 | "/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty" 1601675358 5050 0d3b77275060ca09a40635b830c3c904 ""
36 | "/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo" 1601675358 8450 6fd3588c0e9d06f6f56c6cf4f7246466 ""
37 | "/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd" 1580683321 2431 b6cead9f069ed55f4fba0c637aa047b6 ""
38 | "/usr/share/texlive/texmf-dist/tex/latex/bbm-macros/bbm.sty" 1191314257 1644 1e0d54b051369c3f457872824cac219f ""
39 | "/usr/share/texlive/texmf-dist/tex/latex/bbm-macros/ubbm.fd" 1191314257 2132 62f898e14cad3357133b5cbf57b61c0a ""
40 | "/usr/share/texlive/texmf-dist/tex/latex/jknapltx/mathrsfs.sty" 1137110241 300 12fa6f636b617656f2810ee82cb05015 ""
41 | "/usr/share/texlive/texmf-dist/tex/latex/jknapltx/ursfs.fd" 1137110241 548 cc4e3557704bfed27c7002773fad6c90 ""
42 | "/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-xetex.def" 1611959857 34893 cbd456ee6e7730ec7601ee4597a5a22e ""
43 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/mathpazo.sty" 1586716065 8976 3f18c815295e2a2949e87fa743bcb489 ""
44 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/omlzplm.fd" 1137110629 638 2349dd185efcefd0c3380a2601df0cee ""
45 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/omszplm.fd" 1137110629 455 c09241d92b40b1b84eb2bb5776606aea ""
46 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/omxzplm.fd" 1137110629 322 fb88cb3e5f25cf1596ba8826c4210e0e ""
47 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/ot1ppl.fd" 1137110629 961 06b773644d960aac68add40fcb596208 ""
48 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/ot1zplm.fd" 1137110629 436 5e7baa1a259bab50a2bdffad6426f38c ""
49 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1ppl.fd" 1137110629 774 5747d3f33ec2f7c4881c94e931a130b1 ""
50 | "/usr/share/texlive/texmf-dist/tex/latex/psnfss/ts1ppl.fd" 1137110629 619 35f1cf70bf09b6e2d22ee0902cfb1a8b ""
51 | "/usr/share/texlive/texmf-dist/tex/latex/subfigure/subfigure.cfg" 1167176009 2062 a0e7d66e09e508f51289a656aec06ed2 ""
52 | "/usr/share/texlive/texmf-dist/tex/latex/subfigure/subfigure.sty" 1167176009 15188 91281c7ddbccfa54a8e0c3b56ab5aa72 ""
53 | "/usr/share/texlive/texmf-dist/tex/latex/tools/enumerate.sty" 1580683321 3469 19b6cb25f21abe53fb90b9fe27615441 ""
54 | "/usr/share/texlive/texmf-dist/web2c/texmf.cnf" 1613593815 38841 799d1dd9682a55ce442e10c99777ecc1 ""
55 | "/usr/share/texmf/fonts/tfm/public/lm/ec-lmtt12.tfm" 1254938640 1368 6a60e6a5e029141041d64d339b87e533 ""
56 | "/usr/share/texmf/tex/latex/lm/t1lmtt.fd" 1256929440 2681 354015af3b61e7be30009f084986375a ""
57 | "/usr/share/texmf/web2c/texmf.cnf" 1613593815 38841 799d1dd9682a55ce442e10c99777ecc1 ""
58 | "/var/lib/texmf/web2c/xetex/xelatex.fmt" 1646895108 4944439 8ca7885d66bdd0197b7a2e53c4de5b7e ""
59 | "assignment.aux" 1656466410 57 de1406cbf8b0484b74ca9af432473f52 "pdflatex"
60 | "assignment.tex" 1656466409 8769 2075fab608b53682d3af7107b4b11255 ""
61 | (generated)
62 | "assignment.pdf"
63 | "assignment.aux"
64 | "assignment.log"
65 |
--------------------------------------------------------------------------------
/assignment/assignment.log:
--------------------------------------------------------------------------------
1 | This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/Debian) (preloaded format=xelatex 2022.3.10) 29 JUN 2022 10:33
2 | entering extended mode
3 | \write18 enabled.
4 | file:line:error style messages enabled.
5 | %&-line parsing enabled.
6 | **assignment.tex
7 | (./assignment.tex
8 | LaTeX2e <2020-10-01> patch level 4
9 | L3 programming layer <2021-01-09> xparse <2020-03-03> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
10 | Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
11 | (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo
12 | File: size12.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
13 | )
14 | \c@part=\count173
15 | \c@section=\count174
16 | \c@subsection=\count175
17 | \c@subsubsection=\count176
18 | \c@paragraph=\count177
19 | \c@subparagraph=\count178
20 | \c@figure=\count179
21 | \c@table=\count180
22 | \abovecaptionskip=\skip47
23 | \belowcaptionskip=\skip48
24 | \bibindent=\dimen138
25 | ) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty
26 | Package: amsmath 2020/09/23 v2.17i AMS math features
27 | \@mathmargin=\skip49
28 |
29 | For additional information on amsmath, use the `?' option.
30 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty
31 | Package: amstext 2000/06/29 v2.01 AMS text
32 | (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty
33 | File: amsgen.sty 1999/11/30 v2.0 generic functions
34 | \@emptytoks=\toks15
35 | \ex@=\dimen139
36 | )) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty
37 | Package: amsbsy 1999/11/29 v1.2d Bold Symbols
38 | \pmbraise@=\dimen140
39 | ) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty
40 | Package: amsopn 2016/03/08 v2.02 operator names
41 | )
42 | \inf@bad=\count181
43 | LaTeX Info: Redefining \frac on input line 234.
44 | \uproot@=\count182
45 | \leftroot@=\count183
46 | LaTeX Info: Redefining \overline on input line 399.
47 | \classnum@=\count184
48 | \DOTSCASE@=\count185
49 | LaTeX Info: Redefining \ldots on input line 496.
50 | LaTeX Info: Redefining \dots on input line 499.
51 | LaTeX Info: Redefining \cdots on input line 620.
52 | \Mathstrutbox@=\box47
53 | \strutbox@=\box48
54 | \big@size=\dimen141
55 | LaTeX Font Info: Redeclaring font encoding OML on input line 743.
56 | LaTeX Font Info: Redeclaring font encoding OMS on input line 744.
57 | \macc@depth=\count186
58 | \c@MaxMatrixCols=\count187
59 | \dotsspace@=\muskip16
60 | \c@parentequation=\count188
61 | \dspbrk@lvl=\count189
62 | \tag@help=\toks16
63 | \row@=\count190
64 | \column@=\count191
65 | \maxfields@=\count192
66 | \andhelp@=\toks17
67 | \eqnshift@=\dimen142
68 | \alignsep@=\dimen143
69 | \tagshift@=\dimen144
70 | \tagwidth@=\dimen145
71 | \totwidth@=\dimen146
72 | \lineht@=\dimen147
73 | \@envbody=\toks18
74 | \multlinegap=\skip50
75 | \multlinetaggap=\skip51
76 | \mathdisplay@stack=\toks19
77 | LaTeX Info: Redefining \[ on input line 2923.
78 | LaTeX Info: Redefining \] on input line 2924.
79 | ) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
80 | Package: amssymb 2013/01/14 v3.01 AMS font symbols
81 | (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty
82 | Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support
83 | \symAMSa=\mathgroup4
84 | \symAMSb=\mathgroup5
85 | LaTeX Font Info: Redeclaring math symbol \hbar on input line 98.
86 | LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold'
87 | (Font) U/euf/m/n --> U/euf/b/n on input line 106.
88 | )) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty
89 | Package: amsthm 2020/05/29 v2.20.6
90 | \thm@style=\toks20
91 | \thm@bodyfont=\toks21
92 | \thm@headfont=\toks22
93 | \thm@notefont=\toks23
94 | \thm@headpunct=\toks24
95 | \thm@preskip=\skip52
96 | \thm@postskip=\skip53
97 | \thm@headsep=\skip54
98 | \dth@everypar=\toks25
99 | ) (/usr/share/texlive/texmf-dist/tex/latex/psnfss/mathpazo.sty
100 | Package: mathpazo 2020/03/25 PSNFSS-v9.3 Palatino w/ Pazo Math (D.Puga, WaS)
101 | \symupright=\mathgroup6
102 | ) (/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
103 | Package: fontenc 2020/08/10 v2.0s Standard LaTeX package
104 | LaTeX Font Info: Trying to load font information for T1+ppl on input line 112.
105 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1ppl.fd
106 | File: t1ppl.fd 2001/06/04 font definitions for T1/ppl.
107 | )) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty
108 | Package: inputenc 2020/08/01 v1.3d Input encoding file
109 | \inpenc@prehook=\toks26
110 | \inpenc@posthook=\toks27
111 |
112 |
113 | Package inputenc Warning: inputenc package ignored with utf8 based engines.
114 |
115 | ) (/usr/share/texlive/texmf-dist/tex/latex/jknapltx/mathrsfs.sty
116 | Package: mathrsfs 1996/01/01 Math RSFS package v1.0 (jk)
117 | \symrsfs=\mathgroup7
118 | ) (/usr/share/texlive/texmf-dist/tex/latex/bbm-macros/bbm.sty
119 | Package: bbm 1999/03/15 V 1.2 provides fonts for set symbols - TH
120 | LaTeX Font Info: Overwriting math alphabet `\mathbbm' in version `bold'
121 | (Font) U/bbm/m/n --> U/bbm/bx/n on input line 33.
122 | LaTeX Font Info: Overwriting math alphabet `\mathbbmss' in version `bold'
123 | (Font) U/bbmss/m/n --> U/bbmss/bx/n on input line 35.
124 | ) (/usr/share/texlive/texmf-dist/tex/latex/subfigure/subfigure.sty
125 | Package: subfigure 2002/03/15 v2.1.5 subfigure package
126 | \subfigtopskip=\skip55
127 | \subfigcapskip=\skip56
128 | \subfigcaptopadj=\dimen148
129 | \subfigbottomskip=\skip57
130 | \subfigcapmargin=\dimen149
131 | \subfiglabelskip=\skip58
132 | \c@subfigure=\count193
133 | \c@lofdepth=\count194
134 | \c@subtable=\count195
135 | \c@lotdepth=\count196
136 |
137 | ****************************************
138 | * Local config file subfigure.cfg used *
139 | ****************************************
140 | (/usr/share/texlive/texmf-dist/tex/latex/subfigure/subfigure.cfg)
141 | \subfig@top=\skip59
142 | \subfig@bottom=\skip60
143 | ) (/usr/share/texlive/texmf-dist/tex/latex/tools/enumerate.sty
144 | Package: enumerate 2015/07/23 v3.00 enumerate extensions (DPC)
145 | \@enLab=\toks28
146 | )
147 | \c@question=\count197
148 | (/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-xetex.def
149 | File: l3backend-xetex.def 2020-01-29 L3 backend support: XeTeX
150 | (|extractbb --version)
151 | \c__kernel_sys_dvipdfmx_version_int=\count198
152 | \l__color_backend_stack_int=\count199
153 | \g__graphics_track_int=\count266
154 | \l__pdf_internal_box=\box49
155 | \g__pdf_backend_object_int=\count267
156 | \g__pdf_backend_annotation_int=\count268
157 | \g__pdf_backend_link_int=\count269
158 | ) (./assignment.aux)
159 | \openout1 = `assignment.aux'.
160 |
161 | LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 137.
162 | LaTeX Font Info: ... okay on input line 137.
163 | LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 137.
164 | LaTeX Font Info: ... okay on input line 137.
165 | LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 137.
166 | LaTeX Font Info: ... okay on input line 137.
167 | LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 137.
168 | LaTeX Font Info: ... okay on input line 137.
169 | LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 137.
170 | LaTeX Font Info: Trying to load font information for TS1+cmr on input line 137.
171 | (/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd
172 | File: ts1cmr.fd 2019/12/16 v2.5j Standard LaTeX font definitions
173 | )
174 | LaTeX Font Info: ... okay on input line 137.
175 | LaTeX Font Info: Checking defaults for TU/lmr/m/n on input line 137.
176 | LaTeX Font Info: ... okay on input line 137.
177 | LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 137.
178 | LaTeX Font Info: ... okay on input line 137.
179 | LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 137.
180 | LaTeX Font Info: ... okay on input line 137.
181 | LaTeX Font Info: Trying to load font information for TS1+ppl on input line 160.
182 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/ts1ppl.fd
183 | File: ts1ppl.fd 2001/06/04 font definitions for TS1/ppl.
184 | )
185 | LaTeX Font Info: Trying to load font information for T1+lmtt on input line 173.
186 | (/usr/share/texmf/tex/latex/lm/t1lmtt.fd
187 | File: t1lmtt.fd 2009/10/30 v1.6 Font defs for Latin Modern
188 | ) [1
189 |
190 | ]
191 | LaTeX Font Info: Trying to load font information for OT1+ppl on input line 200.
192 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/ot1ppl.fd
193 | File: ot1ppl.fd 2001/06/04 font definitions for OT1/ppl.
194 | )
195 | LaTeX Font Info: Trying to load font information for OML+zplm on input line 200.
196 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/omlzplm.fd
197 | File: omlzplm.fd 2002/09/08 Fontinst v1.914 font definitions for OML/zplm.
198 | )
199 | LaTeX Font Info: Trying to load font information for OMS+zplm on input line 200.
200 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/omszplm.fd
201 | File: omszplm.fd 2002/09/08 Fontinst v1.914 font definitions for OMS/zplm.
202 | )
203 | LaTeX Font Info: Trying to load font information for OMX+zplm on input line 200.
204 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/omxzplm.fd
205 | File: omxzplm.fd 2002/09/08 Fontinst v1.914 font definitions for OMX/zplm.
206 | )
207 | LaTeX Font Info: Font shape `U/msa/m/n' will be
208 | (Font) scaled to size 12.50409pt on input line 200.
209 | LaTeX Font Info: Font shape `U/msa/m/n' will be
210 | (Font) scaled to size 9.37807pt on input line 200.
211 | LaTeX Font Info: Font shape `U/msa/m/n' will be
212 | (Font) scaled to size 7.29405pt on input line 200.
213 | LaTeX Font Info: Font shape `U/msb/m/n' will be
214 | (Font) scaled to size 12.50409pt on input line 200.
215 | LaTeX Font Info: Font shape `U/msb/m/n' will be
216 | (Font) scaled to size 9.37807pt on input line 200.
217 | LaTeX Font Info: Font shape `U/msb/m/n' will be
218 | (Font) scaled to size 7.29405pt on input line 200.
219 | LaTeX Font Info: Trying to load font information for OT1+zplm on input line 200.
220 | (/usr/share/texlive/texmf-dist/tex/latex/psnfss/ot1zplm.fd
221 | File: ot1zplm.fd 2002/09/08 Fontinst v1.914 font definitions for OT1/zplm.
222 | )
223 | LaTeX Font Info: Trying to load font information for U+rsfs on input line 200.
224 | (/usr/share/texlive/texmf-dist/tex/latex/jknapltx/ursfs.fd
225 | File: ursfs.fd 1998/03/24 rsfs font definition file (jk)
226 | )
227 | LaTeX Font Info: Trying to load font information for U+bbm on input line 212.
228 | (/usr/share/texlive/texmf-dist/tex/latex/bbm-macros/ubbm.fd
229 | File: ubbm.fd 1999/03/15 V 1.2 Font definition for bbm font - TH
230 | ) [2] [3] (./assignment.aux) )
231 | Here is how much of TeX's memory you used:
232 | 2515 strings out of 477220
233 | 33238 string characters out of 5832722
234 | 314306 words of memory out of 5000000
235 | 22196 multiletter control sequences out of 15000+600000
236 | 419713 words of font info for 67 fonts, out of 8000000 for 9000
237 | 1348 hyphenation exceptions out of 8191
238 | 67i,4n,74p,227b,178s stack positions out of 5000i,500n,10000p,200000b,80000s
239 |
240 | Output written on assignment.pdf (3 pages).
241 |
--------------------------------------------------------------------------------
/assignment/assignment.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/assignment/assignment.pdf
--------------------------------------------------------------------------------
/assignment/assignment.synctex.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/assignment/assignment.synctex.gz
--------------------------------------------------------------------------------
/assignment/assignment.tex:
--------------------------------------------------------------------------------
1 | \documentclass[12pt]{article}
2 |
3 |
4 | %%%%%%%%%%%%%%%%%%%%% MY STUFF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 |
6 | %\usepackage{fancyhdr}
7 | %\pagestyle{fancy}
8 | %\fancyfoot[C]{ {\bf Page \thepage\ of ??? -- ADV. ECON. METHODS (EMET3011/8014)}}
9 | %\fancyhead{}
10 | %\renewcommand{\headrulewidth}{0pt}
11 | %\addtolength{\footskip}{80pt}
12 |
13 | \usepackage{amsmath, amssymb, amsthm}
14 | \usepackage{mathpazo}
15 | \usepackage[T1]{fontenc}
16 |
17 | \usepackage[utf8]{inputenc}
18 |
19 | % caligraphic
20 | \usepackage{mathrsfs}
21 | \usepackage{bbm}
22 | \usepackage{subfigure}
23 |
24 | \usepackage{enumerate}
25 |
26 | \renewcommand{\baselinestretch}{1.1}
27 |
28 |
29 | \setcounter{tocdepth}{1}
30 |
31 | % skip a line between paragraphs, no indentation
32 | \setlength{\parskip}{1.5ex plus0.5ex minus0.5ex}
33 | \setlength{\parindent}{0pt}
34 |
35 | \newcommand{\navy}[1]{\textcolor{Blue}{\bf #1}}
36 |
37 | \newcommand{\argmax}{\operatornamewithlimits{argmax}}
38 | \newcommand{\argmin}{\operatornamewithlimits{argmin}}
39 |
40 | \DeclareMathOperator{\cl}{cl}
41 | \DeclareMathOperator{\se}{se}
42 | %\DeclareMathOperator{\argmax}{argmax}
43 | \DeclareMathOperator{\interior}{int}
44 | \DeclareMathOperator{\Prob}{Prob}
45 | \DeclareMathOperator{\determinant}{det}
46 | \DeclareMathOperator{\Span}{span}
47 | \DeclareMathOperator{\rank}{rank}
48 | \DeclareMathOperator{\range}{rng}
49 | \DeclareMathOperator{\trace}{trace}
50 | \DeclareMathOperator{\cov}{cov}
51 | \DeclareMathOperator{\corr}{corr}
52 | \DeclareMathOperator{\var}{var}
53 | \DeclareMathOperator{\mse}{mse}
54 |
55 | \newcommand{\ess}{ \textrm{{\sc ess}} }
56 | \newcommand{\tss}{ \textrm{{\sc tss}} }
57 | \newcommand{\ssr}{ \textrm{{\sc ssr}} }
58 | \newcommand{\rssr}{ \textrm{{\sc rssr}} }
59 | \newcommand{\ussr}{ \textrm{{\sc ussr}} }
60 |
61 |
62 | % mics short cuts and symbols
63 | \newcommand{\st}{\ensuremath{\ \mathrm{s.t.}\ }}
64 | \newcommand{\setntn}[2]{ \{ #1 : #2 \} }
65 | \newcommand{\fore}{\therefore \quad}
66 | \newcommand{\tod}{\stackrel { d } {\to} }
67 | \newcommand{\eqdist}{\stackrel {\textrm{ \scriptsize{d} }} {=} }
68 | \newcommand{\iidsim}{\stackrel {\textrm{ {\sc iid }}} {\sim} }
69 | \newcommand{\1}{\mathbbm 1}
70 | \newcommand{\dee}{\,{\rm d}}
71 | \newcommand{\given}{\, | \,}
72 | \newcommand{\la}{\langle}
73 | \newcommand{\ra}{\rangle}
74 |
75 | \newcommand{\boldx}{ {\bf x} }
76 | \newcommand{\boldw}{ {\bf w} }
77 | \newcommand{\boldu}{ {\bf u} }
78 | \newcommand{\boldy}{ {\bf y} }
79 | \newcommand{\boldb}{ {\bf b} }
80 | \newcommand{\bolda}{ {\bf a} }
81 | \newcommand{\boldi}{ {\bf i} }
82 | \newcommand{\bolde}{ {\bf e} }
83 | \newcommand{\bolds}{ {\bf s} }
84 | \newcommand{\boldz}{ {\bf z} }
85 | \newcommand{\boldv}{ {\bf v} }
86 |
87 | \newcommand{\boldzero}{ {\bf 0} }
88 | \newcommand{\boldone}{ {\bf 1} }
89 |
90 | \newcommand{\boldalpha}{ {\boldsymbol \alpha} }
91 | \newcommand{\boldbeta}{ {\boldsymbol \beta} }
92 | \newcommand{\boldgamma}{ {\boldsymbol \gamma} }
93 | \newcommand{\boldtheta}{ {\boldsymbol \theta} }
94 | \newcommand{\boldepsilon}{ {\boldsymbol \epsilon} }
95 | \newcommand{\boldSigma}{ {\boldsymbol \Sigma} }
96 |
97 | \newcommand{\hboldy}{ \hat {\bf y} }
98 | \newcommand{\hboldu}{ \hat {\bf u} }
99 | \newcommand{\hboldbeta}{ \hat {\boldsymbol \beta} }
100 |
101 | \newcommand{\boldA}{\mathbf A}
102 | \newcommand{\boldZ}{\mathbf Z}
103 | \newcommand{\boldB}{\mathbf B}
104 | \newcommand{\boldC}{\mathbf C}
105 | \newcommand{\boldD}{\mathbf D}
106 | \newcommand{\boldM}{\mathbf M}
107 | \newcommand{\boldP}{\mathbf P}
108 | \newcommand{\boldI}{\mathbf I}
109 | \newcommand{\boldX}{\mathbf X}
110 | \newcommand{\boldY}{\mathbf Y}
111 |
112 |
113 | \newcommand{\RR}{\mathbbm R}
114 | \newcommand{\NN}{\mathbbm N}
115 | \newcommand{\PP}{\mathbbm P}
116 | \newcommand{\EE}{\mathbbm E \,}
117 | \newcommand{\XX}{\mathbbm X}
118 | \newcommand{\ZZ}{\mathbbm Z}
119 | \newcommand{\QQ}{\mathbbm Q}
120 |
121 | \newcommand{\fF}{\mathcal F}
122 | \newcommand{\nN}{\mathcal N}
123 |
124 |
125 | \newcommand{\Xsf}{\mathsf X}
126 | \newcommand{\Zsf}{\mathsf Z}
127 |
128 |
129 | \theoremstyle{definition}
130 | \newtheorem{question}{Question}
131 |
132 |
133 |
134 | %%%%%%%%%%%%%%%%%% end my preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 |
136 |
137 | \begin{document}
138 |
139 |
140 | \title{Practice Questions}
141 |
142 | \date{}
143 |
144 | %\maketitle
145 |
146 | \begin{center}
147 |
148 | {\bf {\Large Introduction to Computational Macroeconomics}}
149 |
150 | \bigskip
151 | {\bf {\Large Tokyo 2022}}
152 |
153 | \bigskip
154 | {\bf {\Large Assignment}}
155 |
156 | \today
157 | \end{center}
158 |
159 | \begin{itemize}
160 | \item Due date: 12th July
161 | \item Weight: 40\% of total marks
162 | \end{itemize}
163 |
164 | \vspace{1em}
165 | \hrule
166 | \vspace{1em}
167 | \hrule
168 | \vspace{1em}
169 |
170 | This assignment should be submitted by email as a single Jupyter notebook no
171 | later than midnight on the due date. Please note that 20\% of the total mark
172 | will be deducted for late assignments. Please send your email to
173 | \texttt{john.stachurski@anu.edu.au}. Make sure that you include your {\sc
174 | name and student number} in the Jupyter notebook. The subject of your email
175 | should be ``Comp econ assignment''.
176 |
177 | Note that proofs and other discussion should also be included in the notebook.
178 | If you are not sure how to do this please ask. No other files should be
179 | submitted. I recommend that you stop and restart Jupyter before you submit,
180 | and make sure that the notebook runs from start to finish without error.
181 |
182 | Please note that \emph{you may collaborate with up to two other students}.
183 | Please be generous and offer to collaborate with any student who does not have
184 | a partner. You should include the names of the students with whom you
185 | collaborated in your Jupyter notebook.
186 |
187 | Groups of students should not collaborate with other groups.
188 |
189 | \vspace{1em}
190 | \vspace{1em}
191 | \vspace{1em}
192 | \hrule
193 | \vspace{1em}
194 | \hrule
195 | \vspace{1em}
196 |
197 | \newpage
198 |
199 | A worker is currently employed and deciding when to retire. While
200 | employed, the worker is paid a fixed wage $w$ in each period. When she
201 | retires, she is paid a single lump sum pension $s$. Both $w$ and $s$
202 | are nonnegative and constant.
203 |
204 | The worker discounts future earnings using the real interest rate $r_t = i -
205 | \pi_t$, where $i$ is the nominal risk-free interest rate and $\pi_t$ is time
206 | $t$ inflation. In other words, a payment $y_{t+1}$ at $t+1$
207 | is discounted to time $t$
208 | present value via $\beta_t y_{t+1}$, where $\beta_t = 1/(1 + r_t)$. The
209 | nominal risk-free rate is constant.
210 |
211 | Assume that the inflation rate obeys $\pi_t = \pi(Z_t)$ for some fixed
212 | function $\pi \in \RR^\Zsf$, where $\Zsf$ is a finite subset of $\RR$ and
213 | $(Z)_{t \geq 0}$ is $Q$-Markov for some stochastic matrix $Q$ on $\Zsf$.
214 | In what follows we set $n := |\Zsf|$.
215 |
216 |
217 | \begin{question}
218 | Write down the Bellman equation for the problem, in terms of the lifetime
219 | value for an employed worker. Define the Bellman operator $T$
220 | corresponding to the Bellman equation as a self-map on $\RR^\Zsf$.
221 | \end{question}
222 |
223 | \begin{question}
224 | Prove that $T$ is a contraction map on $\RR^\Zsf$ with respect to the
225 | supremum norm whenever $\bar r := \min_{z \in \Zsf} (i - \pi(z))$
226 | satisfies $\bar r > 0$.
227 | \end{question}
228 |
229 | Although the condition $\bar r > 0$ is sufficient for global stability of $T$,
230 | it is not necessary. As we will learn later, it sufficies that the matrix
231 | $n \times n$ matrix
232 | %
233 | \begin{equation*}
234 | L(z, z') := \frac{1}{1 + i - \pi(z)} Q(z, z')
235 | \end{equation*}
236 | %
237 | satisfies $r(L) < 1$.
238 |
239 | \begin{question}
240 | Let $\pi(z) = p + z$, where $p$ is a parameter indicating the long-run
241 | average inflation rate. Show that $r(L) < 1$ holds when $(Z_t)$ is
242 | the Tauchen discretization of the AR(1) process $X_{t+1} = \rho X_t + \nu
243 | W_{t+1}$, where $(W_t)_{t \geq 0}$ is {\sc iid} standard normal and
244 | the parameters are given by
245 | %
246 | \begin{equation}\label{eq:dp}
247 | s = 100, \;
248 | w = 5, \;
249 | i = 0.1,\;
250 | p = 0.06,\;
251 | \rho = 0.9 \; \text{and} \;
252 | \nu = 0.01
253 | \end{equation}
254 | %
255 | The AR(1) process should be discretized to a grid of $n = 100$ points
256 | (which is the size of the state space $\Zsf$). To discretize,
257 | you can use the commands \texttt{import quantecon as qe} and
258 | %
259 | \begin{center}
260 | \texttt{mc = qe.tauchen($\rho$, $\nu$, m=10, n=n)}
261 | \end{center}
262 | \end{question}
263 |
264 | \begin{question}
265 | Solve for the value function $v^*$ using value function iteration using
266 | the default parameters in \eqref{eq:dp}. Plot $v^*$ as
267 | a function of $z$. Plot the stopping value $s$ on the same figure.
268 | \end{question}
269 |
270 | \begin{question}
271 | Plot the $v^*$-greedy policy as a function of $z$.
272 | Provide some interpretation of the figure.
273 | \end{question}
274 |
275 | \begin{question}
276 | Prove that the value function $v^*$ is increasing on $\Zsf$ under the
277 | parameters in \eqref{eq:dp}. Provide some economic intuition if you can.
278 | \end{question}
279 |
280 | \begin{question}
281 | Using the default parameters and simulation, compute the average number of
282 | years until retirement at the default parameters. In answering this
283 | question, you should regard one period in the model as one month (i.e.,
284 | wages are paid monthly and interest and inflation rates are monthly).
285 | If you can, accelerate your simulation using Numba.
286 | \end{question}
287 |
288 | \begin{question}
289 | Now set $w=4.9$ and repeat the last exercise. What change do you observe?
290 | How can you explain this change?
291 | \end{question}
292 |
293 |
294 | \end{document}
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
--------------------------------------------------------------------------------
/ch_1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_1.pdf
--------------------------------------------------------------------------------
/ch_2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_2.pdf
--------------------------------------------------------------------------------
/ch_3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_3.pdf
--------------------------------------------------------------------------------
/ch_4.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_4.pdf
--------------------------------------------------------------------------------
/ch_5.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_5.pdf
--------------------------------------------------------------------------------
/ch_6.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_6.pdf
--------------------------------------------------------------------------------
/ch_7.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/ch_7.pdf
--------------------------------------------------------------------------------
/dp.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/dp.pdf
--------------------------------------------------------------------------------
/notebooks/intro_to_python/01_getting_started.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "2d72c29a",
6 | "metadata": {},
7 | "source": [
8 | "# Setting up Your Python Environment\n",
9 | "\n",
10 | "Aims\n",
11 | "\n",
12 | "1. get a Python environment up and running\n",
13 | "1. execute simple Python commands\n",
14 | "1. run a sample program\n",
15 | "1. install the code libraries that underpin these lectures\n",
16 | "\n",
17 | "## Anaconda\n",
18 | "\n",
19 | "The [core Python package](https://www.python.org/downloads/) is easy to install but *not* what you should choose for these lectures.\n",
20 | "\n",
21 | "These lectures require the entire scientific programming ecosystem, which\n",
22 | "\n",
23 | "* the core installation doesn't provide\n",
24 | "* is painful to install one piece at a time.\n",
25 | "\n",
26 | "Hence the best approach for our purposes is to install a Python distribution that contains\n",
27 | "\n",
28 | "1. the core Python language **and**\n",
29 | "1. compatible versions of the most popular scientific libraries.\n",
30 | "\n",
31 | "The best such distribution is \n",
32 | "\n",
33 | "Anaconda is\n",
34 | "\n",
35 | "* very popular\n",
36 | "* cross-platform\n",
37 | "* comprehensive\n",
38 | "* completely unrelated to the [Nicki Minaj song of the same name](????)\n",
39 | "\n",
40 | "Anaconda also comes with a great package management system to organize your code libraries."
41 | ]
42 | },
43 | {
44 | "cell_type": "markdown",
45 | "id": "dad6be37",
46 | "metadata": {},
47 | "source": [
48 | "### Installing Anaconda\n",
49 | "\n",
50 | "To install Anaconda, [download](https://www.anaconda.com/download/) the binary and follow the instructions.\n",
51 | "\n",
52 | "Important points:\n",
53 | "\n",
54 | "* Install the latest version!\n",
55 | "* If you are asked during the installation process whether you'd like to make Anaconda your default Python installation, say yes."
56 | ]
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "id": "f091f671",
61 | "metadata": {},
62 | "source": [
63 | "## Jupyter Notebooks \n",
64 | "\n",
65 | "\n",
66 | "[Jupyter](http://jupyter.org/) notebooks are one of the many possible ways to interact with Python and the scientific libraries.\n",
67 | "\n",
68 | "They use a *browser-based* interface to Python with\n",
69 | "\n",
70 | "* The ability to write and execute Python commands.\n",
71 | "* Formatted output in the browser, including tables, figures, animation, etc.\n",
72 | "* The option to mix in formatted text and mathematical expressions.\n",
73 | "\n",
74 | "\n",
75 | "While Jupyter isn't the only way to code in Python, it's great for when you wish to\n",
76 | "\n",
77 | "* start coding in Python\n",
78 | "* test new ideas or interact with small pieces of code\n",
79 | "* share or collaborate scientific ideas with students or colleagues"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "id": "c7b5cfd1",
85 | "metadata": {},
86 | "source": [
87 | "### Starting the Jupyter Notebook\n",
88 | "\n",
89 | "\n",
90 | "* search for Jupyter in your applications menu, or\n",
91 | "* open up a terminal and type `jupyter notebook`"
92 | ]
93 | },
94 | {
95 | "cell_type": "markdown",
96 | "id": "c1caf409",
97 | "metadata": {},
98 | "source": [
99 | "Let's now cover some basics:\n",
100 | "\n",
101 | "\n",
102 | "* Running Cells\n",
103 | "* Modal Editing\n",
104 | "* Inserting Unicode \n",
105 | "* Tab Completion\n",
106 | "* On-Line Help\n",
107 | "* Adding rich text and LaTeX\n",
108 | "* Installing Libraries\n",
109 | ""
110 | ]
111 | }
112 | ],
113 | "metadata": {
114 | "jupyter": {
115 | "jupytext": {
116 | "text_representation": {
117 | "extension": ".md",
118 | "format_name": "myst",
119 | "format_version": "1.3",
120 | "jupytext_version": "1.13.7"
121 | }
122 | },
123 | "kernelspec": {
124 | "display_name": "Python 3",
125 | "language": "python",
126 | "name": "python3"
127 | }
128 | }
129 | },
130 | "nbformat": 4,
131 | "nbformat_minor": 5
132 | }
133 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/07_scipy.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "b1d0dfd6",
6 | "metadata": {},
7 | "source": [
8 | "## Overview\n",
9 | "\n",
10 | "[SciPy](http://www.scipy.org) builds on top of NumPy to provide common tools for scientific programming such as\n",
11 | "\n",
12 | "* [linear algebra](http://docs.scipy.org/doc/scipy/reference/linalg.html)\n",
13 | "* [numerical integration](http://docs.scipy.org/doc/scipy/reference/integrate.html)\n",
14 | "* [interpolation](http://docs.scipy.org/doc/scipy/reference/interpolate.html)\n",
15 | "* [optimization](http://docs.scipy.org/doc/scipy/reference/optimize.html)\n",
16 | "* [distributions and random number generation](http://docs.scipy.org/doc/scipy/reference/stats.html)\n",
17 | "* [signal processing](http://docs.scipy.org/doc/scipy/reference/signal.html)\n",
18 | "* etc., etc"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "id": "fd6a2f4d",
24 | "metadata": {},
25 | "source": [
26 | "Many SciPy routines are thin wrappers around industry-standard Fortran libraries such as [LAPACK](https://en.wikipedia.org/wiki/LAPACK), [BLAS](https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms), etc.\n",
27 | "\n",
28 | "It's not really necessary to \"learn\" SciPy as a whole.\n",
29 | "\n",
30 | "In this lecture, we aim only to highlight some useful parts of the package.\n",
31 | "\n",
32 | "The functionality of SciPy is in its sub-packages\n",
33 | "\n",
34 | "* `scipy.optimize`, `scipy.integrate`, `scipy.stats`, etc.\n",
35 | "\n",
36 | "Let's explore some of the major sub-packages."
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "id": "9a6e4456",
42 | "metadata": {},
43 | "source": [
44 | "## Statistics\n",
45 | "\n",
46 | "The `scipy.stats` subpackage supplies\n",
47 | "\n",
48 | "* numerous random variable objects (densities, cumulative distributions, random sampling, etc.)\n",
49 | "* some estimation procedures\n",
50 | "* some statistical tests"
51 | ]
52 | },
53 | {
54 | "cell_type": "markdown",
55 | "id": "0366495e",
56 | "metadata": {},
57 | "source": [
58 | "### Random Variables and Distributions\n",
59 | "\n",
60 | "Recall that `numpy.random` provides functions for generating random variables"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "id": "ad7aaa1a",
67 | "metadata": {},
68 | "outputs": [],
69 | "source": [
70 | "import numpy as np\n",
71 | "np.random.beta(5, 5, size=3)"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "id": "c163b09e",
77 | "metadata": {},
78 | "source": [
79 | "This generates a draw from the distribution with the density function below when `a, b = 5, 5`\n",
80 | "\n",
81 | "$$\n",
82 | "f(x; a, b) = \\frac{x^{(a - 1)} (1 - x)^{(b - 1)}}\n",
83 | " {\\int_0^1 u^{(a - 1)} (1 - u)^{(b - 1)} du}\n",
84 | " \\qquad (0 \\leq x \\leq 1)\n",
85 | "$$\n",
86 | "\n",
87 | "Sometimes we need access to the density itself, or the cdf, the quantiles, etc.\n",
88 | "\n",
89 | "For this, we can use `scipy.stats`, which provides all of this functionality as well as random number generation in a single consistent interface.\n",
90 | "\n",
91 | "Here's an example of usage"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "id": "84158ef6",
98 | "metadata": {},
99 | "outputs": [],
100 | "source": [
101 | "%matplotlib inline\n",
102 | "from scipy.stats import beta\n",
103 | "import matplotlib.pyplot as plt\n",
104 | "\n",
105 | "q = beta(5, 5) # Beta(a, b), with a = b = 5\n",
106 | "obs = q.rvs(2000) # 2000 observations\n",
107 | "grid = np.linspace(0.01, 0.99, 100)\n",
108 | "\n",
109 | "fig, ax = plt.subplots()\n",
110 | "ax.hist(obs, bins=40, density=True)\n",
111 | "ax.plot(grid, q.pdf(grid), 'k-', linewidth=2)\n",
112 | "plt.show()"
113 | ]
114 | },
115 | {
116 | "cell_type": "markdown",
117 | "id": "8e959811",
118 | "metadata": {},
119 | "source": [
120 | "The object `q` that represents the distribution has additional useful methods, including"
121 | ]
122 | },
123 | {
124 | "cell_type": "code",
125 | "execution_count": null,
126 | "id": "c895fe29",
127 | "metadata": {},
128 | "outputs": [],
129 | "source": [
130 | "q.cdf(0.4) # Cumulative distribution function"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "id": "503e00d5",
137 | "metadata": {},
138 | "outputs": [],
139 | "source": [
140 | "q.ppf(0.8) # Quantile (inverse cdf) function"
141 | ]
142 | },
143 | {
144 | "cell_type": "code",
145 | "execution_count": null,
146 | "id": "d5a61353",
147 | "metadata": {},
148 | "outputs": [],
149 | "source": [
150 | "q.mean()"
151 | ]
152 | },
153 | {
154 | "cell_type": "markdown",
155 | "id": "d923a0c1",
156 | "metadata": {},
157 | "source": [
158 | "## Roots and Fixed Points\n",
159 | "\n",
160 | "A **root** or **zero** of a real function $f$ on $[a,b]$ is an $x \\in [a, b]$ such that $f(x)=0$.\n",
161 | "\n",
162 | "For example, if we plot the function\n",
163 | "\n",
164 | "$$\n",
165 | "f(x) = \\sin(4 (x - 1/4)) + x + x^{20} - 1\n",
166 | "$$\n",
167 | "\n",
168 | "with $x \\in [0,1]$ we get"
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": null,
174 | "id": "98dd7f04",
175 | "metadata": {},
176 | "outputs": [],
177 | "source": [
178 | "f = lambda x: np.sin(4 * (x - 1/4)) + x + x**20 - 1\n",
179 | "x = np.linspace(0, 1, 100)\n",
180 | "\n",
181 | "fig, ax = plt.subplots()\n",
182 | "ax.plot(x, f(x), label='$f(x)$')\n",
183 | "ax.axhline(ls='--', c='k')\n",
184 | "ax.set_xlabel('$x$', fontsize=12)\n",
185 | "ax.set_ylabel('$f(x)$', fontsize=12)\n",
186 | "ax.legend(fontsize=12)\n",
187 | "plt.show()"
188 | ]
189 | },
190 | {
191 | "cell_type": "markdown",
192 | "id": "802cfded",
193 | "metadata": {},
194 | "source": [
195 | "The unique root is approximately 0.408.\n",
196 | "\n",
197 | "Let's consider some numerical techniques for finding roots."
198 | ]
199 | },
200 | {
201 | "cell_type": "markdown",
202 | "id": "6a6579d2",
203 | "metadata": {},
204 | "source": [
205 | "### Bisection \n",
206 | "\n",
207 | "One of the most common algorithms for numerical root-finding is *bisection*.\n",
208 | "\n",
209 | "To understand the idea, recall the well-known game where\n",
210 | "\n",
211 | "* Player A thinks of a secret number between 1 and 100\n",
212 | "* Player B asks if it's less than 50\n",
213 | " * If yes, B asks if it's less than 25\n",
214 | " * If no, B asks if it's less than 75\n",
215 | "\n",
216 | "And so on.\n",
217 | "\n",
218 | "This is bisection.\n",
219 | "\n",
220 | "SciPy provides a bisection function."
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": null,
226 | "id": "48179bdd",
227 | "metadata": {},
228 | "outputs": [],
229 | "source": [
230 | "from scipy.optimize import bisect\n",
231 | "\n",
232 | "bisect(f, 0, 1)"
233 | ]
234 | },
235 | {
236 | "cell_type": "markdown",
237 | "id": "822f4838",
238 | "metadata": {},
239 | "source": [
240 | "### The Newton-Raphson Method \n",
241 | "\n",
242 | "\n",
243 | "Another very common root-finding algorithm is the [Newton-Raphson method](https://en.wikipedia.org/wiki/Newton%27s_method).\n",
244 | "\n",
245 | "In SciPy this algorithm is implemented by `scipy.optimize.newton`.\n",
246 | "\n",
247 | "Unlike bisection, the Newton-Raphson method uses local slope information in an attempt to increase the speed of convergence.\n",
248 | "\n",
249 | "Let's investigate this using the same function $f$ defined above.\n",
250 | "\n",
251 | "With a suitable initial condition for the search we get convergence:"
252 | ]
253 | },
254 | {
255 | "cell_type": "code",
256 | "execution_count": null,
257 | "id": "4916e231",
258 | "metadata": {},
259 | "outputs": [],
260 | "source": [
261 | "from scipy.optimize import newton\n",
262 | "\n",
263 | "newton(f, 0.2) # Start the search at initial condition x = 0.2"
264 | ]
265 | },
266 | {
267 | "cell_type": "markdown",
268 | "id": "415cef42",
269 | "metadata": {},
270 | "source": [
271 | "But other initial conditions lead to failure of convergence:"
272 | ]
273 | },
274 | {
275 | "cell_type": "code",
276 | "execution_count": null,
277 | "id": "e3c0f6b3",
278 | "metadata": {},
279 | "outputs": [],
280 | "source": [
281 | "newton(f, 0.7) # Start the search at x = 0.7 instead"
282 | ]
283 | },
284 | {
285 | "cell_type": "markdown",
286 | "id": "0677e42b",
287 | "metadata": {},
288 | "source": [
289 | "### Hybrid Methods\n",
290 | "\n",
291 | "A general principle of numerical methods is as follows:\n",
292 | "\n",
293 | "* If you have specific knowledge about a given problem, you might be able to exploit it to generate efficiency.\n",
294 | "* If not, then the choice of algorithm involves a trade-off between speed and robustness.\n",
295 | "\n",
296 | "In practice, most default algorithms for root-finding, optimization and fixed points use *hybrid* methods.\n",
297 | "\n",
298 | "These methods typically combine a fast method with a robust method in the following manner:\n",
299 | "\n",
300 | "1. Attempt to use a fast method\n",
301 | "1. Check diagnostics\n",
302 | "1. If diagnostics are bad, then switch to a more robust algorithm\n",
303 | "\n",
304 | "In `scipy.optimize`, the function `brentq` is such a hybrid method and a good default"
305 | ]
306 | },
307 | {
308 | "cell_type": "code",
309 | "execution_count": null,
310 | "id": "c4bd2fac",
311 | "metadata": {},
312 | "outputs": [],
313 | "source": [
314 | "from scipy.optimize import brentq\n",
315 | "\n",
316 | "brentq(f, 0, 1)"
317 | ]
318 | },
319 | {
320 | "cell_type": "markdown",
321 | "id": "cbbb79b8",
322 | "metadata": {},
323 | "source": [
324 | "Here the correct solution is found and the speed is better than bisection:"
325 | ]
326 | },
327 | {
328 | "cell_type": "code",
329 | "execution_count": null,
330 | "id": "6bf81ce9",
331 | "metadata": {},
332 | "outputs": [],
333 | "source": [
334 | "%timeit brentq(f, 0, 1)"
335 | ]
336 | },
337 | {
338 | "cell_type": "code",
339 | "execution_count": null,
340 | "id": "3bd285c6",
341 | "metadata": {},
342 | "outputs": [],
343 | "source": [
344 | "%timeit bisect(f, 0, 1)"
345 | ]
346 | },
347 | {
348 | "cell_type": "markdown",
349 | "id": "48552d0d",
350 | "metadata": {},
351 | "source": [
352 | "## Optimization \n",
353 | "\n",
354 | "Most numerical packages provide only functions for *minimization*.\n",
355 | "\n",
356 | "Maximization can be performed by recalling that the maximizer of a function $f$ on domain $D$ is\n",
357 | "the minimizer of $-f$ on $D$.\n",
358 | "\n",
359 | "Minimization is closely related to root-finding: For smooth functions, interior optima correspond to roots of the first derivative.\n",
360 | "\n",
361 | "The speed/robustness trade-off described above is present with numerical optimization too.\n",
362 | "\n",
363 | "Unless you have some prior information you can exploit, it's usually best to use hybrid methods.\n",
364 | "\n",
365 | "For constrained, univariate (i.e., scalar) minimization, a good hybrid option is `fminbound`"
366 | ]
367 | },
368 | {
369 | "cell_type": "code",
370 | "execution_count": null,
371 | "id": "5b1a8d51",
372 | "metadata": {},
373 | "outputs": [],
374 | "source": [
375 | "from scipy.optimize import fminbound\n",
376 | "\n",
377 | "fminbound(lambda x: x**2, -1, 2) # Search in [-1, 2]"
378 | ]
379 | },
380 | {
381 | "cell_type": "markdown",
382 | "id": "ea9d5a9e",
383 | "metadata": {},
384 | "source": [
385 | "## Integration \n",
386 | "\n",
387 | "Most numerical integration methods work by computing the integral of an approximating polynomial.\n",
388 | "\n",
389 | "The resulting error depends on how well the polynomial fits the integrand, which in turn depends on how \"regular\" the integrand is.\n",
390 | "\n",
391 | "In SciPy, the relevant module for numerical integration is `scipy.integrate`.\n",
392 | "\n",
393 | "A good default for univariate integration is `quad`"
394 | ]
395 | },
396 | {
397 | "cell_type": "code",
398 | "execution_count": null,
399 | "id": "a4b29c89",
400 | "metadata": {},
401 | "outputs": [],
402 | "source": [
403 | "from scipy.integrate import quad\n",
404 | "\n",
405 | "integral, error = quad(lambda x: x**2, 0, 1)\n",
406 | "integral"
407 | ]
408 | }
409 | ],
410 | "metadata": {
411 | "kernelspec": {
412 | "display_name": "Python 3",
413 | "language": "python",
414 | "name": "python3"
415 | }
416 | },
417 | "nbformat": 4,
418 | "nbformat_minor": 5
419 | }
420 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/08_writing_good_code.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "c9ef413b",
6 | "metadata": {},
7 | "source": [
8 | "# Writing Good Code\n",
9 | "\n",
10 | "```{epigraph}\n",
11 | "\"Any fool can write code that a computer can understand. Good programmers write code that humans can understand.\" -- Martin Fowler\n",
12 | "```"
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "id": "f0984216",
18 | "metadata": {},
19 | "source": [
20 | "## Overview\n",
21 | "\n",
22 | "When computer programs are small, poorly written code is not overly costly.\n",
23 | "\n",
24 | "But more data, more sophisticated models, and more computer power are enabling us to take on more challenging problems that involve writing longer programs.\n",
25 | "\n",
26 | "For such programs, investment in good coding practices will pay high returns.\n",
27 | "\n",
28 | "The main payoffs are higher productivity and faster code.\n",
29 | "\n",
30 | "In this lecture, we review some elements of good coding practice.\n",
31 | "\n",
32 | "We also touch on modern developments in scientific computing --- such as just in time compilation --- and how they affect good program design."
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "id": "380803f3",
38 | "metadata": {},
39 | "source": [
40 | "## An Example of Poor Code\n",
41 | "\n",
42 | "Let's have a look at some poorly written code.\n",
43 | "\n",
44 | "The job of the code is to generate and plot time series of the simplified Solow model\n",
45 | "\n",
46 | "$$\n",
47 | "k_{t+1} = s k_t^{\\alpha} + (1 - \\delta) k_t,\n",
48 | "\\quad t = 0, 1, 2, \\ldots\n",
49 | "$$\n",
50 | "\n",
51 | "Here\n",
52 | "\n",
53 | "* $k_t$ is capital at time $t$ and\n",
54 | "* $s, \\alpha, \\delta$ are parameters (savings, a productivity parameter and depreciation)\n",
55 | "\n",
56 | "For each parameterization, the code\n",
57 | "\n",
58 | "1. sets $k_0 = 1$\n",
59 | "1. iterates using the rule above to produce a sequence $k_0, k_1, k_2 \\ldots , k_T$\n",
60 | "1. plots the sequence\n",
61 | "\n",
62 | "The plots will be grouped into three subfigures.\n",
63 | "\n",
64 | "In each subfigure, two parameters are held fixed while another varies"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": null,
70 | "id": "9bcbd0be",
71 | "metadata": {},
72 | "outputs": [],
73 | "source": [
74 | "%matplotlib inline\n",
75 | "import numpy as np\n",
76 | "import matplotlib.pyplot as plt\n",
77 | "\n",
78 | "# Allocate memory for time series\n",
79 | "k = np.empty(50)\n",
80 | "\n",
81 | "fig, axes = plt.subplots(3, 1, figsize=(8, 16))\n",
82 | "\n",
83 | "# Trajectories with different α\n",
84 | "δ = 0.1\n",
85 | "s = 0.4\n",
86 | "α = (0.25, 0.33, 0.45)\n",
87 | "\n",
88 | "for j in range(3):\n",
89 | " k[0] = 1\n",
90 | " for t in range(49):\n",
91 | " k[t+1] = s * k[t]**α[j] + (1 - δ) * k[t]\n",
92 | " axes[0].plot(k, 'o-', label=rf\"$\\alpha = {α[j]},\\; s = {s},\\; \\delta={δ}$\")\n",
93 | "\n",
94 | "axes[0].grid(lw=0.2)\n",
95 | "axes[0].set_ylim(0, 18)\n",
96 | "axes[0].set_xlabel('time')\n",
97 | "axes[0].set_ylabel('capital')\n",
98 | "axes[0].legend(loc='upper left', frameon=True)\n",
99 | "\n",
100 | "# Trajectories with different s\n",
101 | "δ = 0.1\n",
102 | "α = 0.33\n",
103 | "s = (0.3, 0.4, 0.5)\n",
104 | "\n",
105 | "for j in range(3):\n",
106 | " k[0] = 1\n",
107 | " for t in range(49):\n",
108 | " k[t+1] = s[j] * k[t]**α + (1 - δ) * k[t]\n",
109 | " axes[1].plot(k, 'o-', label=rf\"$\\alpha = {α},\\; s = {s[j]},\\; \\delta={δ}$\")\n",
110 | "\n",
111 | "axes[1].grid(lw=0.2)\n",
112 | "axes[1].set_xlabel('time')\n",
113 | "axes[1].set_ylabel('capital')\n",
114 | "axes[1].set_ylim(0, 18)\n",
115 | "axes[1].legend(loc='upper left', frameon=True)\n",
116 | "\n",
117 | "# Trajectories with different δ\n",
118 | "δ = (0.05, 0.1, 0.15)\n",
119 | "α = 0.33\n",
120 | "s = 0.4\n",
121 | "\n",
122 | "for j in range(3):\n",
123 | " k[0] = 1\n",
124 | " for t in range(49):\n",
125 | " k[t+1] = s * k[t]**α + (1 - δ[j]) * k[t]\n",
126 | " axes[2].plot(k, 'o-', label=rf\"$\\alpha = {α},\\; s = {s},\\; \\delta={δ[j]}$\")\n",
127 | "\n",
128 | "axes[2].set_ylim(0, 18)\n",
129 | "axes[2].set_xlabel('time')\n",
130 | "axes[2].set_ylabel('capital')\n",
131 | "axes[2].grid(lw=0.2)\n",
132 | "axes[2].legend(loc='upper left', frameon=True)\n",
133 | "\n",
134 | "plt.show()"
135 | ]
136 | },
137 | {
138 | "cell_type": "markdown",
139 | "id": "0d76f868",
140 | "metadata": {},
141 | "source": [
142 | "True, the code more or less follows [PEP8](https://www.python.org/dev/peps/pep-0008/).\n",
143 | "\n",
144 | "At the same time, it's very poorly structured.\n",
145 | "\n",
146 | "Let's talk about why that's the case, and what we can do about it.\n",
147 | "\n",
148 | "* magic numbers\n",
149 | "* repetition\n",
150 | "* globals \n",
151 | "\n",
152 | "\n",
153 | "## Revisiting the Example\n",
154 | "\n",
155 | "Here's some code that reproduces the plot above with better coding style."
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": null,
161 | "id": "4b2a139b",
162 | "metadata": {},
163 | "outputs": [],
164 | "source": [
165 | "from itertools import product\n",
166 | "\n",
167 | "def plot_path(ax, αs, s_vals, δs, time_series_length=50):\n",
168 | " \"\"\"\n",
169 | " Add a time series plot to the axes ax for all given parameters.\n",
170 | " \"\"\"\n",
171 | " k = np.empty(time_series_length)\n",
172 | "\n",
173 | " for (α, s, δ) in product(αs, s_vals, δs):\n",
174 | " k[0] = 1\n",
175 | " for t in range(time_series_length-1):\n",
176 | " k[t+1] = s * k[t]**α + (1 - δ) * k[t]\n",
177 | " ax.plot(k, 'o-', label=rf\"$\\alpha = {α},\\; s = {s},\\; \\delta = {δ}$\")\n",
178 | "\n",
179 | " ax.set_xlabel('time')\n",
180 | " ax.set_ylabel('capital')\n",
181 | " ax.set_ylim(0, 18)\n",
182 | " ax.legend(loc='upper left', frameon=True)\n",
183 | "\n",
184 | "fig, axes = plt.subplots(3, 1, figsize=(8, 16))\n",
185 | "\n",
186 | "# Parameters (αs, s_vals, δs)\n",
187 | "set_one = ([0.25, 0.33, 0.45], [0.4], [0.1])\n",
188 | "set_two = ([0.33], [0.3, 0.4, 0.5], [0.1])\n",
189 | "set_three = ([0.33], [0.4], [0.05, 0.1, 0.15])\n",
190 | "\n",
191 | "for (ax, params) in zip(axes, (set_one, set_two, set_three)):\n",
192 | " αs, s_vals, δs = params\n",
193 | " plot_path(ax, αs, s_vals, δs)\n",
194 | "\n",
195 | "plt.show()"
196 | ]
197 | },
198 | {
199 | "cell_type": "markdown",
200 | "id": "edd3f4bd",
201 | "metadata": {},
202 | "source": [
203 | "If you inspect this code, you will see that\n",
204 | "\n",
205 | "* it uses a function to avoid repetition.\n",
206 | "* Global variables are quarantined by collecting them together at the end, not the start of the program.\n",
207 | "* Magic numbers are avoided.\n",
208 | "* The loop at the end where the actual work is done is short and relatively simple."
209 | ]
210 | },
211 | {
212 | "cell_type": "markdown",
213 | "id": "0fe749e2",
214 | "metadata": {},
215 | "source": [
216 | "## Exercises\n",
217 | "\n",
218 | "\n",
219 | "Here is some code that needs improving.\n",
220 | "\n",
221 | "It involves a basic supply and demand problem.\n",
222 | "\n",
223 | "Supply is given by\n",
224 | "\n",
225 | "$$\n",
226 | "q_s(p) = \\exp(\\alpha p) - \\beta.\n",
227 | "$$\n",
228 | "\n",
229 | "The demand curve is\n",
230 | "\n",
231 | "$$\n",
232 | "q_d(p) = \\gamma p^{-\\delta}.\n",
233 | "$$\n",
234 | "\n",
235 | "The values $\\alpha$, $\\beta$, $\\gamma$ and\n",
236 | "$\\delta$ are **parameters**\n",
237 | "\n",
238 | "The equilibrium $p^*$ is the price such that\n",
239 | "$q_d(p) = q_s(p)$.\n",
240 | "\n",
241 | "We can solve for this equilibrium using a root finding algorithm.\n",
242 | "Specifically, we will find the $p$ such that $h(p) = 0$,\n",
243 | "where\n",
244 | "\n",
245 | "$$\n",
246 | "h(p) := q_d(p) - q_s(p)\n",
247 | "$$\n",
248 | "\n",
249 | "This yields the equilibrium price $p^*$. From this we get the\n",
250 | "equilibrium quantity by $q^* = q_s(p^*)$\n",
251 | "\n",
252 | "The parameter values will be\n",
253 | "\n",
254 | "- $\\alpha = 0.1$\n",
255 | "- $\\beta = 1$\n",
256 | "- $\\gamma = 1$\n",
257 | "- $\\delta = 1$"
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": null,
263 | "id": "d9f141fc",
264 | "metadata": {},
265 | "outputs": [],
266 | "source": [
267 | "from scipy.optimize import brentq\n",
268 | "\n",
269 | "# Compute equilibrium\n",
270 | "def h(p):\n",
271 | " return p**(-1) - (np.exp(0.1 * p) - 1) # demand - supply\n",
272 | "\n",
273 | "p_star = brentq(h, 2, 4)\n",
274 | "q_star = np.exp(0.1 * p_star) - 1\n",
275 | "\n",
276 | "print(f'Equilibrium price is {p_star: .2f}')\n",
277 | "print(f'Equilibrium quantity is {q_star: .2f}')"
278 | ]
279 | },
280 | {
281 | "cell_type": "markdown",
282 | "id": "29c0683e",
283 | "metadata": {},
284 | "source": [
285 | "Let's also plot our results."
286 | ]
287 | },
288 | {
289 | "cell_type": "code",
290 | "execution_count": null,
291 | "id": "3c0ca307",
292 | "metadata": {},
293 | "outputs": [],
294 | "source": [
295 | "# Now plot\n",
296 | "grid = np.linspace(2, 4, 100)\n",
297 | "fig, ax = plt.subplots()\n",
298 | "\n",
299 | "qs = np.exp(0.1 * grid) - 1\n",
300 | "qd = grid**(-1)\n",
301 | "\n",
302 | "\n",
303 | "ax.plot(grid, qd, 'b-', lw=2, label='demand')\n",
304 | "ax.plot(grid, qs, 'g-', lw=2, label='supply')\n",
305 | "\n",
306 | "ax.set_xlabel('price')\n",
307 | "ax.set_ylabel('quantity')\n",
308 | "ax.legend(loc='upper center')\n",
309 | "\n",
310 | "plt.show()"
311 | ]
312 | },
313 | {
314 | "cell_type": "markdown",
315 | "id": "9abc4fc9",
316 | "metadata": {},
317 | "source": [
318 | "We also want to consider supply and demand shifts.\n",
319 | "\n",
320 | "For example, let's see what happens when demand shifts up, with $\\gamma$ increasing to $1.25$:"
321 | ]
322 | },
323 | {
324 | "cell_type": "code",
325 | "execution_count": null,
326 | "id": "62c3ecc2",
327 | "metadata": {},
328 | "outputs": [],
329 | "source": [
330 | "# Compute equilibrium\n",
331 | "def h(p):\n",
332 | " return 1.25 * p**(-1) - (np.exp(0.1 * p) - 1)\n",
333 | "\n",
334 | "p_star = brentq(h, 2, 4)\n",
335 | "q_star = np.exp(0.1 * p_star) - 1\n",
336 | "\n",
337 | "print(f'Equilibrium price is {p_star: .2f}')\n",
338 | "print(f'Equilibrium quantity is {q_star: .2f}')"
339 | ]
340 | },
341 | {
342 | "cell_type": "code",
343 | "execution_count": null,
344 | "id": "a0e85313",
345 | "metadata": {},
346 | "outputs": [],
347 | "source": [
348 | "# Now plot\n",
349 | "p_grid = np.linspace(2, 4, 100)\n",
350 | "fig, ax = plt.subplots()\n",
351 | "\n",
352 | "qs = np.exp(0.1 * p_grid) - 1\n",
353 | "qd = 1.25 * p_grid**(-1)\n",
354 | "\n",
355 | "\n",
356 | "ax.plot(grid, qd, 'b-', lw=2, label='demand')\n",
357 | "ax.plot(grid, qs, 'g-', lw=2, label='supply')\n",
358 | "\n",
359 | "ax.set_xlabel('price')\n",
360 | "ax.set_ylabel('quantity')\n",
361 | "ax.legend(loc='upper center')\n",
362 | "\n",
363 | "plt.show()"
364 | ]
365 | },
366 | {
367 | "cell_type": "markdown",
368 | "id": "35a3015f",
369 | "metadata": {},
370 | "source": [
371 | "## Discussion\n",
372 | "\n",
373 | "- What's wrong with this code?\n",
374 | "- How could we improve it?"
375 | ]
376 | }
377 | ],
378 | "metadata": {
379 | "kernelspec": {
380 | "display_name": "Python 3",
381 | "language": "python",
382 | "name": "python3"
383 | }
384 | },
385 | "nbformat": 4,
386 | "nbformat_minor": 5
387 | }
388 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/lecture_1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/lecture_1.pdf
--------------------------------------------------------------------------------
/notebooks/intro_to_python/md_source_files/01_getting_started.md:
--------------------------------------------------------------------------------
1 | ---
2 | jupyter:
3 | jupytext:
4 | text_representation:
5 | extension: .md
6 | format_name: myst
7 | format_version: '1.3'
8 | jupytext_version: 1.13.7
9 | kernelspec:
10 | display_name: Python 3
11 | language: python
12 | name: python3
13 | ---
14 |
15 | # Setting up Your Python Environment
16 |
17 | Aims
18 |
19 | 1. get a Python environment up and running
20 | 1. execute simple Python commands
21 | 1. run a sample program
22 | 1. install the code libraries that underpin these lectures
23 |
24 | ## Anaconda
25 |
26 | The [core Python package](https://www.python.org/downloads/) is easy to install but *not* what you should choose for these lectures.
27 |
28 | These lectures require the entire scientific programming ecosystem, which
29 |
30 | * the core installation doesn't provide
31 | * is painful to install one piece at a time.
32 |
33 | Hence the best approach for our purposes is to install a Python distribution that contains
34 |
35 | 1. the core Python language **and**
36 | 1. compatible versions of the most popular scientific libraries.
37 |
38 | The best such distribution is
39 |
40 | Anaconda is
41 |
42 | * very popular
43 | * cross-platform
44 | * comprehensive
45 | * completely unrelated to the [Nicki Minaj song of the same name](????)
46 |
47 | Anaconda also comes with a great package management system to organize your code libraries.
48 |
49 | +++
50 |
51 | ### Installing Anaconda
52 |
53 | To install Anaconda, [download](https://www.anaconda.com/download/) the binary and follow the instructions.
54 |
55 | Important points:
56 |
57 | * Install the latest version!
58 | * If you are asked during the installation process whether you'd like to make Anaconda your default Python installation, say yes.
59 |
60 |
61 | +++
62 |
63 | ## Jupyter Notebooks
64 |
65 |
66 | [Jupyter](http://jupyter.org/) notebooks are one of the many possible ways to interact with Python and the scientific libraries.
67 |
68 | They use a *browser-based* interface to Python with
69 |
70 | * The ability to write and execute Python commands.
71 | * Formatted output in the browser, including tables, figures, animation, etc.
72 | * The option to mix in formatted text and mathematical expressions.
73 |
74 |
75 | While Jupyter isn't the only way to code in Python, it's great for when you wish to
76 |
77 | * start coding in Python
78 | * test new ideas or interact with small pieces of code
79 | * share or collaborate scientific ideas with students or colleagues
80 |
81 | +++
82 |
83 | ### Starting the Jupyter Notebook
84 |
85 |
86 | * search for Jupyter in your applications menu, or
87 | * open up a terminal and type `jupyter notebook`
88 |
89 |
90 | +++
91 |
92 | Let's now cover some basics:
93 |
94 |
95 | * Running Cells
96 | * Modal Editing
97 | * Inserting Unicode
98 | * Tab Completion
99 | * On-Line Help
100 | * Adding rich text and LaTeX
101 | * Installing Libraries
102 |
103 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/md_source_files/03_functions.md:
--------------------------------------------------------------------------------
1 | ---
2 | jupytext:
3 | text_representation:
4 | extension: .md
5 | format_name: myst
6 | kernelspec:
7 | display_name: Python 3
8 | language: python
9 | name: python3
10 | ---
11 |
12 | # Functions
13 |
14 |
15 | ## Overview
16 |
17 | One construct that's extremely useful and provided by almost all programming
18 | languages is **functions**.
19 |
20 | We have already met several functions, such as
21 |
22 | * the `sqrt()` function from NumPy and
23 | * the built-in `print()` function
24 |
25 | In this lecture we'll treat functions systematically and begin to learn just how
26 | useful and important they are.
27 |
28 | One of the things we will learn to do is build our own user-defined functions
29 |
30 | We will use the following imports.
31 |
32 | ```{code-cell} ipython
33 | %matplotlib inline
34 | import numpy as np
35 | import matplotlib.pyplot as plt
36 | ```
37 |
38 | ## Function Basics
39 |
40 | A function is a named section of a program that implements a specific task.
41 |
42 | Many functions exist already and we can use them off the shelf.
43 |
44 | First we review these functions and then discuss how we can build our own.
45 |
46 | ### Built-In Functions
47 |
48 | Python has a number of *built-in* functions that are available without `import`.
49 |
50 | We have already met some
51 |
52 | ```{code-cell} python3
53 | max(19, 20)
54 | ```
55 |
56 | ```{code-cell} python3
57 | print('foobar')
58 | ```
59 |
60 | ```{code-cell} python3
61 | str(22)
62 | ```
63 |
64 | ```{code-cell} python3
65 | type(22)
66 | ```
67 |
68 | Two more useful built-in functions are `any()` and `all()`
69 |
70 | ```{code-cell} python3
71 | bools = False, True, True
72 | all(bools) # True if all are True and False otherwise
73 | ```
74 |
75 | ```{code-cell} python3
76 | any(bools) # False if all are False and True otherwise
77 | ```
78 |
79 |
80 | ### Third Party Functions
81 |
82 | If the built-in functions don't cover what we need, we either need to import
83 | functions or create our own.
84 |
85 | Examples of importing and using functions
86 | were given in the {doc}`previous lecture `
87 |
88 | Here's another one, which tests whether a given year is a leap year:
89 |
90 | ```{code-cell} python3
91 | import calendar
92 |
93 | calendar.isleap(2020)
94 | ```
95 |
96 | ## Defining Functions
97 |
98 | In many instances, it is useful to be able to define our own functions.
99 |
100 | This will become clearer as you see more examples.
101 |
102 | Let's start by discussing how it's done.
103 |
104 | ### Syntax
105 |
106 | Here's a very simple Python function, that implements the mathematical function
107 | $f(x) = 2 x + 1$
108 |
109 | ```{code-cell} python3
110 | def f(x):
111 | return 2 * x + 1
112 | ```
113 |
114 | Now that we've *defined* this function, let's *call* it and check whether it
115 | does what we expect:
116 |
117 | ```{code-cell} python3
118 | f(1)
119 | ```
120 |
121 | ```{code-cell} python3
122 | f(10)
123 | ```
124 |
125 | Here's a longer function, that computes the absolute value of a given number.
126 |
127 | (Such a function already exists as a built-in, but let's write our own for the
128 | exercise.)
129 |
130 | ```{code-cell} python3
131 | def new_abs_function(x):
132 |
133 | if x < 0:
134 | abs_value = -x
135 | else:
136 | abs_value = x
137 |
138 | return abs_value
139 | ```
140 |
141 | Let's review the syntax here.
142 |
143 | * `def` is a Python keyword used to start function definitions.
144 | * `def new_abs_function(x):` indicates that the function is called `new_abs_function` and that it has a single argument `x`.
145 | * The indented code is a code block called the *function body*.
146 | * The `return` keyword indicates that `abs_value` is the object that should be returned to the calling code.
147 |
148 | This whole function definition is read by the Python interpreter and stored in memory.
149 |
150 | Let's call it to check that it works:
151 |
152 | ```{code-cell} python3
153 | print(new_abs_function(3))
154 | print(new_abs_function(-3))
155 | ```
156 |
157 | ### Why Write Functions?
158 |
159 | User-defined functions are important for improving the clarity of your code by
160 |
161 | * separating different strands of logic
162 | * facilitating code reuse
163 |
164 |
165 | ## Applications
166 |
167 | ### Random Draws
168 |
169 | Consider again this code from the "Getting Started" lecture
170 |
171 | ```{code-cell} python3
172 | ts_length = 100
173 | ϵ_values = [] # empty list
174 |
175 | for i in range(ts_length):
176 | e = np.random.randn()
177 | ϵ_values.append(e)
178 |
179 | plt.plot(ϵ_values)
180 | plt.show()
181 | ```
182 |
183 | We will break this program into two parts:
184 |
185 | 1. A user-defined function that generates a list of random variables.
186 | 1. The main part of the program that
187 | 1. calls this function to get data
188 | 1. plots the data
189 |
190 | This is accomplished in the next program
191 |
192 | ```{code-cell} python3
193 | def generate_data(n):
194 | ϵ_values = []
195 | for i in range(n):
196 | e = np.random.randn()
197 | ϵ_values.append(e)
198 | return ϵ_values
199 |
200 | data = generate_data(100)
201 | plt.plot(data)
202 | plt.show()
203 | ```
204 |
205 | When the interpreter gets to the expression `generate_data(100)`, it executes the function body with `n` set equal to 100.
206 |
207 | The net result is that the name `data` is *bound* to the list `ϵ_values` returned by the function.
208 |
209 | ### Adding Conditions
210 |
211 | Our function `generate_data()` is rather limited.
212 |
213 | Let's make it slightly more useful by giving it the ability to return either standard normals or uniform random variables on $(0, 1)$ as required.
214 |
215 | This is achieved in the next piece of code.
216 |
217 | ```{code-cell} python3
218 | def generate_data(n, generator_type):
219 | ϵ_values = []
220 | for i in range(n):
221 | if generator_type == 'U':
222 | e = np.random.uniform(0, 1)
223 | else:
224 | e = np.random.randn()
225 | ϵ_values.append(e)
226 | return ϵ_values
227 |
228 | data = generate_data(100, 'U')
229 | plt.plot(data)
230 | plt.show()
231 | ```
232 |
233 | Hopefully, the syntax of the if/else clause is self-explanatory, with indentation again delimiting the extent of the code blocks.
234 |
235 | Notes
236 |
237 | * We are passing the argument `U` as a string, which is why we write it as `'U'`.
238 | * Notice that equality is tested with the `==` syntax, not `=`.
239 | * For example, the statement `a = 10` assigns the name `a` to the value `10`.
240 | * The expression `a == 10` evaluates to either `True` or `False`, depending on the value of `a`.
241 |
242 | Now, there are several ways that we can simplify the code above.
243 |
244 | For example, we can get rid of the conditionals all together by just passing the desired generator type *as a function*.
245 |
246 | To understand this, consider the following version.
247 |
248 | ```{code-cell} python3
249 | def generate_data(n, generator_type):
250 | ϵ_values = []
251 | for i in range(n):
252 | e = generator_type()
253 | ϵ_values.append(e)
254 | return ϵ_values
255 |
256 | data = generate_data(100, np.random.uniform)
257 | plt.plot(data)
258 | plt.show()
259 | ```
260 |
261 | Now, when we call the function `generate_data()`, we pass `np.random.uniform`
262 | as the second argument.
263 |
264 | This object is a *function*.
265 |
266 | When the function call `generate_data(100, np.random.uniform)` is executed,
267 | Python runs the function code block with `n` equal to 100 and the name
268 | `generator_type` "bound" to the function `np.random.uniform`.
269 |
270 | * While these lines are executed, the names `generator_type` and `np.random.uniform` are "synonyms", and can be used in identical ways.
271 |
272 | This principle works more generally---for example, consider the following piece of code
273 |
274 | ```{code-cell} python3
275 | max(7, 2, 4) # max() is a built-in Python function
276 | ```
277 |
278 | ```{code-cell} python3
279 | m = max
280 | m(7, 2, 4)
281 | ```
282 |
283 | Here we created another name for the built-in function `max()`, which could
284 | then be used in identical ways.
285 |
286 | In the context of our program, the ability to bind new names to functions
287 | means that there is no problem *passing a function as an argument to another
288 | function*---as we did above.
289 |
290 |
291 | +++
292 |
293 | ## Exercises
294 |
295 | +++
296 |
297 | ### Ex. 1
298 |
299 | Recall that $n!$ is read as "$n$ factorial" and defined as
300 | $n! = n \times (n - 1) \times \cdots \times 2 \times 1$.
301 |
302 | Write a function `factorial` such that `factorial(n)` returns $n!$
303 | for any positive integer $n$.
304 |
305 | +++
306 |
307 | ### Ex. 2
308 |
309 | The [binomial random
310 | variable](https://en.wikipedia.org/wiki/Binomial_distribution) $Y \sim Bin(n,
311 | p)$ represents the number of successes in $n$ binary trials, where each trial
312 | succeeds with probability $p$.
313 |
314 | Without any import besides `from numpy.random import uniform`, write a function
315 | `binomial_rv` such that `binomial_rv(n, p)` generates one draw of $Y$.
316 |
317 | Hint: If $U$ is uniform on $(0, 1)$ and $p \in (0,1)$, then the expression `U < p` evaluates to `True` with probability $p$.
318 |
319 | +++
320 |
321 | ```
322 | solutions below
323 | solutions below
324 | solutions below
325 | solutions below
326 | solutions below
327 | solutions below
328 | solutions below
329 | solutions below
330 | solutions below
331 | solutions below
332 | solutions below
333 | solutions below
334 | solutions below
335 | solutions below
336 | solutions below
337 | solutions below
338 | solutions below
339 | solutions below
340 | solutions below
341 | solutions below
342 | solutions below
343 | ```
344 |
345 |
346 | ## Solutions
347 |
348 |
349 | ### Solution to Ex. 1
350 |
351 |
352 | Here's one solution.
353 |
354 | ```{code-cell} python3
355 | def factorial(n):
356 | k = 1
357 | for i in range(n):
358 | k = k * (i + 1)
359 | return k
360 |
361 | factorial(4)
362 | ```
363 |
364 | ### Solution to Ex. 2
365 |
366 | ```{code-cell} python3
367 | from numpy.random import uniform
368 |
369 | def binomial_rv(n, p):
370 | count = 0
371 | for i in range(n):
372 | U = uniform()
373 | if U < p:
374 | count = count + 1 # Or count += 1
375 | return count
376 |
377 | binomial_rv(10, 0.5)
378 | ```
379 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/md_source_files/04_python_essentials.md:
--------------------------------------------------------------------------------
1 | ---
2 | jupytext:
3 | text_representation:
4 | extension: .md
5 | format_name: myst
6 | kernelspec:
7 | display_name: Python 3
8 | language: python
9 | name: python3
10 | ---
11 |
12 |
13 | # Python Essentials
14 |
15 | Now let's cover some core features of Python in a more systematic way.
16 |
17 | +++
18 |
19 | ## Data Types
20 |
21 | Programs typically track a range of data types.
22 |
23 | For example, `1.5` is a floating point number, while `1` is an integer.
24 |
25 | Programs need to distinguish between these two types for various reasons.
26 |
27 | One is that they are stored in memory differently.
28 |
29 | Another is that arithmetic operations are different
30 |
31 | * For example, floating point arithmetic is implemented on most machines by a
32 | specialized Floating Point Unit (FPU).
33 |
34 | In general, floats are more informative but arithmetic operations on integers
35 | are faster and more accurate.
36 |
37 | Python provides numerous other built-in Python data types, some of which we've already met
38 |
39 | * strings, lists, etc.
40 |
41 | Let's learn a bit more about them.
42 |
43 | +++
44 |
45 | ### Primitive Data Types
46 |
47 | One simple data type is **Boolean values**, which can be either `True` or `False`
48 |
49 | ```{code-cell} python3
50 | x = True
51 | x
52 | ```
53 |
54 | We can check the type of any object in memory using the `type()` function.
55 |
56 | ```{code-cell} python3
57 | type(x)
58 | ```
59 |
60 | In the next line of code, the interpreter evaluates the expression on the right of = and binds y to this value
61 |
62 | ```{code-cell} python3
63 | y = 100 < 10
64 | y
65 | ```
66 |
67 | ```{code-cell} python3
68 | type(y)
69 | ```
70 |
71 | In arithmetic expressions, `True` is converted to `1` and `False` is converted `0`.
72 |
73 | This is called **Boolean arithmetic** and is often useful in programming.
74 |
75 | Here are some examples
76 |
77 | ```{code-cell} python3
78 | x + y
79 | ```
80 |
81 | ```{code-cell} python3
82 | x * y
83 | ```
84 |
85 | ```{code-cell} python3
86 | True + True
87 | ```
88 |
89 | ```{code-cell} python3
90 | bools = [True, True, False, True] # List of Boolean values
91 |
92 | sum(bools)
93 | ```
94 |
95 | Complex numbers are another primitive data type in Python
96 |
97 | ```{code-cell} python3
98 | x = complex(1, 2)
99 | y = complex(2, 1)
100 | print(x * y)
101 |
102 | type(x)
103 | ```
104 |
105 | ### Containers
106 |
107 | Python has several basic types for storing collections of (possibly heterogeneous) data.
108 |
109 | We've already discussed lists.
110 |
111 | A related data type is **tuples**, which are "immutable" lists
112 |
113 | ```{code-cell} python3
114 | x = ('a', 'b') # Parentheses instead of the square brackets
115 | x = 'a', 'b' # Or no brackets --- the meaning is identical
116 | x
117 | ```
118 |
119 | ```{code-cell} python3
120 | type(x)
121 | ```
122 |
123 | In Python, an object is called **immutable** if, once created, the object cannot be changed.
124 |
125 | Conversely, an object is **mutable** if it can still be altered after creation.
126 |
127 | Python lists are mutable
128 |
129 | ```{code-cell} python3
130 | x = [1, 2]
131 | x[0] = 10
132 | x
133 | ```
134 |
135 | But tuples are not
136 |
137 | ```{code-cell} python3
138 | ---
139 | tags: [raises-exception]
140 | ---
141 | x = (1, 2)
142 | x[0] = 10
143 | ```
144 |
145 | We'll say more about the role of mutable and immutable data a bit later.
146 |
147 |
148 | ## Iterating
149 |
150 | One of the most important tasks in computing is stepping through a
151 | sequence of data and performing a given action.
152 |
153 | One of Python's strengths is its simple, flexible interface to this kind of iteration via
154 | the `for` loop.
155 |
156 | ### Looping over Different Objects
157 |
158 | Many Python objects are "iterable", in the sense that they can be looped over.
159 |
160 | To give an example, let's write the file us_cities.txt, which lists US cities and their population, to the present working directory.
161 |
162 | ```{code-cell} ipython
163 | %%file us_cities.txt
164 | new york: 8244910
165 | los angeles: 3819702
166 | chicago: 2707120
167 | houston: 2145146
168 | philadelphia: 1536471
169 | phoenix: 1469471
170 | san antonio: 1359758
171 | san diego: 1326179
172 | dallas: 1223229
173 | ```
174 |
175 | Suppose that we want to make the information more readable, by capitalizing names and adding commas to mark thousands.
176 |
177 | The program below reads the data in and makes the conversion:
178 |
179 | ```{code-cell} python3
180 | data_file = open('us_cities.txt', 'r')
181 | for line in data_file:
182 | city, population = line.split(':') # Tuple unpacking
183 | city = city.title() # Capitalize city names
184 | population = f'{int(population):,}' # Add commas to numbers
185 | print(city.ljust(15) + population)
186 | data_file.close()
187 | ```
188 |
189 | ### Looping Techniques
190 |
191 | Python provides some facilities to simplify looping
192 |
193 | One is `zip()`, which is used for stepping through pairs from two sequences.
194 |
195 | For example, try running the following code
196 |
197 | ```{code-cell} python3
198 | countries = ('Japan', 'Korea', 'China')
199 | cities = ('Tokyo', 'Seoul', 'Beijing')
200 | for country, city in zip(countries, cities):
201 | print(f'The capital of {country} is {city}')
202 | ```
203 |
204 | Another useful one is `enumerate()` --- here's an example
205 |
206 |
207 | ```{code-cell} python3
208 | countries = ('Japan', 'Korea', 'China')
209 | cities = ('Tokyo', 'Seoul', 'Beijing')
210 | for i, country in enumerate(countries):
211 | print(f'The capital of {country} is {cities[i]}')
212 | ```
213 |
214 | ### List Comprehensions
215 |
216 |
217 | We can also simplify the code for generating the list of random draws considerably by using something called a *list comprehension*.
218 |
219 | [List comprehensions](https://en.wikipedia.org/wiki/List_comprehension) are an elegant Python tool for creating lists.
220 |
221 | Consider the following example, where the list comprehension is on the
222 | right-hand side of the second line
223 |
224 | ```{code-cell} python3
225 | animals = ['dog', 'cat', 'bird']
226 | plurals = [animal + 's' for animal in animals]
227 | plurals
228 | ```
229 |
230 | Here's another example
231 |
232 | ```{code-cell} python3
233 | range(8)
234 | ```
235 |
236 | ```{code-cell} python3
237 | doubles = [2 * x for x in range(8)]
238 | doubles
239 | ```
240 |
241 | ## Comparisons and Logical Operators
242 |
243 | ### Comparisons
244 |
245 |
246 | Many different kinds of expressions evaluate to one of the Boolean values (i.e., `True` or `False`).
247 |
248 | A common type is comparisons, such as
249 |
250 | ```{code-cell} python3
251 | x, y = 1, 2
252 | x < y
253 | ```
254 |
255 | ```{code-cell} python3
256 | x > y
257 | ```
258 |
259 | One of the nice features of Python is that we can *chain* inequalities
260 |
261 | ```{code-cell} python3
262 | 1 < 2 < 3
263 | ```
264 |
265 | ```{code-cell} python3
266 | 1 <= 2 <= 3
267 | ```
268 |
269 | As we saw earlier, when testing for equality we use `==`
270 |
271 | ```{code-cell} python3
272 | x = 1 # Assignment
273 | x == 2 # Comparison
274 | ```
275 |
276 | For "not equal" use `!=`
277 |
278 | ```{code-cell} python3
279 | 1 != 2
280 | ```
281 |
282 | Note that when testing conditions, we can use **any** valid Python expression
283 |
284 | ```{code-cell} python3
285 | x = 'yes' if 42 else 'no'
286 | x
287 | ```
288 |
289 | ```{code-cell} python3
290 | x = 'yes' if [] else 'no'
291 | x
292 | ```
293 |
294 | What's going on here?
295 |
296 | The rule is:
297 |
298 | * Expressions that evaluate to zero, empty sequences or containers (strings, lists, etc.) and `None` are all equivalent to `False`.
299 | * for example, `[]` and `()` are equivalent to `False` in an `if` clause
300 | * All other values are equivalent to `True`.
301 | * for example, `42` is equivalent to `True` in an `if` clause
302 |
303 | ### Combining Expressions
304 |
305 | ```{index} single: Python; Logical Expressions
306 | ```
307 |
308 | We can combine expressions using `and`, `or` and `not`.
309 |
310 | These are the standard logical connectives (conjunction, disjunction and denial)
311 |
312 | ```{code-cell} python3
313 | 1 < 2 and 'f' in 'foo'
314 | ```
315 |
316 | ```{code-cell} python3
317 | 1 < 2 and 'g' in 'foo'
318 | ```
319 |
320 | ```{code-cell} python3
321 | 1 < 2 or 'g' in 'foo'
322 | ```
323 |
324 | ```{code-cell} python3
325 | not True
326 | ```
327 |
328 | ```{code-cell} python3
329 | not not True
330 | ```
331 |
332 | Remember
333 |
334 | * `P and Q` is `True` if both are `True`, else `False`
335 | * `P or Q` is `False` if both are `False`, else `True`
336 |
337 |
338 | ## Keyword Arguments
339 |
340 | We previously came across the statement `plt.plot(x, 'b-', label="white noise")`.
341 |
342 | In this call to Matplotlib's `plot` function, notice that the last argument is passed in `name=argument` syntax.
343 |
344 | This is called a *keyword argument*, with `label` being the keyword.
345 |
346 | Non-keyword arguments are called *positional arguments*, since their meaning
347 | is determined by order
348 |
349 | * `plot(x, 'b-', label="white noise")` is different from `plot('b-', x, label="white noise")`
350 |
351 | Keyword arguments are particularly useful when a function has a lot of arguments, in which case it's hard to remember the right order.
352 |
353 | You can adopt keyword arguments in user-defined functions with no difficulty.
354 |
355 | The next example illustrates the syntax
356 |
357 | ```{code-cell} python3
358 | def f(x, a=1, b=1):
359 | return a + b * x
360 | ```
361 |
362 | The keyword argument values we supplied in the definition of `f` become the default values
363 |
364 | ```{code-cell} python3
365 | f(2)
366 | ```
367 |
368 | They can be modified as follows
369 |
370 | ```{code-cell} python3
371 | f(2, a=4, b=5)
372 | ```
373 |
374 | ## Coding Style and PEP8
375 |
376 |
377 | To learn more about the Python programming philosophy type `import this` at the prompt.
378 |
379 | Among other things, Python strongly favors consistency in programming style.
380 |
381 | The standard style is set out in [PEP8](https://www.python.org/dev/peps/pep-0008/).
382 |
383 | (Occasionally we'll deviate from PEP8 in these lectures to better match mathematical notation)
384 |
385 |
386 | +++
387 |
388 | ## Exercises
389 |
390 |
391 | +++
392 |
393 | ### Ex. 1
394 |
395 | Given two numeric lists or tuples `x_vals` and `y_vals` of equal length, compute
396 | their inner product using `zip()`.
397 |
398 |
399 | +++
400 |
401 |
402 | ### Ex. 2
403 |
404 | In one line, count the number of even numbers in 0,...,99.
405 |
406 | * Hint: `x % 2` returns 0 if `x` is even, 1 otherwise.
407 |
408 |
409 | +++
410 |
411 | ### Ex. 3
412 |
413 | Given `pairs = ((2, 5), (4, 2), (9, 8), (12, 10))`, count the number of pairs `(a, b)`
414 | such that both `a` and `b` are even.
415 |
416 |
417 | +++
418 |
419 |
420 | ### Ex. 4
421 |
422 | Write a function that takes a string as an argument and returns the number of
423 | capital letters in the string.
424 |
425 |
426 | +++
427 |
428 |
429 | ```
430 | solutions below
431 | solutions below
432 | solutions below
433 | solutions below
434 | solutions below
435 | solutions below
436 | solutions below
437 | solutions below
438 | solutions below
439 | solutions below
440 | solutions below
441 | solutions below
442 | solutions below
443 | solutions below
444 | solutions below
445 | solutions below
446 | solutions below
447 | solutions below
448 | solutions below
449 | solutions below
450 | solutions below
451 | ```
452 |
453 |
454 | ## Solutions
455 |
456 | ### Solution to Ex. 1
457 |
458 | Here's one possible solution
459 |
460 | ```{code-cell} python3
461 | x_vals = [1, 2, 3]
462 | y_vals = [1, 1, 1]
463 | sum([x * y for x, y in zip(x_vals, y_vals)])
464 | ```
465 |
466 | This also works
467 |
468 | ```{code-cell} python3
469 | sum(x * y for x, y in zip(x_vals, y_vals))
470 | ```
471 |
472 | ### Solution to Ex. 2
473 |
474 | One solution is
475 |
476 | ```{code-cell} python3
477 | sum([x % 2 == 0 for x in range(100)])
478 | ```
479 |
480 | This also works:
481 |
482 | ```{code-cell} python3
483 | sum(x % 2 == 0 for x in range(100))
484 | ```
485 |
486 | Some less natural alternatives that nonetheless help to illustrate the
487 | flexibility of list comprehensions are
488 |
489 | ```{code-cell} python3
490 | len([x for x in range(100) if x % 2 == 0])
491 | ```
492 |
493 | and
494 |
495 | ```{code-cell} python3
496 | sum([1 for x in range(100) if x % 2 == 0])
497 | ```
498 |
499 | ### Solution to Ex. 3
500 |
501 | Here's one possibility
502 |
503 | ```{code-cell} python3
504 | pairs = ((2, 5), (4, 2), (9, 8), (12, 10))
505 | sum([x % 2 == 0 and y % 2 == 0 for x, y in pairs])
506 | ```
507 |
508 | ### Solution to Ex. 4
509 |
510 | Here's one solution:
511 |
512 | ```{code-cell} python3
513 | def f(string):
514 | count = 0
515 | for letter in string:
516 | if letter == letter.upper() and letter.isalpha():
517 | count += 1
518 | return count
519 |
520 | f('The Rain in Spain')
521 | ```
522 |
523 | An alternative, more pythonic solution:
524 |
525 | ```{code-cell} python3
526 | def count_uppercase_chars(s):
527 | return sum([c.isupper() for c in s])
528 |
529 | count_uppercase_chars('The Rain in Spain')
530 | ```
531 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/md_source_files/07_scipy.md:
--------------------------------------------------------------------------------
1 | ---
2 | jupytext:
3 | text_representation:
4 | extension: .md
5 | format_name: myst
6 | kernelspec:
7 | display_name: Python 3
8 | language: python
9 | name: python3
10 | ---
11 |
12 | ## Overview
13 |
14 | [SciPy](http://www.scipy.org) builds on top of NumPy to provide common tools for scientific programming such as
15 |
16 | * [linear algebra](http://docs.scipy.org/doc/scipy/reference/linalg.html)
17 | * [numerical integration](http://docs.scipy.org/doc/scipy/reference/integrate.html)
18 | * [interpolation](http://docs.scipy.org/doc/scipy/reference/interpolate.html)
19 | * [optimization](http://docs.scipy.org/doc/scipy/reference/optimize.html)
20 | * [distributions and random number generation](http://docs.scipy.org/doc/scipy/reference/stats.html)
21 | * [signal processing](http://docs.scipy.org/doc/scipy/reference/signal.html)
22 | * etc., etc
23 |
24 | +++
25 |
26 | Many SciPy routines are thin wrappers around industry-standard Fortran libraries such as [LAPACK](https://en.wikipedia.org/wiki/LAPACK), [BLAS](https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms), etc.
27 |
28 | It's not really necessary to "learn" SciPy as a whole.
29 |
30 | In this lecture, we aim only to highlight some useful parts of the package.
31 |
32 | The functionality of SciPy is in its sub-packages
33 |
34 | * `scipy.optimize`, `scipy.integrate`, `scipy.stats`, etc.
35 |
36 | Let's explore some of the major sub-packages.
37 |
38 | +++
39 |
40 | ## Statistics
41 |
42 | The `scipy.stats` subpackage supplies
43 |
44 | * numerous random variable objects (densities, cumulative distributions, random sampling, etc.)
45 | * some estimation procedures
46 | * some statistical tests
47 |
48 | +++
49 |
50 | ### Random Variables and Distributions
51 |
52 | Recall that `numpy.random` provides functions for generating random variables
53 |
54 | ```{code-cell} python3
55 | import numpy as np
56 | np.random.beta(5, 5, size=3)
57 | ```
58 |
59 | This generates a draw from the distribution with the density function below when `a, b = 5, 5`
60 |
61 | $$
62 | f(x; a, b) = \frac{x^{(a - 1)} (1 - x)^{(b - 1)}}
63 | {\int_0^1 u^{(a - 1)} (1 - u)^{(b - 1)} du}
64 | \qquad (0 \leq x \leq 1)
65 | $$
66 |
67 | Sometimes we need access to the density itself, or the cdf, the quantiles, etc.
68 |
69 | For this, we can use `scipy.stats`, which provides all of this functionality as well as random number generation in a single consistent interface.
70 |
71 | Here's an example of usage
72 |
73 | ```{code-cell} ipython
74 | %matplotlib inline
75 | from scipy.stats import beta
76 | import matplotlib.pyplot as plt
77 |
78 | q = beta(5, 5) # Beta(a, b), with a = b = 5
79 | obs = q.rvs(2000) # 2000 observations
80 | grid = np.linspace(0.01, 0.99, 100)
81 |
82 | fig, ax = plt.subplots()
83 | ax.hist(obs, bins=40, density=True)
84 | ax.plot(grid, q.pdf(grid), 'k-', linewidth=2)
85 | plt.show()
86 | ```
87 |
88 | The object `q` that represents the distribution has additional useful methods, including
89 |
90 | ```{code-cell} python3
91 | q.cdf(0.4) # Cumulative distribution function
92 | ```
93 |
94 | ```{code-cell} python3
95 | q.ppf(0.8) # Quantile (inverse cdf) function
96 | ```
97 |
98 | ```{code-cell} python3
99 | q.mean()
100 | ```
101 |
102 |
103 | ## Roots and Fixed Points
104 |
105 | A **root** or **zero** of a real function $f$ on $[a,b]$ is an $x \in [a, b]$ such that $f(x)=0$.
106 |
107 | For example, if we plot the function
108 |
109 | $$
110 | f(x) = \sin(4 (x - 1/4)) + x + x^{20} - 1
111 | $$
112 |
113 | with $x \in [0,1]$ we get
114 |
115 | ```{code-cell} python3
116 | f = lambda x: np.sin(4 * (x - 1/4)) + x + x**20 - 1
117 | x = np.linspace(0, 1, 100)
118 |
119 | fig, ax = plt.subplots()
120 | ax.plot(x, f(x), label='$f(x)$')
121 | ax.axhline(ls='--', c='k')
122 | ax.set_xlabel('$x$', fontsize=12)
123 | ax.set_ylabel('$f(x)$', fontsize=12)
124 | ax.legend(fontsize=12)
125 | plt.show()
126 | ```
127 |
128 | The unique root is approximately 0.408.
129 |
130 | Let's consider some numerical techniques for finding roots.
131 |
132 | +++
133 |
134 | ### Bisection
135 |
136 | One of the most common algorithms for numerical root-finding is *bisection*.
137 |
138 | To understand the idea, recall the well-known game where
139 |
140 | * Player A thinks of a secret number between 1 and 100
141 | * Player B asks if it's less than 50
142 | * If yes, B asks if it's less than 25
143 | * If no, B asks if it's less than 75
144 |
145 | And so on.
146 |
147 | This is bisection.
148 |
149 | SciPy provides a bisection function.
150 |
151 |
152 | ```{code-cell} python3
153 | from scipy.optimize import bisect
154 |
155 | bisect(f, 0, 1)
156 | ```
157 |
158 | ### The Newton-Raphson Method
159 |
160 |
161 | Another very common root-finding algorithm is the [Newton-Raphson method](https://en.wikipedia.org/wiki/Newton%27s_method).
162 |
163 | In SciPy this algorithm is implemented by `scipy.optimize.newton`.
164 |
165 | Unlike bisection, the Newton-Raphson method uses local slope information in an attempt to increase the speed of convergence.
166 |
167 | Let's investigate this using the same function $f$ defined above.
168 |
169 | With a suitable initial condition for the search we get convergence:
170 |
171 | ```{code-cell} python3
172 | from scipy.optimize import newton
173 |
174 | newton(f, 0.2) # Start the search at initial condition x = 0.2
175 | ```
176 |
177 | But other initial conditions lead to failure of convergence:
178 |
179 | ```{code-cell} python3
180 | newton(f, 0.7) # Start the search at x = 0.7 instead
181 | ```
182 |
183 | ### Hybrid Methods
184 |
185 | A general principle of numerical methods is as follows:
186 |
187 | * If you have specific knowledge about a given problem, you might be able to exploit it to generate efficiency.
188 | * If not, then the choice of algorithm involves a trade-off between speed and robustness.
189 |
190 | In practice, most default algorithms for root-finding, optimization and fixed points use *hybrid* methods.
191 |
192 | These methods typically combine a fast method with a robust method in the following manner:
193 |
194 | 1. Attempt to use a fast method
195 | 1. Check diagnostics
196 | 1. If diagnostics are bad, then switch to a more robust algorithm
197 |
198 | In `scipy.optimize`, the function `brentq` is such a hybrid method and a good default
199 |
200 | ```{code-cell} python3
201 | from scipy.optimize import brentq
202 |
203 | brentq(f, 0, 1)
204 | ```
205 |
206 | Here the correct solution is found and the speed is better than bisection:
207 |
208 | ```{code-cell} ipython
209 | %timeit brentq(f, 0, 1)
210 | ```
211 |
212 | ```{code-cell} ipython
213 | %timeit bisect(f, 0, 1)
214 | ```
215 |
216 | ## Optimization
217 |
218 | Most numerical packages provide only functions for *minimization*.
219 |
220 | Maximization can be performed by recalling that the maximizer of a function $f$ on domain $D$ is
221 | the minimizer of $-f$ on $D$.
222 |
223 | Minimization is closely related to root-finding: For smooth functions, interior optima correspond to roots of the first derivative.
224 |
225 | The speed/robustness trade-off described above is present with numerical optimization too.
226 |
227 | Unless you have some prior information you can exploit, it's usually best to use hybrid methods.
228 |
229 | For constrained, univariate (i.e., scalar) minimization, a good hybrid option is `fminbound`
230 |
231 | ```{code-cell} python3
232 | from scipy.optimize import fminbound
233 |
234 | fminbound(lambda x: x**2, -1, 2) # Search in [-1, 2]
235 | ```
236 |
237 | ## Integration
238 |
239 | Most numerical integration methods work by computing the integral of an approximating polynomial.
240 |
241 | The resulting error depends on how well the polynomial fits the integrand, which in turn depends on how "regular" the integrand is.
242 |
243 | In SciPy, the relevant module for numerical integration is `scipy.integrate`.
244 |
245 | A good default for univariate integration is `quad`
246 |
247 | ```{code-cell} python3
248 | from scipy.integrate import quad
249 |
250 | integral, error = quad(lambda x: x**2, 0, 1)
251 | integral
252 | ```
253 |
254 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/md_source_files/08_writing_good_code.md:
--------------------------------------------------------------------------------
1 | ---
2 | jupytext:
3 | text_representation:
4 | extension: .md
5 | format_name: myst
6 | kernelspec:
7 | display_name: Python 3
8 | language: python
9 | name: python3
10 | ---
11 |
12 |
13 | # Writing Good Code
14 |
15 | ```{epigraph}
16 | "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." -- Martin Fowler
17 | ```
18 |
19 | +++
20 |
21 | ## Overview
22 |
23 | When computer programs are small, poorly written code is not overly costly.
24 |
25 | But more data, more sophisticated models, and more computer power are enabling us to take on more challenging problems that involve writing longer programs.
26 |
27 | For such programs, investment in good coding practices will pay high returns.
28 |
29 | The main payoffs are higher productivity and faster code.
30 |
31 | In this lecture, we review some elements of good coding practice.
32 |
33 | We also touch on modern developments in scientific computing --- such as just in time compilation --- and how they affect good program design.
34 |
35 | +++
36 |
37 | ## An Example of Poor Code
38 |
39 | Let's have a look at some poorly written code.
40 |
41 | The job of the code is to generate and plot time series of the simplified Solow model
42 |
43 | $$
44 | k_{t+1} = s k_t^{\alpha} + (1 - \delta) k_t,
45 | \quad t = 0, 1, 2, \ldots
46 | $$
47 |
48 | Here
49 |
50 | * $k_t$ is capital at time $t$ and
51 | * $s, \alpha, \delta$ are parameters (savings, a productivity parameter and depreciation)
52 |
53 | For each parameterization, the code
54 |
55 | 1. sets $k_0 = 1$
56 | 1. iterates using the rule above to produce a sequence $k_0, k_1, k_2 \ldots , k_T$
57 | 1. plots the sequence
58 |
59 | The plots will be grouped into three subfigures.
60 |
61 | In each subfigure, two parameters are held fixed while another varies
62 |
63 | ```{code-cell} ipython
64 | %matplotlib inline
65 | import numpy as np
66 | import matplotlib.pyplot as plt
67 |
68 | # Allocate memory for time series
69 | k = np.empty(50)
70 |
71 | fig, axes = plt.subplots(3, 1, figsize=(8, 16))
72 |
73 | # Trajectories with different α
74 | δ = 0.1
75 | s = 0.4
76 | α = (0.25, 0.33, 0.45)
77 |
78 | for j in range(3):
79 | k[0] = 1
80 | for t in range(49):
81 | k[t+1] = s * k[t]**α[j] + (1 - δ) * k[t]
82 | axes[0].plot(k, 'o-', label=rf"$\alpha = {α[j]},\; s = {s},\; \delta={δ}$")
83 |
84 | axes[0].grid(lw=0.2)
85 | axes[0].set_ylim(0, 18)
86 | axes[0].set_xlabel('time')
87 | axes[0].set_ylabel('capital')
88 | axes[0].legend(loc='upper left', frameon=True)
89 |
90 | # Trajectories with different s
91 | δ = 0.1
92 | α = 0.33
93 | s = (0.3, 0.4, 0.5)
94 |
95 | for j in range(3):
96 | k[0] = 1
97 | for t in range(49):
98 | k[t+1] = s[j] * k[t]**α + (1 - δ) * k[t]
99 | axes[1].plot(k, 'o-', label=rf"$\alpha = {α},\; s = {s[j]},\; \delta={δ}$")
100 |
101 | axes[1].grid(lw=0.2)
102 | axes[1].set_xlabel('time')
103 | axes[1].set_ylabel('capital')
104 | axes[1].set_ylim(0, 18)
105 | axes[1].legend(loc='upper left', frameon=True)
106 |
107 | # Trajectories with different δ
108 | δ = (0.05, 0.1, 0.15)
109 | α = 0.33
110 | s = 0.4
111 |
112 | for j in range(3):
113 | k[0] = 1
114 | for t in range(49):
115 | k[t+1] = s * k[t]**α + (1 - δ[j]) * k[t]
116 | axes[2].plot(k, 'o-', label=rf"$\alpha = {α},\; s = {s},\; \delta={δ[j]}$")
117 |
118 | axes[2].set_ylim(0, 18)
119 | axes[2].set_xlabel('time')
120 | axes[2].set_ylabel('capital')
121 | axes[2].grid(lw=0.2)
122 | axes[2].legend(loc='upper left', frameon=True)
123 |
124 | plt.show()
125 | ```
126 |
127 | True, the code more or less follows [PEP8](https://www.python.org/dev/peps/pep-0008/).
128 |
129 | At the same time, it's very poorly structured.
130 |
131 | Let's talk about why that's the case, and what we can do about it.
132 |
133 | * magic numbers
134 | * repetition
135 | * globals
136 |
137 |
138 | ## Revisiting the Example
139 |
140 | Here's some code that reproduces the plot above with better coding style.
141 |
142 | ```{code-cell} python3
143 | from itertools import product
144 |
145 | def plot_path(ax, αs, s_vals, δs, time_series_length=50):
146 | """
147 | Add a time series plot to the axes ax for all given parameters.
148 | """
149 | k = np.empty(time_series_length)
150 |
151 | for (α, s, δ) in product(αs, s_vals, δs):
152 | k[0] = 1
153 | for t in range(time_series_length-1):
154 | k[t+1] = s * k[t]**α + (1 - δ) * k[t]
155 | ax.plot(k, 'o-', label=rf"$\alpha = {α},\; s = {s},\; \delta = {δ}$")
156 |
157 | ax.set_xlabel('time')
158 | ax.set_ylabel('capital')
159 | ax.set_ylim(0, 18)
160 | ax.legend(loc='upper left', frameon=True)
161 |
162 | fig, axes = plt.subplots(3, 1, figsize=(8, 16))
163 |
164 | # Parameters (αs, s_vals, δs)
165 | set_one = ([0.25, 0.33, 0.45], [0.4], [0.1])
166 | set_two = ([0.33], [0.3, 0.4, 0.5], [0.1])
167 | set_three = ([0.33], [0.4], [0.05, 0.1, 0.15])
168 |
169 | for (ax, params) in zip(axes, (set_one, set_two, set_three)):
170 | αs, s_vals, δs = params
171 | plot_path(ax, αs, s_vals, δs)
172 |
173 | plt.show()
174 | ```
175 |
176 | If you inspect this code, you will see that
177 |
178 | * it uses a function to avoid repetition.
179 | * Global variables are quarantined by collecting them together at the end, not the start of the program.
180 | * Magic numbers are avoided.
181 | * The loop at the end where the actual work is done is short and relatively simple.
182 |
183 | +++
184 |
185 | ## Exercises
186 |
187 |
188 | Here is some code that needs improving.
189 |
190 | It involves a basic supply and demand problem.
191 |
192 | Supply is given by
193 |
194 | $$
195 | q_s(p) = \exp(\alpha p) - \beta.
196 | $$
197 |
198 | The demand curve is
199 |
200 | $$
201 | q_d(p) = \gamma p^{-\delta}.
202 | $$
203 |
204 | The values $\alpha$, $\beta$, $\gamma$ and
205 | $\delta$ are **parameters**
206 |
207 | The equilibrium $p^*$ is the price such that
208 | $q_d(p) = q_s(p)$.
209 |
210 | We can solve for this equilibrium using a root finding algorithm.
211 | Specifically, we will find the $p$ such that $h(p) = 0$,
212 | where
213 |
214 | $$
215 | h(p) := q_d(p) - q_s(p)
216 | $$
217 |
218 | This yields the equilibrium price $p^*$. From this we get the
219 | equilibrium quantity by $q^* = q_s(p^*)$
220 |
221 | The parameter values will be
222 |
223 | - $\alpha = 0.1$
224 | - $\beta = 1$
225 | - $\gamma = 1$
226 | - $\delta = 1$
227 |
228 | ```{code-cell} ipython3
229 | from scipy.optimize import brentq
230 |
231 | # Compute equilibrium
232 | def h(p):
233 | return p**(-1) - (np.exp(0.1 * p) - 1) # demand - supply
234 |
235 | p_star = brentq(h, 2, 4)
236 | q_star = np.exp(0.1 * p_star) - 1
237 |
238 | print(f'Equilibrium price is {p_star: .2f}')
239 | print(f'Equilibrium quantity is {q_star: .2f}')
240 | ```
241 |
242 | Let's also plot our results.
243 |
244 | ```{code-cell} ipython3
245 | # Now plot
246 | grid = np.linspace(2, 4, 100)
247 | fig, ax = plt.subplots()
248 |
249 | qs = np.exp(0.1 * grid) - 1
250 | qd = grid**(-1)
251 |
252 |
253 | ax.plot(grid, qd, 'b-', lw=2, label='demand')
254 | ax.plot(grid, qs, 'g-', lw=2, label='supply')
255 |
256 | ax.set_xlabel('price')
257 | ax.set_ylabel('quantity')
258 | ax.legend(loc='upper center')
259 |
260 | plt.show()
261 | ```
262 |
263 | We also want to consider supply and demand shifts.
264 |
265 | For example, let's see what happens when demand shifts up, with $\gamma$ increasing to $1.25$:
266 |
267 | ```{code-cell} ipython3
268 | # Compute equilibrium
269 | def h(p):
270 | return 1.25 * p**(-1) - (np.exp(0.1 * p) - 1)
271 |
272 | p_star = brentq(h, 2, 4)
273 | q_star = np.exp(0.1 * p_star) - 1
274 |
275 | print(f'Equilibrium price is {p_star: .2f}')
276 | print(f'Equilibrium quantity is {q_star: .2f}')
277 | ```
278 |
279 | ```{code-cell} ipython3
280 | # Now plot
281 | p_grid = np.linspace(2, 4, 100)
282 | fig, ax = plt.subplots()
283 |
284 | qs = np.exp(0.1 * p_grid) - 1
285 | qd = 1.25 * p_grid**(-1)
286 |
287 |
288 | ax.plot(grid, qd, 'b-', lw=2, label='demand')
289 | ax.plot(grid, qs, 'g-', lw=2, label='supply')
290 |
291 | ax.set_xlabel('price')
292 | ax.set_ylabel('quantity')
293 | ax.legend(loc='upper center')
294 |
295 | plt.show()
296 | ```
297 |
298 |
299 | ## Discussion
300 |
301 | - What's wrong with this code?
302 | - How could we improve it?
303 |
304 |
305 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/md_source_files/09_numba.md:
--------------------------------------------------------------------------------
1 | ---
2 | jupytext:
3 | text_representation:
4 | extension: .md
5 | format_name: myst
6 | kernelspec:
7 | display_name: Python 3
8 | language: python
9 | name: python3
10 | ---
11 |
12 |
13 | # Numba
14 |
15 | In addition to what's in Anaconda, this lecture will need the following libraries:
16 |
17 | ```{code-cell} ipython
18 | !pip install quantecon
19 | ```
20 |
21 | ```{code-cell} ipython
22 | %matplotlib inline
23 | import numpy as np
24 | import quantecon as qe
25 | import matplotlib.pyplot as plt
26 | ```
27 |
28 |
29 | ## Overview
30 |
31 | In an earlier lecture we learned about vectorization, which is one method to improve speed and efficiency in numerical work.
32 |
33 | Vectorization involves sending array processing operations in batch to efficient low-level code.
34 |
35 | However, vectorization has several weaknesses.
36 |
37 | One is that it is highly memory-intensive when working with large amounts of data.
38 |
39 | Another is that the set of algorithms that can be entirely vectorized is not universal.
40 |
41 | In fact, for some algorithms, vectorization is ineffective.
42 |
43 | Fortunately, a Python library called [Numba](http://numba.pydata.org/) solves many of these problems.
44 |
45 | It does so through something called **just in time (JIT) compilation**.
46 |
47 | The key idea is to compile functions to native machine code instructions on the fly.
48 |
49 | When it succeeds, the compiled code is extremely fast.
50 |
51 | This lecture introduces the main ideas.
52 |
53 | +++
54 |
55 | ## Applications
56 |
57 | As stated above, Numba's primary use is compiling functions to fast native
58 | machine code during runtime.
59 |
60 | ### An Example
61 |
62 | Let's consider a problem that is difficult to vectorize: generating the trajectory of a difference equation given an initial condition.
63 |
64 | We will take the difference equation to be the quadratic map
65 |
66 | $$
67 | x_{t+1} = \alpha x_t (1 - x_t)
68 | $$
69 |
70 | In what follows we set
71 |
72 | ```{code-cell} python3
73 | α = 4.0
74 | ```
75 |
76 | Here's the plot of a typical trajectory, starting from $x_0 = 0.1$, with $t$ on the x-axis
77 |
78 | ```{code-cell} python3
79 | def qm(x0, n):
80 | x = np.empty(n+1)
81 | x[0] = x0
82 | for t in range(n):
83 | x[t+1] = α * x[t] * (1 - x[t])
84 | return x
85 |
86 | x = qm(0.1, 250)
87 | fig, ax = plt.subplots()
88 | ax.plot(x, 'b-', lw=2, alpha=0.8)
89 | ax.set_xlabel('$t$', fontsize=12)
90 | ax.set_ylabel('$x_{t}$', fontsize = 12)
91 | plt.show()
92 | ```
93 |
94 | To speed the function `qm` up using Numba, our first step is
95 |
96 | ```{code-cell} python3
97 | from numba import jit
98 |
99 | qm_numba = jit(qm)
100 | ```
101 |
102 | The function `qm_numba` is a version of `qm` that is "targeted" for
103 | JIT-compilation.
104 |
105 | Let's time and compare identical function calls across these two versions, starting with the original function `qm`:
106 |
107 | ```{code-cell} python3
108 | n = 10_000_000
109 |
110 | qe.tic()
111 | qm(0.1, int(n))
112 | time1 = qe.toc()
113 | ```
114 |
115 | Now let's try qm_numba
116 |
117 | ```{code-cell} python3
118 | qe.tic()
119 | qm_numba(0.1, int(n))
120 | time2 = qe.toc()
121 | ```
122 |
123 | This is already a massive speed gain.
124 |
125 | In fact, the next time and all subsequent times it runs even faster as the function has been compiled and is in memory:
126 |
127 | ```{code-cell} python3
128 | qe.tic()
129 | qm_numba(0.1, int(n))
130 | time3 = qe.toc()
131 | ```
132 |
133 | ```{code-cell} python3
134 | time1 / time3 # Calculate speed gain
135 | ```
136 |
137 | This kind of speed gain is huge relative to how simple and clear the implementation is.
138 |
139 |
140 | ### How and When it Works
141 |
142 | Numba attempts to generate fast machine code using the infrastructure provided by the [LLVM Project](http://llvm.org/).
143 |
144 | It does this by inferring type information on the fly.
145 |
146 | The basic idea is this:
147 |
148 | * Python is very flexible and hence we could call the function qm with many
149 | types.
150 | * e.g., `x0` could be a NumPy array or a list, `n` could be an integer or a float, etc.
151 | * This makes it hard to *pre*-compile the function.
152 | * However, when we do actually call the function, say by executing `qm(0.5, 10)`,
153 | the types of `x0` and `n` become clear.
154 | * Moreover, the types of other variables in `qm` can be inferred once the input is known.
155 | * So the strategy of Numba and other JIT compilers is to wait until this
156 | moment, and *then* compile the function.
157 |
158 | That's why it is called "just-in-time" compilation.
159 |
160 | Note that, if you make the call `qm(0.5, 10)` and then follow it with `qm(0.9, 20)`, compilation only takes place on the first call.
161 |
162 | The compiled code is then cached and recycled as required.
163 |
164 | ## Decorators and "nopython" Mode
165 |
166 | In the code above we created a JIT compiled version of `qm` via the call
167 |
168 | ```{code-cell} python3
169 | qm_numba = jit(qm)
170 | ```
171 |
172 | In practice this would typically be done using an alternative *decorator* syntax.
173 |
174 | (We will explain all about decorators in a {doc}`later lecture ` but you can skip the details at this stage.)
175 |
176 | Let's see how this is done.
177 |
178 | ### Decorator Notation
179 |
180 | To target a function for JIT compilation we can put `@jit` before the function definition.
181 |
182 | Here's what this looks like for `qm`
183 |
184 | ```{code-cell} python3
185 | @jit
186 | def qm(x0, n):
187 | x = np.empty(n+1)
188 | x[0] = x0
189 | for t in range(n):
190 | x[t+1] = α * x[t] * (1 - x[t])
191 | return x
192 | ```
193 |
194 | This is equivalent to `qm = jit(qm)`.
195 |
196 | The following now uses the jitted version:
197 |
198 | ```{code-cell} python3
199 | qm(0.1, 10)
200 | ```
201 |
202 | ### Type Inference and "nopython" Mode
203 |
204 | Clearly type inference is a key part of JIT compilation.
205 |
206 | As you can imagine, inferring types is easier for simple Python objects (e.g., simple scalar data types such as floats and integers).
207 |
208 | Numba also plays well with NumPy arrays.
209 |
210 | In an ideal setting, Numba can infer all necessary type information.
211 |
212 | This allows it to generate native machine code, without having to call the Python runtime environment.
213 |
214 | In such a setting, Numba will be on par with machine code from low-level languages.
215 |
216 | When Numba cannot infer all type information, some Python objects are given generic object status and execution falls back to the Python runtime.
217 |
218 | When this happens, Numba provides only minor speed gains or none at all.
219 |
220 | We generally prefer to force an error when this occurs, so we know effective
221 | compilation is failing.
222 |
223 | This is done by using either `@jit(nopython=True)` or, equivalently, `@njit` instead of `@jit`.
224 |
225 | For example,
226 |
227 | ```{code-cell} python3
228 | from numba import njit
229 |
230 | @njit
231 | def qm(x0, n):
232 | x = np.empty(n+1)
233 | x[0] = x0
234 | for t in range(n):
235 | x[t+1] = 4 * x[t] * (1 - x[t])
236 | return x
237 | ```
238 |
239 |
240 | ## Ex. 1
241 |
242 | Previously we considered how to approximate $\pi$ by
243 | Monte Carlo.
244 |
245 | ```{code-cell python3}
246 | from random import uniform
247 |
248 | def calculate_pi(n=1_000_000):
249 | count = 0
250 | for i in range(n):
251 | u, v = uniform(0, 1), uniform(0, 1)
252 | d = np.sqrt((u - 0.5)**2 + (v - 0.5)**2)
253 | if d < 0.5:
254 | count += 1
255 |
256 | area_estimate = count / n
257 | return area_estimate * 4 # dividing by radius**2
258 | ```
259 |
260 | Make the code efficient using Numba.
261 |
262 | Compare speed with and without Numba when the sample size is large.
263 |
264 |
265 | +++
266 |
267 |
268 | ### Ex. 2
269 |
270 | Write your own version of a one dimensional [kernel density
271 | estimator](https://en.wikipedia.org/wiki/Kernel_density_estimation),
272 | which estimates a density from a sample.
273 |
274 | Write it as a class that takes the data $X$ and bandwidth
275 | $h$ when initialized and provides a method $f$ such that
276 |
277 | $$
278 | f(x) = \frac{1}{hn} \sum_{i=1}^n
279 | K \left( \frac{x-X_i}{h} \right)
280 | $$
281 |
282 | For $K$ use the Gaussian kernel ($K$ is the standard normal
283 | density).
284 |
285 | +++
286 |
287 | Write the class so that the bandwidth defaults to Silverman’s rule (see
288 | the “rule of thumb” discussion on [this
289 | page](https://en.wikipedia.org/wiki/Kernel_density_estimation)). Test
290 | the class you have written by going through the steps
291 |
292 | 1. simulate data $X_1, \ldots, X_n$ from distribution $\phi$
293 | 1. plot the kernel density estimate over a suitable range
294 | 1. plot the density of $\phi$ on the same figure
295 |
296 | for distributions $\phi$ of the following types
297 |
298 | - [beta
299 | distribution](https://en.wikipedia.org/wiki/Beta_distribution)
300 | with $\alpha = \beta = 2$
301 | - [beta
302 | distribution](https://en.wikipedia.org/wiki/Beta_distribution)
303 | with $\alpha = 2$ and $\beta = 5$
304 | - [beta
305 | distribution](https://en.wikipedia.org/wiki/Beta_distribution)
306 | with $\alpha = \beta = 0.5$
307 |
308 | Use $n=500$.
309 |
310 | Make a comment on your results. (Do you think this is a good estimator
311 | of these distributions?)
312 |
313 |
314 | ```
315 | solutions below
316 | solutions below
317 | solutions below
318 | solutions below
319 | solutions below
320 | solutions below
321 | solutions below
322 | solutions below
323 | solutions below
324 | solutions below
325 | solutions below
326 | solutions below
327 | solutions below
328 | solutions below
329 | solutions below
330 | solutions below
331 | solutions below
332 | solutions below
333 | solutions below
334 | solutions below
335 | solutions below
336 | ```
337 |
338 |
339 |
340 | +++
341 |
342 | ### Solution to Ex. 1
343 |
344 | Since we want to compare speed, we'll avoid decorator syntax and keep a
345 | non-jitted version:
346 |
347 | ```{code-cell} python3
348 | from random import uniform
349 |
350 | def calculate_pi(n=1_000_000):
351 | count = 0
352 | for i in range(n):
353 | u, v = uniform(0, 1), uniform(0, 1)
354 | d = np.sqrt((u - 0.5)**2 + (v - 0.5)**2)
355 | if d < 0.5:
356 | count += 1
357 |
358 | area_estimate = count / n
359 | return area_estimate * 4 # dividing by radius**2
360 |
361 | calculate_pi_jitted = njit(calculate_pi)
362 | ```
363 |
364 | Here's the speed comparison:
365 |
366 | ```{code-cell} python3
367 | qe.tic()
368 | calculate_pi()
369 | time1 = qe.toc()
370 | ```
371 |
372 | Now let's try qm_numba
373 |
374 | ```{code-cell} python3
375 | calculate_pi_jitted() # once to compile
376 | qe.tic()
377 | calculate_pi_jitted() # and once to time
378 | time2 = qe.toc()
379 | ```
380 |
381 | Here's the time difference:
382 |
383 | ```{code-cell} python3
384 | time1 / time2
385 | ```
386 |
387 |
388 | ### Solution to Ex. 2
389 |
390 | Here is one solution:
391 |
392 | ```{code-cell} ipython3
393 | from scipy.stats import norm
394 | from numba import vectorize, float64
395 |
396 | @njit
397 | def K(x):
398 | return (1/np.sqrt(2*np.pi)) * np.exp(-x**2 / 2)
399 |
400 | def kde(x_data, h=None):
401 |
402 | if h is None:
403 | c = x_data.std()
404 | n = len(x_data)
405 | h = 1.06 * c * n**(-1/5)
406 |
407 | @vectorize([float64(float64)])
408 | def f(x):
409 | return K((x - x_data) / h).mean() * (1/h)
410 |
411 | return f
412 | ```
413 |
414 |
415 |
416 | ```{code-cell} ipython3
417 | def plot_kde(ϕ, x_min=-0.2, x_max=1.2):
418 | x_data = ϕ.rvs(n)
419 | f = kde(x_data)
420 |
421 | x_grid = np.linspace(-0.2, 1.2, 100)
422 | fig, ax = plt.subplots()
423 | ax.plot(x_grid, f(x_grid), label="estimate")
424 | ax.plot(x_grid, ϕ.pdf(x_grid), label="true density")
425 | ax.legend()
426 | plt.show()
427 | ```
428 |
429 | ```{code-cell} ipython3
430 | from scipy.stats import beta
431 |
432 | n = 500
433 | parameter_pairs= (2, 2), (2, 5), (0.5, 0.5)
434 | for α, β in parameter_pairs:
435 | plot_kde(beta(α, β))
436 | ```
437 |
438 | We see that the kernel density estimator is effective when the underlying
439 | distribution is smooth but less so otherwise.
440 |
441 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/2A20D064E5B48BE32BA789F4D5876813C3FF684A43DD05DB942AAFE1D7B2E81C.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\}]
2 | \PYG{n}{data\PYGZus{}file} \PYG{o}{=} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}data.txt\PYGZdq{}}\PYG{p}{)}
3 | \PYG{k}{for} \PYG{n}{line} \PYG{o+ow}{in} \PYG{n}{data\PYGZus{}file}\PYG{p}{:}
4 | \PYG{k}{print}\PYG{p}{(}\PYG{n}{line}\PYG{o}{.}\PYG{n}{capitalize}\PYG{p}{())}
5 | \PYG{n}{data\PYGZus{}file}\PYG{o}{.}\PYG{n}{close}\PYG{p}{()}
6 | \end{Verbatim}
7 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/338FAB092F754A86073BB22A33F6852138A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{10}\PYG{p}{]:} \PYG{l+m+mi}{2}\PYG{o}{**}\PYG{l+m+mi}{1000}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{10}\PYG{p}{]:}
4 | \PYG{l+m+mi}{107150860718626732094842504906000181056140481170}
5 | \PYG{l+m+mi}{553360744375038837035105112493612249319837881569}
6 | \PYG{l+m+mi}{585812759467291755314682518714528569231404359845}
7 | \PYG{l+m+mi}{775746985748039345677748242309854210746050623711}
8 | \PYG{l+m+mi}{418779541821530464749835819412673987675591655439}
9 | \PYG{l+m+mi}{460770629145711964776865421676604298316526243868}
10 | \PYG{l+m+mi}{37205668069376}
11 | \end{Verbatim}
12 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/6FB4CCF74C7BDCAEFF65CF0C90E0A25FD0A1E07ECC8EA949162E2D5A763F202A.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\}]
2 | \PYG{n+nx}{pushq} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}
3 | \PYG{n+nx}{movq} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rsp}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}
4 | \PYG{n+nx}{movl} \PYG{n+nx}{\PYGZdl{}1}\PYG{o}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{12}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}
5 | \PYG{n+nx}{movl} \PYG{n+nx}{\PYGZdl{}1}\PYG{o}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{8}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}
6 | \PYG{n+nx}{movl} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{12}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{edx}
7 | \PYG{n+nx}{movl} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{8}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}
8 | \PYG{n+nx}{addl} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{edx}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}
9 | \PYG{n+nx}{movl} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}\PYG{o}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{4}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}
10 | \PYG{n+nx}{movl} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{4}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}
11 | \PYG{n+nx}{popq} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}
12 | \end{Verbatim}
13 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/B2741080E8A5EB900163B849C77D51A838A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{20}\PYG{p}{]:} \PYG{l+m+mi}{5} \PYG{o}{*} \PYG{l+m+mi}{10}\PYG{o}{**}\PYG{l+m+mi}{9} \PYG{c+c1}{\PYGZsh{} Expected lifespan of sun}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{20}\PYG{p}{]:} \PYG{l+m+mi}{5000000000}
4 | \end{Verbatim}
5 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/C489745F93B72AC9F19D2216C755D0F138A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{16}\PYG{p}{]:} \PYG{p}{(}\PYG{l+m+mi}{2}\PYG{o}{**}\PYG{l+m+mi}{1000} \PYG{o}{/} \PYG{l+m+mi}{10}\PYG{o}{**}\PYG{l+m+mi}{9}\PYG{p}{)} \PYG{o}{/} \PYG{l+m+mi}{31556926} \PYG{c+c1}{\PYGZsh{} In years}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{16}\PYG{p}{]:}
4 | \PYG{l+m+mi}{339547840365144349278007955863635707280678989995}
5 | \PYG{l+m+mi}{899349462539661933596146571733926965255861364854}
6 | \PYG{l+m+mo}{0602}\PYG{l+m+mi}{86985707326991591901311029244639453805988092}
7 | \PYG{l+m+mo}{045}\PYG{l+m+mi}{933072657455119924381235072941549332310199388}
8 | \PYG{l+m+mi}{301571394569707026437986448403352049168514244509}
9 | \PYG{l+m+mi}{939816790601568621661265174170019913588941596}
10 | \end{Verbatim}
11 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/E96D923064AB1C3D7D66F328B0305D8638A6E84F18F2EF8D00D53F9B09FB7F7C.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{19}\PYG{p}{]:} \PYG{p}{(}\PYG{l+m+mi}{2}\PYG{o}{**}\PYG{l+m+mi}{1000} \PYG{o}{/} \PYG{l+m+mi}{10}\PYG{o}{**}\PYG{p}{(}\PYG{l+m+mi}{9} \PYG{o}{+} \PYG{l+m+mi}{12}\PYG{p}{))} \PYG{o}{/} \PYG{l+m+mi}{31556926}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{19}\PYG{p}{]:}
4 | \PYG{l+m+mi}{3395478403651443492780079558636357072806789899958}
5 | \PYG{l+m+mi}{9934946253966193359614657173392696525586136485406}
6 | \PYG{l+m+mo}{02}\PYG{l+m+mi}{86985707326991591901311029244639453805988092045}
7 | \PYG{l+m+mi}{9330726574551199243812350729415493323101993883015}
8 | \PYG{l+m+mi}{7139456970702643798644840335204916851424450993981}
9 | \PYG{l+m+mi}{6790601568621661265174170019}
10 | \end{Verbatim}
11 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/default-pyg-prefix.pygstyle:
--------------------------------------------------------------------------------
1 |
2 | \makeatletter
3 | \def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
4 | \let\PYG@ul=\relax \let\PYG@tc=\relax%
5 | \let\PYG@bc=\relax \let\PYG@ff=\relax}
6 | \def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
7 | \def\PYG@toks#1+{\ifx\relax#1\empty\else%
8 | \PYG@tok{#1}\expandafter\PYG@toks\fi}
9 | \def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
10 | \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
11 | \def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}
12 |
13 | \expandafter\def\csname PYG@tok@w\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
14 | \expandafter\def\csname PYG@tok@c\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
15 | \expandafter\def\csname PYG@tok@cp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
16 | \expandafter\def\csname PYG@tok@k\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
17 | \expandafter\def\csname PYG@tok@kp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
18 | \expandafter\def\csname PYG@tok@kt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
19 | \expandafter\def\csname PYG@tok@o\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
20 | \expandafter\def\csname PYG@tok@ow\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
21 | \expandafter\def\csname PYG@tok@nb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
22 | \expandafter\def\csname PYG@tok@nf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
23 | \expandafter\def\csname PYG@tok@nc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
24 | \expandafter\def\csname PYG@tok@nn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
25 | \expandafter\def\csname PYG@tok@ne\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
26 | \expandafter\def\csname PYG@tok@nv\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
27 | \expandafter\def\csname PYG@tok@no\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
28 | \expandafter\def\csname PYG@tok@nl\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
29 | \expandafter\def\csname PYG@tok@ni\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
30 | \expandafter\def\csname PYG@tok@na\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
31 | \expandafter\def\csname PYG@tok@nt\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
32 | \expandafter\def\csname PYG@tok@nd\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
33 | \expandafter\def\csname PYG@tok@s\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
34 | \expandafter\def\csname PYG@tok@sd\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
35 | \expandafter\def\csname PYG@tok@si\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
36 | \expandafter\def\csname PYG@tok@se\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
37 | \expandafter\def\csname PYG@tok@sr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
38 | \expandafter\def\csname PYG@tok@ss\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
39 | \expandafter\def\csname PYG@tok@sx\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
40 | \expandafter\def\csname PYG@tok@m\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
41 | \expandafter\def\csname PYG@tok@gh\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
42 | \expandafter\def\csname PYG@tok@gu\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
43 | \expandafter\def\csname PYG@tok@gd\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
44 | \expandafter\def\csname PYG@tok@gi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
45 | \expandafter\def\csname PYG@tok@gr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
46 | \expandafter\def\csname PYG@tok@ge\endcsname{\let\PYG@it=\textit}
47 | \expandafter\def\csname PYG@tok@gs\endcsname{\let\PYG@bf=\textbf}
48 | \expandafter\def\csname PYG@tok@gp\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
49 | \expandafter\def\csname PYG@tok@go\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
50 | \expandafter\def\csname PYG@tok@gt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
51 | \expandafter\def\csname PYG@tok@err\endcsname{\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
52 | \expandafter\def\csname PYG@tok@kc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
53 | \expandafter\def\csname PYG@tok@kd\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
54 | \expandafter\def\csname PYG@tok@kn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
55 | \expandafter\def\csname PYG@tok@kr\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
56 | \expandafter\def\csname PYG@tok@bp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
57 | \expandafter\def\csname PYG@tok@fm\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
58 | \expandafter\def\csname PYG@tok@vc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
59 | \expandafter\def\csname PYG@tok@vg\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
60 | \expandafter\def\csname PYG@tok@vi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
61 | \expandafter\def\csname PYG@tok@vm\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
62 | \expandafter\def\csname PYG@tok@sa\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
63 | \expandafter\def\csname PYG@tok@sb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
64 | \expandafter\def\csname PYG@tok@sc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
65 | \expandafter\def\csname PYG@tok@dl\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
66 | \expandafter\def\csname PYG@tok@s2\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
67 | \expandafter\def\csname PYG@tok@sh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
68 | \expandafter\def\csname PYG@tok@s1\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
69 | \expandafter\def\csname PYG@tok@mb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
70 | \expandafter\def\csname PYG@tok@mf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
71 | \expandafter\def\csname PYG@tok@mh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
72 | \expandafter\def\csname PYG@tok@mi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
73 | \expandafter\def\csname PYG@tok@il\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
74 | \expandafter\def\csname PYG@tok@mo\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
75 | \expandafter\def\csname PYG@tok@ch\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
76 | \expandafter\def\csname PYG@tok@cm\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
77 | \expandafter\def\csname PYG@tok@cpf\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
78 | \expandafter\def\csname PYG@tok@c1\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
79 | \expandafter\def\csname PYG@tok@cs\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
80 |
81 | \def\PYGZbs{\char`\\}
82 | \def\PYGZus{\char`\_}
83 | \def\PYGZob{\char`\{}
84 | \def\PYGZcb{\char`\}}
85 | \def\PYGZca{\char`\^}
86 | \def\PYGZam{\char`\&}
87 | \def\PYGZlt{\char`\<}
88 | \def\PYGZgt{\char`\>}
89 | \def\PYGZsh{\char`\#}
90 | \def\PYGZpc{\char`\%}
91 | \def\PYGZdl{\char`\$}
92 | \def\PYGZhy{\char`\-}
93 | \def\PYGZsq{\char`\'}
94 | \def\PYGZdq{\char`\"}
95 | \def\PYGZti{\char`\~}
96 | % for compatibility with earlier versions
97 | \def\PYGZat{@}
98 | \def\PYGZlb{[}
99 | \def\PYGZrb{]}
100 | \makeatother
101 |
102 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture1/friendly.pygstyle:
--------------------------------------------------------------------------------
1 |
2 | \makeatletter
3 | \def\PYGfriendly@reset{\let\PYGfriendly@it=\relax \let\PYGfriendly@bf=\relax%
4 | \let\PYGfriendly@ul=\relax \let\PYGfriendly@tc=\relax%
5 | \let\PYGfriendly@bc=\relax \let\PYGfriendly@ff=\relax}
6 | \def\PYGfriendly@tok#1{\csname PYGfriendly@tok@#1\endcsname}
7 | \def\PYGfriendly@toks#1+{\ifx\relax#1\empty\else%
8 | \PYGfriendly@tok{#1}\expandafter\PYGfriendly@toks\fi}
9 | \def\PYGfriendly@do#1{\PYGfriendly@bc{\PYGfriendly@tc{\PYGfriendly@ul{%
10 | \PYGfriendly@it{\PYGfriendly@bf{\PYGfriendly@ff{#1}}}}}}}
11 | \def\PYGfriendly#1#2{\PYGfriendly@reset\PYGfriendly@toks#1+\relax+\PYGfriendly@do{#2}}
12 |
13 | \expandafter\def\csname PYGfriendly@tok@w\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
14 | \expandafter\def\csname PYGfriendly@tok@c\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
15 | \expandafter\def\csname PYGfriendly@tok@cp\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
16 | \expandafter\def\csname PYGfriendly@tok@cs\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}\def\PYGfriendly@bc##1{\setlength{\fboxsep}{0pt}\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}
17 | \expandafter\def\csname PYGfriendly@tok@k\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
18 | \expandafter\def\csname PYGfriendly@tok@kp\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
19 | \expandafter\def\csname PYGfriendly@tok@kt\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.56,0.13,0.00}{##1}}}
20 | \expandafter\def\csname PYGfriendly@tok@o\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
21 | \expandafter\def\csname PYGfriendly@tok@ow\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
22 | \expandafter\def\csname PYGfriendly@tok@nb\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
23 | \expandafter\def\csname PYGfriendly@tok@nf\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
24 | \expandafter\def\csname PYGfriendly@tok@nc\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
25 | \expandafter\def\csname PYGfriendly@tok@nn\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
26 | \expandafter\def\csname PYGfriendly@tok@ne\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
27 | \expandafter\def\csname PYGfriendly@tok@nv\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
28 | \expandafter\def\csname PYGfriendly@tok@no\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.68,0.84}{##1}}}
29 | \expandafter\def\csname PYGfriendly@tok@nl\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.13,0.44}{##1}}}
30 | \expandafter\def\csname PYGfriendly@tok@ni\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.84,0.33,0.22}{##1}}}
31 | \expandafter\def\csname PYGfriendly@tok@na\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
32 | \expandafter\def\csname PYGfriendly@tok@nt\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.02,0.16,0.45}{##1}}}
33 | \expandafter\def\csname PYGfriendly@tok@nd\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
34 | \expandafter\def\csname PYGfriendly@tok@s\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
35 | \expandafter\def\csname PYGfriendly@tok@sd\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
36 | \expandafter\def\csname PYGfriendly@tok@si\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.44,0.63,0.82}{##1}}}
37 | \expandafter\def\csname PYGfriendly@tok@se\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
38 | \expandafter\def\csname PYGfriendly@tok@sr\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.14,0.33,0.53}{##1}}}
39 | \expandafter\def\csname PYGfriendly@tok@ss\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.32,0.47,0.09}{##1}}}
40 | \expandafter\def\csname PYGfriendly@tok@sx\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
41 | \expandafter\def\csname PYGfriendly@tok@m\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
42 | \expandafter\def\csname PYGfriendly@tok@gh\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
43 | \expandafter\def\csname PYGfriendly@tok@gu\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
44 | \expandafter\def\csname PYGfriendly@tok@gd\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
45 | \expandafter\def\csname PYGfriendly@tok@gi\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
46 | \expandafter\def\csname PYGfriendly@tok@gr\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
47 | \expandafter\def\csname PYGfriendly@tok@ge\endcsname{\let\PYGfriendly@it=\textit}
48 | \expandafter\def\csname PYGfriendly@tok@gs\endcsname{\let\PYGfriendly@bf=\textbf}
49 | \expandafter\def\csname PYGfriendly@tok@gp\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
50 | \expandafter\def\csname PYGfriendly@tok@go\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
51 | \expandafter\def\csname PYGfriendly@tok@gt\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
52 | \expandafter\def\csname PYGfriendly@tok@err\endcsname{\def\PYGfriendly@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
53 | \expandafter\def\csname PYGfriendly@tok@kc\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
54 | \expandafter\def\csname PYGfriendly@tok@kd\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
55 | \expandafter\def\csname PYGfriendly@tok@kn\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
56 | \expandafter\def\csname PYGfriendly@tok@kr\endcsname{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
57 | \expandafter\def\csname PYGfriendly@tok@bp\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
58 | \expandafter\def\csname PYGfriendly@tok@fm\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
59 | \expandafter\def\csname PYGfriendly@tok@vc\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
60 | \expandafter\def\csname PYGfriendly@tok@vg\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
61 | \expandafter\def\csname PYGfriendly@tok@vi\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
62 | \expandafter\def\csname PYGfriendly@tok@vm\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
63 | \expandafter\def\csname PYGfriendly@tok@sa\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
64 | \expandafter\def\csname PYGfriendly@tok@sb\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
65 | \expandafter\def\csname PYGfriendly@tok@sc\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
66 | \expandafter\def\csname PYGfriendly@tok@dl\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
67 | \expandafter\def\csname PYGfriendly@tok@s2\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
68 | \expandafter\def\csname PYGfriendly@tok@sh\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
69 | \expandafter\def\csname PYGfriendly@tok@s1\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
70 | \expandafter\def\csname PYGfriendly@tok@mb\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
71 | \expandafter\def\csname PYGfriendly@tok@mf\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
72 | \expandafter\def\csname PYGfriendly@tok@mh\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
73 | \expandafter\def\csname PYGfriendly@tok@mi\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
74 | \expandafter\def\csname PYGfriendly@tok@il\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
75 | \expandafter\def\csname PYGfriendly@tok@mo\endcsname{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
76 | \expandafter\def\csname PYGfriendly@tok@ch\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
77 | \expandafter\def\csname PYGfriendly@tok@cm\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
78 | \expandafter\def\csname PYGfriendly@tok@cpf\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
79 | \expandafter\def\csname PYGfriendly@tok@c1\endcsname{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
80 |
81 | \def\PYGfriendlyZbs{\char`\\}
82 | \def\PYGfriendlyZus{\char`\_}
83 | \def\PYGfriendlyZob{\char`\{}
84 | \def\PYGfriendlyZcb{\char`\}}
85 | \def\PYGfriendlyZca{\char`\^}
86 | \def\PYGfriendlyZam{\char`\&}
87 | \def\PYGfriendlyZlt{\char`\<}
88 | \def\PYGfriendlyZgt{\char`\>}
89 | \def\PYGfriendlyZsh{\char`\#}
90 | \def\PYGfriendlyZpc{\char`\%}
91 | \def\PYGfriendlyZdl{\char`\$}
92 | \def\PYGfriendlyZhy{\char`\-}
93 | \def\PYGfriendlyZsq{\char`\'}
94 | \def\PYGfriendlyZdq{\char`\"}
95 | \def\PYGfriendlyZti{\char`\~}
96 | % for compatibility with earlier versions
97 | \def\PYGfriendlyZat{@}
98 | \def\PYGfriendlyZlb{[}
99 | \def\PYGfriendlyZrb{]}
100 | \makeatother
101 |
102 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/2A20D064E5B48BE32BA789F4D587681385D0BD28A1E4792CF3121F1259CE2057.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\}]
2 | \PYG{n}{data\PYGZus{}file} \PYG{o}{=} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}data.txt\PYGZdq{}}\PYG{p}{)}
3 | \PYG{k}{for} \PYG{n}{line} \PYG{o+ow}{in} \PYG{n}{data\PYGZus{}file}\PYG{p}{:}
4 | \PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{line}\PYG{o}{.}\PYG{n}{capitalize}\PYG{p}{())}
5 | \PYG{n}{data\PYGZus{}file}\PYG{o}{.}\PYG{n}{close}\PYG{p}{()}
6 | \end{Verbatim}
7 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/338FAB092F754A86073BB22A33F6852184A9A22770301CD7D1F5723F317C5665.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{10}\PYG{p}{]:} \PYG{l+m+mi}{2}\PYG{o}{**}\PYG{l+m+mi}{1000}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{10}\PYG{p}{]:}
4 | \PYG{l+m+mi}{107150860718626732094842504906000181056140481170}
5 | \PYG{l+m+mi}{553360744375038837035105112493612249319837881569}
6 | \PYG{l+m+mi}{585812759467291755314682518714528569231404359845}
7 | \PYG{l+m+mi}{775746985748039345677748242309854210746050623711}
8 | \PYG{l+m+mi}{418779541821530464749835819412673987675591655439}
9 | \PYG{l+m+mi}{460770629145711964776865421676604298316526243868}
10 | \PYG{l+m+mi}{37205668069376}
11 | \end{Verbatim}
12 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/6FB4CCF74C7BDCAEFF65CF0C90E0A25F0B89A0F046740D7F88D4B07B9BED7A06.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\}]
2 | \PYG{n+nx}{pushq} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}
3 | \PYG{n+nx}{movq} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rsp}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}
4 | \PYG{n+nx}{movl} \PYG{n+nx}{\PYGZdl{}1}\PYG{o}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{12}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}
5 | \PYG{n+nx}{movl} \PYG{n+nx}{\PYGZdl{}1}\PYG{o}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{8}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}
6 | \PYG{n+nx}{movl} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{12}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{edx}
7 | \PYG{n+nx}{movl} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{8}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}
8 | \PYG{n+nx}{addl} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{edx}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}
9 | \PYG{n+nx}{movl} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}\PYG{o}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{4}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}
10 | \PYG{n+nx}{movl} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{4}\PYG{p}{(}\PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}\PYG{p}{)}\PYG{o}{,} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{eax}
11 | \PYG{n+nx}{popq} \PYG{o}{\PYGZpc{}}\PYG{n+nx}{rbp}
12 | \end{Verbatim}
13 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/B2741080E8A5EB900163B849C77D51A884A9A22770301CD7D1F5723F317C5665.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{20}\PYG{p}{]:} \PYG{l+m+mi}{5} \PYG{o}{*} \PYG{l+m+mi}{10}\PYG{o}{**}\PYG{l+m+mi}{9} \PYG{c+c1}{\PYGZsh{} Expected lifespan of sun}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{20}\PYG{p}{]:} \PYG{l+m+mi}{5000000000}
4 | \end{Verbatim}
5 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/C489745F93B72AC9F19D2216C755D0F184A9A22770301CD7D1F5723F317C5665.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{16}\PYG{p}{]:} \PYG{p}{(}\PYG{l+m+mi}{2}\PYG{o}{**}\PYG{l+m+mi}{1000} \PYG{o}{/} \PYG{l+m+mi}{10}\PYG{o}{**}\PYG{l+m+mi}{9}\PYG{p}{)} \PYG{o}{/} \PYG{l+m+mi}{31556926} \PYG{c+c1}{\PYGZsh{} In years}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{16}\PYG{p}{]:}
4 | \PYG{l+m+mi}{339547840365144349278007955863635707280678989995}
5 | \PYG{l+m+mi}{899349462539661933596146571733926965255861364854}
6 | \PYG{l+m+mi}{060286985707326991591901311029244639453805988092}
7 | \PYG{l+m+mi}{045933072657455119924381235072941549332310199388}
8 | \PYG{l+m+mi}{301571394569707026437986448403352049168514244509}
9 | \PYG{l+m+mi}{939816790601568621661265174170019913588941596}
10 | \end{Verbatim}
11 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/E96D923064AB1C3D7D66F328B0305D8684A9A22770301CD7D1F5723F317C5665.pygtex:
--------------------------------------------------------------------------------
1 | \begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2 | \PYG{n}{In} \PYG{p}{[}\PYG{l+m+mi}{19}\PYG{p}{]:} \PYG{p}{(}\PYG{l+m+mi}{2}\PYG{o}{**}\PYG{l+m+mi}{1000} \PYG{o}{/} \PYG{l+m+mi}{10}\PYG{o}{**}\PYG{p}{(}\PYG{l+m+mi}{9} \PYG{o}{+} \PYG{l+m+mi}{12}\PYG{p}{))} \PYG{o}{/} \PYG{l+m+mi}{31556926}
3 | \PYG{n}{Out}\PYG{p}{[}\PYG{l+m+mi}{19}\PYG{p}{]:}
4 | \PYG{l+m+mi}{3395478403651443492780079558636357072806789899958}
5 | \PYG{l+m+mi}{9934946253966193359614657173392696525586136485406}
6 | \PYG{l+m+mi}{0286985707326991591901311029244639453805988092045}
7 | \PYG{l+m+mi}{9330726574551199243812350729415493323101993883015}
8 | \PYG{l+m+mi}{7139456970702643798644840335204916851424450993981}
9 | \PYG{l+m+mi}{6790601568621661265174170019}
10 | \end{Verbatim}
11 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/default-pyg-prefix.pygstyle:
--------------------------------------------------------------------------------
1 |
2 | \makeatletter
3 | \def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
4 | \let\PYG@ul=\relax \let\PYG@tc=\relax%
5 | \let\PYG@bc=\relax \let\PYG@ff=\relax}
6 | \def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
7 | \def\PYG@toks#1+{\ifx\relax#1\empty\else%
8 | \PYG@tok{#1}\expandafter\PYG@toks\fi}
9 | \def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
10 | \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
11 | \def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}
12 |
13 | \@namedef{PYG@tok@w}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
14 | \@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
15 | \@namedef{PYG@tok@cp}{\def\PYG@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
16 | \@namedef{PYG@tok@k}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
17 | \@namedef{PYG@tok@kp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
18 | \@namedef{PYG@tok@kt}{\def\PYG@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
19 | \@namedef{PYG@tok@o}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
20 | \@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
21 | \@namedef{PYG@tok@nb}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
22 | \@namedef{PYG@tok@nf}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
23 | \@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
24 | \@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
25 | \@namedef{PYG@tok@ne}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
26 | \@namedef{PYG@tok@nv}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
27 | \@namedef{PYG@tok@no}{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
28 | \@namedef{PYG@tok@nl}{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
29 | \@namedef{PYG@tok@ni}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
30 | \@namedef{PYG@tok@na}{\def\PYG@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
31 | \@namedef{PYG@tok@nt}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
32 | \@namedef{PYG@tok@nd}{\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
33 | \@namedef{PYG@tok@s}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
34 | \@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
35 | \@namedef{PYG@tok@si}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
36 | \@namedef{PYG@tok@se}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
37 | \@namedef{PYG@tok@sr}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
38 | \@namedef{PYG@tok@ss}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
39 | \@namedef{PYG@tok@sx}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
40 | \@namedef{PYG@tok@m}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
41 | \@namedef{PYG@tok@gh}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
42 | \@namedef{PYG@tok@gu}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
43 | \@namedef{PYG@tok@gd}{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
44 | \@namedef{PYG@tok@gi}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
45 | \@namedef{PYG@tok@gr}{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
46 | \@namedef{PYG@tok@ge}{\let\PYG@it=\textit}
47 | \@namedef{PYG@tok@gs}{\let\PYG@bf=\textbf}
48 | \@namedef{PYG@tok@gp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
49 | \@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
50 | \@namedef{PYG@tok@gt}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
51 | \@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}}
52 | \@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
53 | \@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
54 | \@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
55 | \@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
56 | \@namedef{PYG@tok@bp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
57 | \@namedef{PYG@tok@fm}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
58 | \@namedef{PYG@tok@vc}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
59 | \@namedef{PYG@tok@vg}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
60 | \@namedef{PYG@tok@vi}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
61 | \@namedef{PYG@tok@vm}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
62 | \@namedef{PYG@tok@sa}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
63 | \@namedef{PYG@tok@sb}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
64 | \@namedef{PYG@tok@sc}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
65 | \@namedef{PYG@tok@dl}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
66 | \@namedef{PYG@tok@s2}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
67 | \@namedef{PYG@tok@sh}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
68 | \@namedef{PYG@tok@s1}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
69 | \@namedef{PYG@tok@mb}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
70 | \@namedef{PYG@tok@mf}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
71 | \@namedef{PYG@tok@mh}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
72 | \@namedef{PYG@tok@mi}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
73 | \@namedef{PYG@tok@il}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
74 | \@namedef{PYG@tok@mo}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
75 | \@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
76 | \@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
77 | \@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
78 | \@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
79 | \@namedef{PYG@tok@cs}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
80 |
81 | \def\PYGZbs{\char`\\}
82 | \def\PYGZus{\char`\_}
83 | \def\PYGZob{\char`\{}
84 | \def\PYGZcb{\char`\}}
85 | \def\PYGZca{\char`\^}
86 | \def\PYGZam{\char`\&}
87 | \def\PYGZlt{\char`\<}
88 | \def\PYGZgt{\char`\>}
89 | \def\PYGZsh{\char`\#}
90 | \def\PYGZpc{\char`\%}
91 | \def\PYGZdl{\char`\$}
92 | \def\PYGZhy{\char`\-}
93 | \def\PYGZsq{\char`\'}
94 | \def\PYGZdq{\char`\"}
95 | \def\PYGZti{\char`\~}
96 | % for compatibility with earlier versions
97 | \def\PYGZat{@}
98 | \def\PYGZlb{[}
99 | \def\PYGZrb{]}
100 | \makeatother
101 |
102 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/_minted-lecture_1/friendly.pygstyle:
--------------------------------------------------------------------------------
1 |
2 | \makeatletter
3 | \def\PYGfriendly@reset{\let\PYGfriendly@it=\relax \let\PYGfriendly@bf=\relax%
4 | \let\PYGfriendly@ul=\relax \let\PYGfriendly@tc=\relax%
5 | \let\PYGfriendly@bc=\relax \let\PYGfriendly@ff=\relax}
6 | \def\PYGfriendly@tok#1{\csname PYGfriendly@tok@#1\endcsname}
7 | \def\PYGfriendly@toks#1+{\ifx\relax#1\empty\else%
8 | \PYGfriendly@tok{#1}\expandafter\PYGfriendly@toks\fi}
9 | \def\PYGfriendly@do#1{\PYGfriendly@bc{\PYGfriendly@tc{\PYGfriendly@ul{%
10 | \PYGfriendly@it{\PYGfriendly@bf{\PYGfriendly@ff{#1}}}}}}}
11 | \def\PYGfriendly#1#2{\PYGfriendly@reset\PYGfriendly@toks#1+\relax+\PYGfriendly@do{#2}}
12 |
13 | \@namedef{PYGfriendly@tok@w}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
14 | \@namedef{PYGfriendly@tok@c}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
15 | \@namedef{PYGfriendly@tok@cp}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
16 | \@namedef{PYGfriendly@tok@cs}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}\def\PYGfriendly@bc##1{{\setlength{\fboxsep}{0pt}\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}}
17 | \@namedef{PYGfriendly@tok@k}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
18 | \@namedef{PYGfriendly@tok@kp}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
19 | \@namedef{PYGfriendly@tok@kt}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.56,0.13,0.00}{##1}}}
20 | \@namedef{PYGfriendly@tok@o}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
21 | \@namedef{PYGfriendly@tok@ow}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
22 | \@namedef{PYGfriendly@tok@nb}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
23 | \@namedef{PYGfriendly@tok@nf}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
24 | \@namedef{PYGfriendly@tok@nc}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
25 | \@namedef{PYGfriendly@tok@nn}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
26 | \@namedef{PYGfriendly@tok@ne}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
27 | \@namedef{PYGfriendly@tok@nv}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
28 | \@namedef{PYGfriendly@tok@no}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.68,0.84}{##1}}}
29 | \@namedef{PYGfriendly@tok@nl}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.13,0.44}{##1}}}
30 | \@namedef{PYGfriendly@tok@ni}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.84,0.33,0.22}{##1}}}
31 | \@namedef{PYGfriendly@tok@na}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
32 | \@namedef{PYGfriendly@tok@nt}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.02,0.16,0.45}{##1}}}
33 | \@namedef{PYGfriendly@tok@nd}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
34 | \@namedef{PYGfriendly@tok@s}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
35 | \@namedef{PYGfriendly@tok@sd}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
36 | \@namedef{PYGfriendly@tok@si}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.44,0.63,0.82}{##1}}}
37 | \@namedef{PYGfriendly@tok@se}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
38 | \@namedef{PYGfriendly@tok@sr}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.14,0.33,0.53}{##1}}}
39 | \@namedef{PYGfriendly@tok@ss}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.32,0.47,0.09}{##1}}}
40 | \@namedef{PYGfriendly@tok@sx}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
41 | \@namedef{PYGfriendly@tok@m}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
42 | \@namedef{PYGfriendly@tok@gh}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
43 | \@namedef{PYGfriendly@tok@gu}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
44 | \@namedef{PYGfriendly@tok@gd}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
45 | \@namedef{PYGfriendly@tok@gi}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
46 | \@namedef{PYGfriendly@tok@gr}{\def\PYGfriendly@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
47 | \@namedef{PYGfriendly@tok@ge}{\let\PYGfriendly@it=\textit}
48 | \@namedef{PYGfriendly@tok@gs}{\let\PYGfriendly@bf=\textbf}
49 | \@namedef{PYGfriendly@tok@gp}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
50 | \@namedef{PYGfriendly@tok@go}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
51 | \@namedef{PYGfriendly@tok@gt}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
52 | \@namedef{PYGfriendly@tok@err}{\def\PYGfriendly@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}}
53 | \@namedef{PYGfriendly@tok@kc}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
54 | \@namedef{PYGfriendly@tok@kd}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
55 | \@namedef{PYGfriendly@tok@kn}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
56 | \@namedef{PYGfriendly@tok@kr}{\let\PYGfriendly@bf=\textbf\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
57 | \@namedef{PYGfriendly@tok@bp}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
58 | \@namedef{PYGfriendly@tok@fm}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
59 | \@namedef{PYGfriendly@tok@vc}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
60 | \@namedef{PYGfriendly@tok@vg}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
61 | \@namedef{PYGfriendly@tok@vi}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
62 | \@namedef{PYGfriendly@tok@vm}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
63 | \@namedef{PYGfriendly@tok@sa}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
64 | \@namedef{PYGfriendly@tok@sb}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
65 | \@namedef{PYGfriendly@tok@sc}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
66 | \@namedef{PYGfriendly@tok@dl}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
67 | \@namedef{PYGfriendly@tok@s2}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
68 | \@namedef{PYGfriendly@tok@sh}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
69 | \@namedef{PYGfriendly@tok@s1}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
70 | \@namedef{PYGfriendly@tok@mb}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
71 | \@namedef{PYGfriendly@tok@mf}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
72 | \@namedef{PYGfriendly@tok@mh}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
73 | \@namedef{PYGfriendly@tok@mi}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
74 | \@namedef{PYGfriendly@tok@il}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
75 | \@namedef{PYGfriendly@tok@mo}{\def\PYGfriendly@tc##1{\textcolor[rgb]{0.25,0.63,0.44}{##1}}}
76 | \@namedef{PYGfriendly@tok@ch}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
77 | \@namedef{PYGfriendly@tok@cm}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
78 | \@namedef{PYGfriendly@tok@cpf}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
79 | \@namedef{PYGfriendly@tok@c1}{\let\PYGfriendly@it=\textit\def\PYGfriendly@tc##1{\textcolor[rgb]{0.38,0.63,0.69}{##1}}}
80 |
81 | \def\PYGfriendlyZbs{\char`\\}
82 | \def\PYGfriendlyZus{\char`\_}
83 | \def\PYGfriendlyZob{\char`\{}
84 | \def\PYGfriendlyZcb{\char`\}}
85 | \def\PYGfriendlyZca{\char`\^}
86 | \def\PYGfriendlyZam{\char`\&}
87 | \def\PYGfriendlyZlt{\char`\<}
88 | \def\PYGfriendlyZgt{\char`\>}
89 | \def\PYGfriendlyZsh{\char`\#}
90 | \def\PYGfriendlyZpc{\char`\%}
91 | \def\PYGfriendlyZdl{\char`\$}
92 | \def\PYGfriendlyZhy{\char`\-}
93 | \def\PYGfriendlyZsq{\char`\'}
94 | \def\PYGfriendlyZdq{\char`\"}
95 | \def\PYGfriendlyZti{\char`\~}
96 | % for compatibility with earlier versions
97 | \def\PYGfriendlyZat{@}
98 | \def\PYGfriendlyZlb{[}
99 | \def\PYGfriendlyZrb{]}
100 | \makeatother
101 |
102 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/brute_force_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/brute_force_1.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/brute_force_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/brute_force_2.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/brute_force_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/brute_force_3.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/brute_force_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/brute_force_4.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/dual_core.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/dual_core.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/gpu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/gpu.jpg
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.aux:
--------------------------------------------------------------------------------
1 | \relax
2 | \providecommand\hyper@newdestlabel[2]{}
3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
5 | \global\let\oldcontentsline\contentsline
6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
7 | \global\let\oldnewlabel\newlabel
8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2}
9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
10 | \AtEndDocument{\ifx\hyper@anchor\@undefined
11 | \let\contentsline\oldcontentsline
12 | \let\newlabel\oldnewlabel
13 | \fi}
14 | \fi}
15 | \global\let\hyper@last\relax
16 | \gdef\HyperFirstAtBeginDocument#1{#1}
17 | \providecommand*\HyPL@Entry[1]{}
18 | \HyPL@Entry{0<
>}
19 | \providecommand \oddpage@label [2]{}
20 | \@writefile{nav}{\headcommand {\slideentry {0}{0}{1}{1/1}{}{0}}}
21 | \@writefile{nav}{\headcommand {\beamer@framepages {1}{1}}}
22 | \HyPL@Entry{1<>}
23 | \@writefile{toc}{\beamer@sectionintoc {1}{Introduction}{2}{0}{1}}
24 | \@writefile{nav}{\headcommand {\beamer@sectionpages {1}{1}}}
25 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {1}{1}}}
26 | \@writefile{nav}{\headcommand {\sectionentry {1}{Introduction}{2}{Introduction}{0}}}
27 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{1}{2/2}{}{0}}}
28 | \@writefile{nav}{\headcommand {\beamer@framepages {2}{2}}}
29 | \HyPL@Entry{2<>}
30 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{2}{3/3}{}{0}}}
31 | \@writefile{nav}{\headcommand {\beamer@framepages {3}{3}}}
32 | \HyPL@Entry{3<>}
33 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{3}{4/4}{}{0}}}
34 | \@writefile{nav}{\headcommand {\beamer@framepages {4}{4}}}
35 | \HyPL@Entry{4<>}
36 | \@writefile{toc}{\beamer@sectionintoc {2}{Assessment}{5}{0}{2}}
37 | \@writefile{nav}{\headcommand {\beamer@sectionpages {2}{4}}}
38 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {2}{4}}}
39 | \@writefile{nav}{\headcommand {\sectionentry {2}{Assessment}{5}{Assessment}{0}}}
40 | \@writefile{nav}{\headcommand {\slideentry {2}{0}{1}{5/5}{}{0}}}
41 | \@writefile{nav}{\headcommand {\beamer@framepages {5}{5}}}
42 | \HyPL@Entry{5<>}
43 | \@writefile{toc}{\beamer@sectionintoc {3}{Topics}{6}{0}{3}}
44 | \@writefile{nav}{\headcommand {\beamer@sectionpages {5}{5}}}
45 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {5}{5}}}
46 | \@writefile{nav}{\headcommand {\sectionentry {3}{Topics}{6}{Topics}{0}}}
47 | \@writefile{nav}{\headcommand {\slideentry {3}{0}{1}{6/6}{}{0}}}
48 | \@writefile{nav}{\headcommand {\beamer@framepages {6}{6}}}
49 | \HyPL@Entry{6<>}
50 | \@writefile{toc}{\beamer@sectionintoc {4}{Motivation}{7}{0}{4}}
51 | \@writefile{nav}{\headcommand {\beamer@sectionpages {6}{6}}}
52 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {6}{6}}}
53 | \@writefile{nav}{\headcommand {\sectionentry {4}{Motivation}{7}{Motivation}{0}}}
54 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{1}{7/7}{}{0}}}
55 | \@writefile{nav}{\headcommand {\beamer@framepages {7}{7}}}
56 | \HyPL@Entry{7<>}
57 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{2}{8/8}{}{0}}}
58 | \@writefile{nav}{\headcommand {\beamer@framepages {8}{8}}}
59 | \HyPL@Entry{8<>}
60 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{3}{9/9}{}{0}}}
61 | \@writefile{nav}{\headcommand {\beamer@framepages {9}{9}}}
62 | \HyPL@Entry{9<>}
63 | \@writefile{snm}{\beamer@slide {eq:earnings}{10}}
64 | \newlabel{eq:earnings}{{3}{10}{Motivation}{Doc-Start}{}}
65 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{4}{10/10}{}{0}}}
66 | \@writefile{nav}{\headcommand {\beamer@framepages {10}{10}}}
67 | \HyPL@Entry{10<>}
68 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{5}{11/11}{}{0}}}
69 | \@writefile{nav}{\headcommand {\beamer@framepages {11}{11}}}
70 | \HyPL@Entry{11<>}
71 | \@writefile{toc}{\beamer@sectionintoc {5}{Mathematics}{12}{0}{5}}
72 | \@writefile{nav}{\headcommand {\beamer@sectionpages {7}{11}}}
73 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {7}{11}}}
74 | \@writefile{nav}{\headcommand {\sectionentry {5}{Mathematics}{12}{Mathematics}{0}}}
75 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{1}{12/12}{}{0}}}
76 | \@writefile{nav}{\headcommand {\beamer@framepages {12}{12}}}
77 | \HyPL@Entry{12<>}
78 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{2}{13/14}{}{0}}}
79 | \@writefile{nav}{\headcommand {\beamer@framepages {13}{14}}}
80 | \HyPL@Entry{14<>}
81 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{3}{15/17}{}{0}}}
82 | \@writefile{nav}{\headcommand {\beamer@framepages {15}{17}}}
83 | \HyPL@Entry{17<>}
84 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{4}{18/18}{}{0}}}
85 | \@writefile{nav}{\headcommand {\beamer@framepages {18}{18}}}
86 | \HyPL@Entry{18<>}
87 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{5}{19/19}{}{0}}}
88 | \@writefile{nav}{\headcommand {\beamer@framepages {19}{19}}}
89 | \HyPL@Entry{19<>}
90 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{6}{20/20}{}{0}}}
91 | \@writefile{nav}{\headcommand {\beamer@framepages {20}{20}}}
92 | \HyPL@Entry{20<>}
93 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{7}{21/21}{}{0}}}
94 | \@writefile{nav}{\headcommand {\beamer@framepages {21}{21}}}
95 | \HyPL@Entry{21<>}
96 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{8}{22/22}{}{0}}}
97 | \@writefile{nav}{\headcommand {\beamer@framepages {22}{22}}}
98 | \HyPL@Entry{22<>}
99 | \@writefile{toc}{\beamer@sectionintoc {6}{Programming}{23}{0}{6}}
100 | \@writefile{nav}{\headcommand {\beamer@sectionpages {12}{22}}}
101 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {12}{22}}}
102 | \@writefile{nav}{\headcommand {\sectionentry {6}{Programming}{23}{Programming}{0}}}
103 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{1}{23/23}{}{0}}}
104 | \@writefile{nav}{\headcommand {\beamer@framepages {23}{23}}}
105 | \HyPL@Entry{23<>}
106 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{2}{24/24}{}{0}}}
107 | \@writefile{nav}{\headcommand {\beamer@framepages {24}{24}}}
108 | \HyPL@Entry{24<>}
109 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{3}{25/25}{}{0}}}
110 | \@writefile{nav}{\headcommand {\beamer@framepages {25}{25}}}
111 | \HyPL@Entry{25<>}
112 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{4}{26/26}{}{0}}}
113 | \@writefile{nav}{\headcommand {\beamer@framepages {26}{26}}}
114 | \HyPL@Entry{26<>}
115 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{5}{27/27}{}{0}}}
116 | \@writefile{nav}{\headcommand {\beamer@framepages {27}{27}}}
117 | \HyPL@Entry{27<>}
118 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{6}{28/28}{}{0}}}
119 | \@writefile{nav}{\headcommand {\beamer@framepages {28}{28}}}
120 | \HyPL@Entry{28<>}
121 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{7}{29/29}{}{0}}}
122 | \@writefile{nav}{\headcommand {\beamer@framepages {29}{29}}}
123 | \HyPL@Entry{29<>}
124 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{8}{30/30}{}{0}}}
125 | \@writefile{nav}{\headcommand {\beamer@framepages {30}{30}}}
126 | \HyPL@Entry{30<>}
127 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{9}{31/31}{}{0}}}
128 | \@writefile{nav}{\headcommand {\beamer@framepages {31}{31}}}
129 | \HyPL@Entry{31<>}
130 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{10}{32/32}{}{0}}}
131 | \@writefile{nav}{\headcommand {\beamer@framepages {32}{32}}}
132 | \HyPL@Entry{32<>}
133 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{11}{33/33}{}{0}}}
134 | \@writefile{nav}{\headcommand {\beamer@framepages {33}{33}}}
135 | \HyPL@Entry{33<>}
136 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{12}{34/34}{}{0}}}
137 | \@writefile{nav}{\headcommand {\beamer@framepages {34}{34}}}
138 | \HyPL@Entry{34<>}
139 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{13}{35/35}{}{0}}}
140 | \@writefile{nav}{\headcommand {\beamer@framepages {35}{35}}}
141 | \HyPL@Entry{35<>}
142 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{14}{36/36}{}{0}}}
143 | \@writefile{nav}{\headcommand {\beamer@framepages {36}{36}}}
144 | \HyPL@Entry{36<>}
145 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{15}{37/37}{}{0}}}
146 | \@writefile{nav}{\headcommand {\beamer@framepages {37}{37}}}
147 | \HyPL@Entry{37<>}
148 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{16}{38/38}{}{0}}}
149 | \@writefile{nav}{\headcommand {\beamer@framepages {38}{38}}}
150 | \HyPL@Entry{38<>}
151 | \@writefile{nav}{\headcommand {\slideentry {6}{0}{17}{39/39}{}{0}}}
152 | \@writefile{nav}{\headcommand {\beamer@framepages {39}{39}}}
153 | \HyPL@Entry{39<>}
154 | \@writefile{toc}{\beamer@sectionintoc {7}{Need for Analysis}{40}{0}{7}}
155 | \@writefile{nav}{\headcommand {\beamer@sectionpages {23}{39}}}
156 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {23}{39}}}
157 | \@writefile{nav}{\headcommand {\sectionentry {7}{Need for Analysis}{40}{Need for Analysis}{0}}}
158 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{1}{40/40}{}{0}}}
159 | \@writefile{nav}{\headcommand {\beamer@framepages {40}{40}}}
160 | \HyPL@Entry{40<>}
161 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{2}{41/41}{}{0}}}
162 | \@writefile{nav}{\headcommand {\beamer@framepages {41}{41}}}
163 | \HyPL@Entry{41<>}
164 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{3}{42/42}{}{0}}}
165 | \@writefile{nav}{\headcommand {\beamer@framepages {42}{42}}}
166 | \HyPL@Entry{42<>}
167 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{4}{43/43}{}{0}}}
168 | \@writefile{nav}{\headcommand {\beamer@framepages {43}{43}}}
169 | \HyPL@Entry{43<>}
170 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{5}{44/44}{}{0}}}
171 | \@writefile{nav}{\headcommand {\beamer@framepages {44}{44}}}
172 | \HyPL@Entry{44<>}
173 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{6}{45/45}{}{0}}}
174 | \@writefile{nav}{\headcommand {\beamer@framepages {45}{45}}}
175 | \HyPL@Entry{45<>}
176 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{7}{46/46}{}{0}}}
177 | \@writefile{nav}{\headcommand {\beamer@framepages {46}{46}}}
178 | \HyPL@Entry{46<>}
179 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{8}{47/47}{}{0}}}
180 | \@writefile{nav}{\headcommand {\beamer@framepages {47}{47}}}
181 | \HyPL@Entry{47<>}
182 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{9}{48/48}{}{0}}}
183 | \@writefile{nav}{\headcommand {\beamer@framepages {48}{48}}}
184 | \HyPL@Entry{48<>}
185 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{10}{49/49}{}{0}}}
186 | \@writefile{nav}{\headcommand {\beamer@framepages {49}{49}}}
187 | \HyPL@Entry{49<>}
188 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{11}{50/50}{}{0}}}
189 | \@writefile{nav}{\headcommand {\beamer@framepages {50}{50}}}
190 | \HyPL@Entry{50<>}
191 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{12}{51/51}{}{0}}}
192 | \@writefile{nav}{\headcommand {\beamer@framepages {51}{51}}}
193 | \HyPL@Entry{51<>}
194 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{13}{52/52}{}{0}}}
195 | \@writefile{nav}{\headcommand {\beamer@framepages {52}{52}}}
196 | \HyPL@Entry{52<>}
197 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{14}{53/53}{}{0}}}
198 | \@writefile{nav}{\headcommand {\beamer@framepages {53}{53}}}
199 | \HyPL@Entry{53<>}
200 | \@writefile{nav}{\headcommand {\slideentry {7}{0}{15}{54/54}{}{0}}}
201 | \@writefile{nav}{\headcommand {\beamer@framepages {54}{54}}}
202 | \HyPL@Entry{54<>}
203 | \@writefile{toc}{\beamer@sectionintoc {8}{Programming tools}{55}{0}{8}}
204 | \@writefile{nav}{\headcommand {\beamer@sectionpages {40}{54}}}
205 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {40}{54}}}
206 | \@writefile{nav}{\headcommand {\sectionentry {8}{Programming tools}{55}{Programming tools}{0}}}
207 | \@writefile{nav}{\headcommand {\slideentry {8}{0}{1}{55/55}{}{0}}}
208 | \@writefile{nav}{\headcommand {\beamer@framepages {55}{55}}}
209 | \HyPL@Entry{55<>}
210 | \@writefile{nav}{\headcommand {\slideentry {8}{0}{2}{56/56}{}{0}}}
211 | \@writefile{nav}{\headcommand {\beamer@framepages {56}{56}}}
212 | \HyPL@Entry{56<>}
213 | \@writefile{nav}{\headcommand {\slideentry {8}{0}{3}{57/57}{}{0}}}
214 | \@writefile{nav}{\headcommand {\beamer@framepages {57}{57}}}
215 | \@writefile{nav}{\headcommand {\beamer@partpages {1}{57}}}
216 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {55}{57}}}
217 | \@writefile{nav}{\headcommand {\beamer@sectionpages {55}{57}}}
218 | \@writefile{nav}{\headcommand {\beamer@documentpages {57}}}
219 | \@writefile{nav}{\headcommand {\gdef \inserttotalframenumber {54}}}
220 | \gdef\minted@oldcachelist{,
221 | default-pyg-prefix.pygstyle,
222 | friendly.pygstyle,
223 | 6FB4CCF74C7BDCAEFF65CF0C90E0A25F0B89A0F046740D7F88D4B07B9BED7A06.pygtex,
224 | 2A20D064E5B48BE32BA789F4D587681385D0BD28A1E4792CF3121F1259CE2057.pygtex,
225 | 338FAB092F754A86073BB22A33F6852184A9A22770301CD7D1F5723F317C5665.pygtex,
226 | C489745F93B72AC9F19D2216C755D0F184A9A22770301CD7D1F5723F317C5665.pygtex,
227 | E96D923064AB1C3D7D66F328B0305D8684A9A22770301CD7D1F5723F317C5665.pygtex,
228 | B2741080E8A5EB900163B849C77D51A884A9A22770301CD7D1F5723F317C5665.pygtex}
229 | \gdef \@abspage@last{57}
230 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.nav:
--------------------------------------------------------------------------------
1 | \headcommand {\slideentry {0}{0}{1}{1/1}{}{0}}
2 | \headcommand {\beamer@framepages {1}{1}}
3 | \headcommand {\beamer@sectionpages {1}{1}}
4 | \headcommand {\beamer@subsectionpages {1}{1}}
5 | \headcommand {\sectionentry {1}{Introduction}{2}{Introduction}{0}}
6 | \headcommand {\slideentry {1}{0}{1}{2/2}{}{0}}
7 | \headcommand {\beamer@framepages {2}{2}}
8 | \headcommand {\slideentry {1}{0}{2}{3/3}{}{0}}
9 | \headcommand {\beamer@framepages {3}{3}}
10 | \headcommand {\slideentry {1}{0}{3}{4/4}{}{0}}
11 | \headcommand {\beamer@framepages {4}{4}}
12 | \headcommand {\beamer@sectionpages {2}{4}}
13 | \headcommand {\beamer@subsectionpages {2}{4}}
14 | \headcommand {\sectionentry {2}{Assessment}{5}{Assessment}{0}}
15 | \headcommand {\slideentry {2}{0}{1}{5/5}{}{0}}
16 | \headcommand {\beamer@framepages {5}{5}}
17 | \headcommand {\beamer@sectionpages {5}{5}}
18 | \headcommand {\beamer@subsectionpages {5}{5}}
19 | \headcommand {\sectionentry {3}{Topics}{6}{Topics}{0}}
20 | \headcommand {\slideentry {3}{0}{1}{6/6}{}{0}}
21 | \headcommand {\beamer@framepages {6}{6}}
22 | \headcommand {\beamer@sectionpages {6}{6}}
23 | \headcommand {\beamer@subsectionpages {6}{6}}
24 | \headcommand {\sectionentry {4}{Motivation}{7}{Motivation}{0}}
25 | \headcommand {\slideentry {4}{0}{1}{7/7}{}{0}}
26 | \headcommand {\beamer@framepages {7}{7}}
27 | \headcommand {\slideentry {4}{0}{2}{8/8}{}{0}}
28 | \headcommand {\beamer@framepages {8}{8}}
29 | \headcommand {\slideentry {4}{0}{3}{9/9}{}{0}}
30 | \headcommand {\beamer@framepages {9}{9}}
31 | \headcommand {\slideentry {4}{0}{4}{10/10}{}{0}}
32 | \headcommand {\beamer@framepages {10}{10}}
33 | \headcommand {\slideentry {4}{0}{5}{11/11}{}{0}}
34 | \headcommand {\beamer@framepages {11}{11}}
35 | \headcommand {\beamer@sectionpages {7}{11}}
36 | \headcommand {\beamer@subsectionpages {7}{11}}
37 | \headcommand {\sectionentry {5}{Mathematics}{12}{Mathematics}{0}}
38 | \headcommand {\slideentry {5}{0}{1}{12/12}{}{0}}
39 | \headcommand {\beamer@framepages {12}{12}}
40 | \headcommand {\slideentry {5}{0}{2}{13/14}{}{0}}
41 | \headcommand {\beamer@framepages {13}{14}}
42 | \headcommand {\slideentry {5}{0}{3}{15/17}{}{0}}
43 | \headcommand {\beamer@framepages {15}{17}}
44 | \headcommand {\slideentry {5}{0}{4}{18/18}{}{0}}
45 | \headcommand {\beamer@framepages {18}{18}}
46 | \headcommand {\slideentry {5}{0}{5}{19/19}{}{0}}
47 | \headcommand {\beamer@framepages {19}{19}}
48 | \headcommand {\slideentry {5}{0}{6}{20/20}{}{0}}
49 | \headcommand {\beamer@framepages {20}{20}}
50 | \headcommand {\slideentry {5}{0}{7}{21/21}{}{0}}
51 | \headcommand {\beamer@framepages {21}{21}}
52 | \headcommand {\slideentry {5}{0}{8}{22/22}{}{0}}
53 | \headcommand {\beamer@framepages {22}{22}}
54 | \headcommand {\beamer@sectionpages {12}{22}}
55 | \headcommand {\beamer@subsectionpages {12}{22}}
56 | \headcommand {\sectionentry {6}{Programming}{23}{Programming}{0}}
57 | \headcommand {\slideentry {6}{0}{1}{23/23}{}{0}}
58 | \headcommand {\beamer@framepages {23}{23}}
59 | \headcommand {\slideentry {6}{0}{2}{24/24}{}{0}}
60 | \headcommand {\beamer@framepages {24}{24}}
61 | \headcommand {\slideentry {6}{0}{3}{25/25}{}{0}}
62 | \headcommand {\beamer@framepages {25}{25}}
63 | \headcommand {\slideentry {6}{0}{4}{26/26}{}{0}}
64 | \headcommand {\beamer@framepages {26}{26}}
65 | \headcommand {\slideentry {6}{0}{5}{27/27}{}{0}}
66 | \headcommand {\beamer@framepages {27}{27}}
67 | \headcommand {\slideentry {6}{0}{6}{28/28}{}{0}}
68 | \headcommand {\beamer@framepages {28}{28}}
69 | \headcommand {\slideentry {6}{0}{7}{29/29}{}{0}}
70 | \headcommand {\beamer@framepages {29}{29}}
71 | \headcommand {\slideentry {6}{0}{8}{30/30}{}{0}}
72 | \headcommand {\beamer@framepages {30}{30}}
73 | \headcommand {\slideentry {6}{0}{9}{31/31}{}{0}}
74 | \headcommand {\beamer@framepages {31}{31}}
75 | \headcommand {\slideentry {6}{0}{10}{32/32}{}{0}}
76 | \headcommand {\beamer@framepages {32}{32}}
77 | \headcommand {\slideentry {6}{0}{11}{33/33}{}{0}}
78 | \headcommand {\beamer@framepages {33}{33}}
79 | \headcommand {\slideentry {6}{0}{12}{34/34}{}{0}}
80 | \headcommand {\beamer@framepages {34}{34}}
81 | \headcommand {\slideentry {6}{0}{13}{35/35}{}{0}}
82 | \headcommand {\beamer@framepages {35}{35}}
83 | \headcommand {\slideentry {6}{0}{14}{36/36}{}{0}}
84 | \headcommand {\beamer@framepages {36}{36}}
85 | \headcommand {\slideentry {6}{0}{15}{37/37}{}{0}}
86 | \headcommand {\beamer@framepages {37}{37}}
87 | \headcommand {\slideentry {6}{0}{16}{38/38}{}{0}}
88 | \headcommand {\beamer@framepages {38}{38}}
89 | \headcommand {\slideentry {6}{0}{17}{39/39}{}{0}}
90 | \headcommand {\beamer@framepages {39}{39}}
91 | \headcommand {\beamer@sectionpages {23}{39}}
92 | \headcommand {\beamer@subsectionpages {23}{39}}
93 | \headcommand {\sectionentry {7}{Need for Analysis}{40}{Need for Analysis}{0}}
94 | \headcommand {\slideentry {7}{0}{1}{40/40}{}{0}}
95 | \headcommand {\beamer@framepages {40}{40}}
96 | \headcommand {\slideentry {7}{0}{2}{41/41}{}{0}}
97 | \headcommand {\beamer@framepages {41}{41}}
98 | \headcommand {\slideentry {7}{0}{3}{42/42}{}{0}}
99 | \headcommand {\beamer@framepages {42}{42}}
100 | \headcommand {\slideentry {7}{0}{4}{43/43}{}{0}}
101 | \headcommand {\beamer@framepages {43}{43}}
102 | \headcommand {\slideentry {7}{0}{5}{44/44}{}{0}}
103 | \headcommand {\beamer@framepages {44}{44}}
104 | \headcommand {\slideentry {7}{0}{6}{45/45}{}{0}}
105 | \headcommand {\beamer@framepages {45}{45}}
106 | \headcommand {\slideentry {7}{0}{7}{46/46}{}{0}}
107 | \headcommand {\beamer@framepages {46}{46}}
108 | \headcommand {\slideentry {7}{0}{8}{47/47}{}{0}}
109 | \headcommand {\beamer@framepages {47}{47}}
110 | \headcommand {\slideentry {7}{0}{9}{48/48}{}{0}}
111 | \headcommand {\beamer@framepages {48}{48}}
112 | \headcommand {\slideentry {7}{0}{10}{49/49}{}{0}}
113 | \headcommand {\beamer@framepages {49}{49}}
114 | \headcommand {\slideentry {7}{0}{11}{50/50}{}{0}}
115 | \headcommand {\beamer@framepages {50}{50}}
116 | \headcommand {\slideentry {7}{0}{12}{51/51}{}{0}}
117 | \headcommand {\beamer@framepages {51}{51}}
118 | \headcommand {\slideentry {7}{0}{13}{52/52}{}{0}}
119 | \headcommand {\beamer@framepages {52}{52}}
120 | \headcommand {\slideentry {7}{0}{14}{53/53}{}{0}}
121 | \headcommand {\beamer@framepages {53}{53}}
122 | \headcommand {\slideentry {7}{0}{15}{54/54}{}{0}}
123 | \headcommand {\beamer@framepages {54}{54}}
124 | \headcommand {\beamer@sectionpages {40}{54}}
125 | \headcommand {\beamer@subsectionpages {40}{54}}
126 | \headcommand {\sectionentry {8}{Programming tools}{55}{Programming tools}{0}}
127 | \headcommand {\slideentry {8}{0}{1}{55/55}{}{0}}
128 | \headcommand {\beamer@framepages {55}{55}}
129 | \headcommand {\slideentry {8}{0}{2}{56/56}{}{0}}
130 | \headcommand {\beamer@framepages {56}{56}}
131 | \headcommand {\slideentry {8}{0}{3}{57/57}{}{0}}
132 | \headcommand {\beamer@framepages {57}{57}}
133 | \headcommand {\beamer@partpages {1}{57}}
134 | \headcommand {\beamer@subsectionpages {55}{57}}
135 | \headcommand {\beamer@sectionpages {55}{57}}
136 | \headcommand {\beamer@documentpages {57}}
137 | \headcommand {\gdef \inserttotalframenumber {54}}
138 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.out:
--------------------------------------------------------------------------------
1 | \BOOKMARK [2][]{Outline0.1}{Introduction}{}% 1
2 | \BOOKMARK [2][]{Outline0.2}{Assessment}{}% 2
3 | \BOOKMARK [2][]{Outline0.3}{Topics}{}% 3
4 | \BOOKMARK [2][]{Outline0.4}{Motivation}{}% 4
5 | \BOOKMARK [2][]{Outline0.5}{Mathematics}{}% 5
6 | \BOOKMARK [2][]{Outline0.6}{Programming}{}% 6
7 | \BOOKMARK [2][]{Outline0.7}{Need\040for\040Analysis}{}% 7
8 | \BOOKMARK [2][]{Outline0.8}{Programming\040tools}{}% 8
9 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/lecture_1.pdf
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.snm:
--------------------------------------------------------------------------------
1 | \beamer@slide {eq:earnings}{10}
2 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.synctex.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/lecture_1.synctex.gz
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.toc:
--------------------------------------------------------------------------------
1 | \beamer@sectionintoc {1}{Introduction}{2}{0}{1}
2 | \beamer@sectionintoc {2}{Assessment}{5}{0}{2}
3 | \beamer@sectionintoc {3}{Topics}{6}{0}{3}
4 | \beamer@sectionintoc {4}{Motivation}{7}{0}{4}
5 | \beamer@sectionintoc {5}{Mathematics}{12}{0}{5}
6 | \beamer@sectionintoc {6}{Programming}{23}{0}{6}
7 | \beamer@sectionintoc {7}{Need for Analysis}{40}{0}{7}
8 | \beamer@sectionintoc {8}{Programming tools}{55}{0}{8}
9 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/lecture_1.vrb:
--------------------------------------------------------------------------------
1 |
2 |
3 | \begin{pythoncode}
4 | In [19]: (2**1000 / 10**(9 + 12)) / 31556926
5 | Out[19]:
6 | 3395478403651443492780079558636357072806789899958
7 | 9934946253966193359614657173392696525586136485406
8 | 0286985707326991591901311029244639453805988092045
9 | 9330726574551199243812350729415493323101993883015
10 | 7139456970702643798644840335204916851424450993981
11 | 6790601568621661265174170019
12 | \end{pythoncode}
13 |
14 | For comparison:
15 |
16 | \begin{pythoncode}
17 | In [20]: 5 * 10**9 # Expected lifespan of sun
18 | Out[20]: 5000000000
19 | \end{pythoncode}
20 |
21 |
22 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/processor_clock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/processor_clock.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/sp1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/sp1.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/sp2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/sp2.png
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff.fig:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.5c
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
23 | 0 0 1.00 60.00 120.00
24 | 2745 7515 2745 1935
25 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
26 | 0 0 1.00 60.00 120.00
27 | 2115 6795 11025 6795
28 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
29 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
30 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
31 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
32 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8235 3195 Julia\001
33 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
34 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
35 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
36 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/tradeoff.pdf
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff2.fig:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.7
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8145 2835 101 101 8044 2835 8246 2835
23 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
24 | 0 0 1.00 60.00 120.00
25 | 2745 7515 2745 1935
26 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
27 | 0 0 1.00 60.00 120.00
28 | 2115 6795 11025 6795
29 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
30 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
31 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
32 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
33 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
34 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
35 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
36 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8055 3195 Julia\001
37 | 4 0 0 50 -1 16 18 0.0000 4 135 540 6750 3150 MATLAB\001
38 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff2.fig.bak:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.5c
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 7650 3330 101 101 7549 3330 7751 3330
23 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
24 | 0 0 1.00 60.00 120.00
25 | 2745 7515 2745 1935
26 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
27 | 0 0 1.00 60.00 120.00
28 | 2115 6795 11025 6795
29 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
30 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
31 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
32 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
33 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
34 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
35 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
36 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8055 3195 Julia\001
37 | 4 0 0 50 -1 16 18 0.0000 4 135 540 6615 3735 MATLAB\001
38 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/tradeoff2.pdf
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff3.fig:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.7
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8820 3375 101 101 8719 3375 8921 3375
23 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8145 2835 101 101 8044 2835 8246 2835
24 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
25 | 0 0 1.00 60.00 120.00
26 | 2745 7515 2745 1935
27 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
28 | 0 0 1.00 60.00 120.00
29 | 2115 6795 11025 6795
30 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
31 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
32 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
33 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
34 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
35 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
36 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
37 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8055 3195 Julia\001
38 | 4 0 0 50 -1 16 18 0.0000 4 135 450 9225 3555 Julia\001
39 | 4 0 0 50 -1 16 18 0.0000 4 135 540 6750 3150 MATLAB\001
40 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff3.fig.bak:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.5c
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 7650 3330 101 101 7549 3330 7751 3330
23 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8820 3375 101 101 8719 3375 8921 3375
24 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
25 | 0 0 1.00 60.00 120.00
26 | 2745 7515 2745 1935
27 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
28 | 0 0 1.00 60.00 120.00
29 | 2115 6795 11025 6795
30 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
31 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
32 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
33 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
34 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
35 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
36 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
37 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8055 3195 Julia\001
38 | 4 0 0 50 -1 16 18 0.0000 4 135 540 6615 3735 MATLAB\001
39 | 4 0 0 50 -1 16 18 0.0000 4 135 450 9225 3555 Julia\001
40 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/tradeoff3.pdf
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff4.fig:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.7
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8820 3375 101 101 8719 3375 8921 3375
23 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8280 2520 101 101 8179 2520 8381 2520
24 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8145 2835 101 101 8044 2835 8246 2835
25 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
26 | 0 0 1.00 60.00 120.00
27 | 2745 7515 2745 1935
28 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
29 | 0 0 1.00 60.00 120.00
30 | 2115 6795 11025 6795
31 | 2 1 0 1 0 0 50 -1 -1 0.000 0 0 -1 1 0 2
32 | 1 1 1.00 60.00 120.00
33 | 4500 2475 7560 2475
34 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
35 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
36 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
37 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
38 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
39 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
40 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
41 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8055 3195 Julia\001
42 | 4 0 0 50 -1 16 18 0.0000 4 135 450 9225 3555 Julia\001
43 | 4 0 0 50 -1 16 18 0.0000 4 165 1980 7920 2115 Python + NumPy + Numba\001
44 | 4 0 0 50 -1 16 18 0.0000 4 135 540 6750 3150 MATLAB\001
45 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff4.fig.bak:
--------------------------------------------------------------------------------
1 | #FIG 3.2 Produced by xfig version 3.2.7
2 | Landscape
3 | Center
4 | Metric
5 | A4
6 | 100.00
7 | Single
8 | -2
9 | 1200 2
10 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3960 3375 101 101 3859 3375 4061 3375
11 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 4500 4050 101 101 4399 4050 4601 4050
12 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 540 1215 101 101 439 1215 641 1215
13 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 11745 8145 101 101 11644 8145 11846 8145
14 | 1 4 0 2 7 7 50 -1 20 0.000 1 0.0000 7965 3555 101 101 7864 3555 8066 3555
15 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3600 2880 101 101 3499 2880 3701 2880
16 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 3825 2430 101 101 3724 2430 3926 2430
17 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 9585 6480 101 101 9484 6480 9686 6480
18 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8550 5985 101 101 8449 5985 8651 5985
19 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 8325 5670 101 101 8224 5670 8426 5670
20 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 6615 5445 101 101 6514 5445 6716 5445
21 | 1 4 0 2 0 13 50 -1 20 0.000 1 0.0000 5490 4770 101 101 5389 4770 5591 4770
22 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8820 3375 101 101 8719 3375 8921 3375
23 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8280 2520 101 101 8179 2520 8381 2520
24 | 1 4 0 2 0 8 50 -1 20 0.000 1 0.0000 8145 2835 101 101 8044 2835 8246 2835
25 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
26 | 0 0 1.00 60.00 120.00
27 | 2745 7515 2745 1935
28 | 2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
29 | 0 0 1.00 60.00 120.00
30 | 2115 6795 11025 6795
31 | 2 1 0 1 0 0 50 -1 -1 0.000 0 0 -1 1 0 2
32 | 1 1 1.00 60.00 120.00
33 | 4500 2475 7560 2475
34 | 4 0 0 50 -1 0 20 0.0000 4 165 1170 9315 7515 Machine speed\001
35 | 4 0 0 50 -1 16 18 0.0000 4 165 720 9720 5715 assembly\001
36 | 4 0 0 50 -1 16 18 0.0000 4 135 630 7335 6345 Fortran\001
37 | 4 0 0 50 -1 16 18 0.0000 4 165 360 3285 3735 Ruby\001
38 | 4 0 0 50 -1 16 18 0.0000 4 165 540 4005 2205 Python\001
39 | 4 0 0 50 -1 16 18 0.0000 4 135 90 8280 5400 C\001
40 | 4 0 0 50 -1 0 20 0.0000 4 165 1080 810 2070 Productivity\001
41 | 4 0 7 50 -1 16 18 0.0000 4 135 450 8055 3195 Julia\001
42 | 4 0 0 50 -1 16 18 0.0000 4 135 450 9225 3555 Julia\001
43 | 4 0 0 50 -1 16 18 0.0000 4 165 1980 7920 2115 Python + NumPy + Numba\001
44 | 4 0 0 50 -1 16 18 0.0000 4 135 540 6750 3150 MATLAB\001
45 |
--------------------------------------------------------------------------------
/notebooks/intro_to_python/tex_source_files/tradeoff4.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/notebooks/intro_to_python/tex_source_files/tradeoff4.pdf
--------------------------------------------------------------------------------
/notebooks/js_beta_exercise/.ipynb_checkpoints/js_python-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "e62e9cab",
7 | "metadata": {
8 | "lines_to_next_cell": 1
9 | },
10 | "outputs": [],
11 | "source": [
12 | "import numpy as np\n",
13 | "from scipy.stats import betabinom\n",
14 | "from collections import namedtuple"
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": 2,
20 | "id": "5cd102b7",
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "def successive_approx(T, # Operator (callable)\n",
25 | " x_0, # Initial condition\n",
26 | " tolerance=1e-6, # Error tolerance\n",
27 | " max_iter=10_000, # Max iteration bound\n",
28 | " print_step=25): # Print at multiples\n",
29 | " x = x_0\n",
30 | " error = np.inf\n",
31 | " k = 1\n",
32 | " while error > tolerance and k <= max_iter:\n",
33 | " x_new = T(x)\n",
34 | " error = max(abs(x_new - x))\n",
35 | " if k % print_step == 0:\n",
36 | " print(\"Completed iteration $k with error $error.\")\n",
37 | " end\n",
38 | " x = x_new\n",
39 | " k += 1\n",
40 | " if k < max_iter:\n",
41 | " print(\"Terminated successfully in $k iterations.\")\n",
42 | " else:\n",
43 | " print(\"Warning: Iteration hit max_iter bound $max_iter.\")\n",
44 | " return x"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 9,
50 | "id": "452a9f09",
51 | "metadata": {
52 | "lines_to_next_cell": 1
53 | },
54 | "outputs": [],
55 | "source": [
56 | "Model = namedtuple(\"Model\", (\"w_vals\", \"φ\", \"β\", \"c\")) "
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 10,
62 | "id": "580a63cb",
63 | "metadata": {},
64 | "outputs": [],
65 | "source": [
66 | "def create_job_search_model(\n",
67 | " n=50, # wage grid size\n",
68 | " w_min=10.0, # lowest wage\n",
69 | " w_max=60.0, # highest wage\n",
70 | " a=200, # wage distribution parameter\n",
71 | " b=100, # wage distribution parameter\n",
72 | " β=0.96, # discount factor\n",
73 | " c=10.0 # unemployment compensation\n",
74 | " ):\n",
75 | " w_vals = np.linspace(w_min, w_max, n+1)\n",
76 | " φ = betabinom(n, a, b)\n",
77 | " return Model(w_vals=w_vals, φ=φ, β=β, c=c)"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": 11,
83 | "id": "59529049",
84 | "metadata": {
85 | "lines_to_next_cell": 1
86 | },
87 | "outputs": [],
88 | "source": [
89 | "def g(h, model):\n",
90 | " w_vals, φ, β, c = model.w_vals, model.φ, model.β, model.c\n",
91 | " return c + β * max(w_vals / (1 - β), h) @ φ.pdf"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": 12,
97 | "id": "233d7e5f",
98 | "metadata": {},
99 | "outputs": [],
100 | "source": [
101 | "def compute_hstar(model, h_init=0.0):\n",
102 | " h_star = successive_approx(lambda h: g(h, model), h_init)\n",
103 | " return h_star"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": 13,
109 | "id": "52dc2d2b",
110 | "metadata": {},
111 | "outputs": [],
112 | "source": [
113 | "betas = np.linspace(0.9, 0.99, 20) \n",
114 | "fs = 16"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 14,
120 | "id": "1eab19b7",
121 | "metadata": {},
122 | "outputs": [
123 | {
124 | "ename": "ValueError",
125 | "evalue": "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()",
126 | "output_type": "error",
127 | "traceback": [
128 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
129 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
130 | "\u001b[0;32m/tmp/ipykernel_3559698/3075253328.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mβ\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbetas\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcreate_job_search_model\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mβ\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mβ\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mh\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcompute_hstar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mh_vals\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
131 | "\u001b[0;32m/tmp/ipykernel_3559698/4282290357.py\u001b[0m in \u001b[0;36mcompute_hstar\u001b[0;34m(model, h_init)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcompute_hstar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mh_init\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mh_star\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuccessive_approx\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mh\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mh_init\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mh_star\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
132 | "\u001b[0;32m/tmp/ipykernel_3559698/1058327185.py\u001b[0m in \u001b[0;36msuccessive_approx\u001b[0;34m(T, x_0, tolerance, max_iter, print_step)\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mk\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0merror\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0mtolerance\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mk\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0mmax_iter\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mx_new\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mT\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 11\u001b[0m \u001b[0merror\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_new\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mk\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mprint_step\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
133 | "\u001b[0;32m/tmp/ipykernel_3559698/4282290357.py\u001b[0m in \u001b[0;36m\u001b[0;34m(h)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcompute_hstar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mh_init\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mh_star\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuccessive_approx\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mh\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mh_init\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mh_star\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
134 | "\u001b[0;32m/tmp/ipykernel_3559698/1600755681.py\u001b[0m in \u001b[0;36mg\u001b[0;34m(h, model)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mh\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mw_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mφ\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mβ\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mw_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mφ\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mβ\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mβ\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw_vals\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mβ\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m@\u001b[0m \u001b[0mφ\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpdf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
135 | "\u001b[0;31mValueError\u001b[0m: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
136 | ]
137 | }
138 | ],
139 | "source": [
140 | "h_vals = np.empty_like(betas)\n",
141 | "for i, β in enumerate(betas):\n",
142 | " model = create_job_search_model(β=β)\n",
143 | " h = compute_hstar(model)\n",
144 | " h_vals[i] = h"
145 | ]
146 | },
147 | {
148 | "cell_type": "code",
149 | "execution_count": null,
150 | "id": "4328c35a",
151 | "metadata": {},
152 | "outputs": [],
153 | "source": [
154 | "fig, ax = plt.subplots()\n",
155 | "ax.plot(betas, h_vals, lw=2.0, alpha=0.7, label=\"$h^*(\\\\beta)$\")\n",
156 | "ax.legend(frameon=False, fontsize=fs)\n",
157 | "ax.set_xlabel(\"$\\\\beta$\", fontsize=fs)\n",
158 | "ax.set_ylabel(\"continuation value\", fontsize=fs)"
159 | ]
160 | },
161 | {
162 | "cell_type": "code",
163 | "execution_count": null,
164 | "id": "ec6aadc0",
165 | "metadata": {
166 | "lines_to_next_cell": 2
167 | },
168 | "outputs": [],
169 | "source": [
170 | "plt.show()"
171 | ]
172 | }
173 | ],
174 | "metadata": {
175 | "jupytext": {
176 | "cell_metadata_filter": "-all",
177 | "main_language": "python",
178 | "notebook_metadata_filter": "-all"
179 | },
180 | "kernelspec": {
181 | "display_name": "Python 3 (ipykernel)",
182 | "language": "python",
183 | "name": "python3"
184 | },
185 | "language_info": {
186 | "codemirror_mode": {
187 | "name": "ipython",
188 | "version": 3
189 | },
190 | "file_extension": ".py",
191 | "mimetype": "text/x-python",
192 | "name": "python",
193 | "nbconvert_exporter": "python",
194 | "pygments_lexer": "ipython3",
195 | "version": "3.9.7"
196 | }
197 | },
198 | "nbformat": 4,
199 | "nbformat_minor": 5
200 | }
201 |
--------------------------------------------------------------------------------
/notebooks/js_beta_exercise/.ipynb_checkpoints/js_python_exercise-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "3c9e342a",
6 | "metadata": {},
7 | "source": [
8 | "# Job search\n",
9 | "\n",
10 | "Compute the continuation value as a function of $\\beta$."
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 1,
16 | "id": "e62e9cab",
17 | "metadata": {
18 | "lines_to_next_cell": 1
19 | },
20 | "outputs": [],
21 | "source": [
22 | "import numpy as np\n",
23 | "from scipy.stats import betabinom\n",
24 | "from collections import namedtuple\n",
25 | "import matplotlib.pyplot as plt"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": 2,
31 | "id": "5cd102b7",
32 | "metadata": {},
33 | "outputs": [],
34 | "source": [
35 | "def successive_approx(T, # Operator (callable)\n",
36 | " x_0, # Initial condition\n",
37 | " tolerance=1e-6, # Error tolerance\n",
38 | " max_iter=10_000, # Max iteration bound\n",
39 | " print_step=25, # Print at multiples\n",
40 | " verbose=False): \n",
41 | " x = x_0\n",
42 | " error = np.inf\n",
43 | " k = 1\n",
44 | " while error > tolerance and k <= max_iter:\n",
45 | " x_new = T(x)\n",
46 | " error = np.max(np.abs(x_new - x))\n",
47 | " if verbose and k % print_step == 0:\n",
48 | " print(f\"Completed iteration {k} with error {error}.\")\n",
49 | " x = x_new\n",
50 | " k += 1\n",
51 | " if k < max_iter:\n",
52 | " print(f\"Terminated successfully in {k} iterations.\")\n",
53 | " else:\n",
54 | " print(f\"Warning: Iteration hit max_iter bound {max_iter}.\")\n",
55 | " return x"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": 3,
61 | "id": "452a9f09",
62 | "metadata": {
63 | "lines_to_next_cell": 1
64 | },
65 | "outputs": [],
66 | "source": [
67 | "Model = namedtuple(\"Model\", (\"w_vals\", \"φ\", \"β\", \"c\")) "
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 4,
73 | "id": "580a63cb",
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "def create_job_search_model(\n",
78 | " n=50, # wage grid size\n",
79 | " w_min=10.0, # lowest wage\n",
80 | " w_max=60.0, # highest wage\n",
81 | " a=200, # wage distribution parameter\n",
82 | " b=100, # wage distribution parameter\n",
83 | " β=0.96, # discount factor\n",
84 | " c=10.0 # unemployment compensation\n",
85 | " ):\n",
86 | " w_vals = np.linspace(w_min, w_max, n+1)\n",
87 | " φ = np.array([betabinom(n, a, b).pmf(k) for k in range(n+1)])\n",
88 | " return Model(w_vals=w_vals, φ=φ, β=β, c=c)"
89 | ]
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "id": "f3df0807",
94 | "metadata": {},
95 | "source": [
96 | "The function $g(h) = c + \\beta \\sum_{w'} \\max\\{w'/(1-\\beta), h\\} \\phi(w')$. The fixed point is the continuation value."
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": 5,
102 | "id": "59529049",
103 | "metadata": {
104 | "lines_to_next_cell": 1
105 | },
106 | "outputs": [],
107 | "source": [
108 | "def g(h, model):\n",
109 | " w_vals, φ, β, c = model.w_vals, model.φ, model.β, model.c\n",
110 | " return c + β * np.maximum(w_vals / (1 - β), h) @ φ"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "id": "97cb7c77",
116 | "metadata": {},
117 | "source": [
118 | "Task: Plot the fixed point $h^*$ of $g$ as a function of $\\beta$. Use the values"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": 6,
124 | "id": "52dc2d2b",
125 | "metadata": {},
126 | "outputs": [],
127 | "source": [
128 | "betas = np.linspace(0.9, 0.99, 20) "
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "id": "809fc7d5",
135 | "metadata": {},
136 | "outputs": [],
137 | "source": []
138 | }
139 | ],
140 | "metadata": {
141 | "jupytext": {
142 | "cell_metadata_filter": "-all",
143 | "main_language": "python",
144 | "notebook_metadata_filter": "-all"
145 | },
146 | "kernelspec": {
147 | "display_name": "Python 3 (ipykernel)",
148 | "language": "python",
149 | "name": "python3"
150 | },
151 | "language_info": {
152 | "codemirror_mode": {
153 | "name": "ipython",
154 | "version": 3
155 | },
156 | "file_extension": ".py",
157 | "mimetype": "text/x-python",
158 | "name": "python",
159 | "nbconvert_exporter": "python",
160 | "pygments_lexer": "ipython3",
161 | "version": "3.9.7"
162 | }
163 | },
164 | "nbformat": 4,
165 | "nbformat_minor": 5
166 | }
167 |
--------------------------------------------------------------------------------
/notebooks/js_beta_exercise/js_python_exercise.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "3c9e342a",
6 | "metadata": {},
7 | "source": [
8 | "# Job search\n",
9 | "\n",
10 | "Compute the continuation value as a function of $\\beta$."
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 1,
16 | "id": "e62e9cab",
17 | "metadata": {
18 | "lines_to_next_cell": 1
19 | },
20 | "outputs": [],
21 | "source": [
22 | "import numpy as np\n",
23 | "from scipy.stats import betabinom\n",
24 | "from collections import namedtuple\n",
25 | "import matplotlib.pyplot as plt"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": 2,
31 | "id": "5cd102b7",
32 | "metadata": {},
33 | "outputs": [],
34 | "source": [
35 | "def successive_approx(T, # Operator (callable)\n",
36 | " x_0, # Initial condition\n",
37 | " tolerance=1e-6, # Error tolerance\n",
38 | " max_iter=10_000, # Max iteration bound\n",
39 | " print_step=25, # Print at multiples\n",
40 | " verbose=False): \n",
41 | " x = x_0\n",
42 | " error = np.inf\n",
43 | " k = 1\n",
44 | " while error > tolerance and k <= max_iter:\n",
45 | " x_new = T(x)\n",
46 | " error = np.max(np.abs(x_new - x))\n",
47 | " if verbose and k % print_step == 0:\n",
48 | " print(f\"Completed iteration {k} with error {error}.\")\n",
49 | " x = x_new\n",
50 | " k += 1\n",
51 | " if k < max_iter:\n",
52 | " print(f\"Terminated successfully in {k} iterations.\")\n",
53 | " else:\n",
54 | " print(f\"Warning: Iteration hit max_iter bound {max_iter}.\")\n",
55 | " return x"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": 3,
61 | "id": "452a9f09",
62 | "metadata": {
63 | "lines_to_next_cell": 1
64 | },
65 | "outputs": [],
66 | "source": [
67 | "Model = namedtuple(\"Model\", (\"w_vals\", \"φ\", \"β\", \"c\")) "
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 4,
73 | "id": "580a63cb",
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "def create_job_search_model(\n",
78 | " n=50, # wage grid size\n",
79 | " w_min=10.0, # lowest wage\n",
80 | " w_max=60.0, # highest wage\n",
81 | " a=200, # wage distribution parameter\n",
82 | " b=100, # wage distribution parameter\n",
83 | " β=0.96, # discount factor\n",
84 | " c=10.0 # unemployment compensation\n",
85 | " ):\n",
86 | " w_vals = np.linspace(w_min, w_max, n+1)\n",
87 | " φ = np.array([betabinom(n, a, b).pmf(k) for k in range(n+1)])\n",
88 | " return Model(w_vals=w_vals, φ=φ, β=β, c=c)"
89 | ]
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "id": "f3df0807",
94 | "metadata": {},
95 | "source": [
96 | "The function $g(h) = c + \\beta \\sum_{w'} \\max\\{w'/(1-\\beta), h\\} \\phi(w')$. The fixed point is the continuation value."
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": 5,
102 | "id": "59529049",
103 | "metadata": {
104 | "lines_to_next_cell": 1
105 | },
106 | "outputs": [],
107 | "source": [
108 | "def g(h, model):\n",
109 | " w_vals, φ, β, c = model.w_vals, model.φ, model.β, model.c\n",
110 | " return c + β * np.maximum(w_vals / (1 - β), h) @ φ"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "id": "97cb7c77",
116 | "metadata": {},
117 | "source": [
118 | "Task: Plot the fixed point $h^*$ of $g$ as a function of $\\beta$. Use the values"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": 6,
124 | "id": "52dc2d2b",
125 | "metadata": {},
126 | "outputs": [],
127 | "source": [
128 | "betas = np.linspace(0.9, 0.99, 20) "
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "id": "809fc7d5",
135 | "metadata": {},
136 | "outputs": [],
137 | "source": []
138 | }
139 | ],
140 | "metadata": {
141 | "jupytext": {
142 | "cell_metadata_filter": "-all",
143 | "main_language": "python",
144 | "notebook_metadata_filter": "-all"
145 | },
146 | "kernelspec": {
147 | "display_name": "Python 3 (ipykernel)",
148 | "language": "python",
149 | "name": "python3"
150 | },
151 | "language_info": {
152 | "codemirror_mode": {
153 | "name": "ipython",
154 | "version": 3
155 | },
156 | "file_extension": ".py",
157 | "mimetype": "text/x-python",
158 | "name": "python",
159 | "nbconvert_exporter": "python",
160 | "pygments_lexer": "ipython3",
161 | "version": "3.9.7"
162 | }
163 | },
164 | "nbformat": 4,
165 | "nbformat_minor": 5
166 | }
167 |
--------------------------------------------------------------------------------
/review.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jstac/tokyo_2022_coursework/0270b3c995ea65f90ae21589d2d99751533a006c/review.pdf
--------------------------------------------------------------------------------