scratch.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Scratchpad &#8212; State Space Models: A Modern Approach</title>
  7. <link href="../_static/css/theme.css" rel="stylesheet">
  8. <link href="../_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
  9. <link rel="stylesheet"
  10. href="../_static/vendor/fontawesome/5.13.0/css/all.min.css">
  11. <link rel="preload" as="font" type="font/woff2" crossorigin
  12. href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
  13. <link rel="preload" as="font" type="font/woff2" crossorigin
  14. href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
  15. <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
  16. <link rel="stylesheet" type="text/css" href="../_static/sphinx-book-theme.css?digest=c3fdc42140077d1ad13ad2f1588a4309" />
  17. <link rel="stylesheet" type="text/css" href="../_static/togglebutton.css" />
  18. <link rel="stylesheet" type="text/css" href="../_static/copybutton.css" />
  19. <link rel="stylesheet" type="text/css" href="../_static/mystnb.css" />
  20. <link rel="stylesheet" type="text/css" href="../_static/sphinx-thebe.css" />
  21. <link rel="stylesheet" type="text/css" href="../_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
  22. <link rel="stylesheet" type="text/css" href="../_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
  23. <link rel="preload" as="script" href="../_static/js/index.be7d3bbb2ef33a8344ce.js">
  24. <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  25. <script src="../_static/jquery.js"></script>
  26. <script src="../_static/underscore.js"></script>
  27. <script src="../_static/doctools.js"></script>
  28. <script src="../_static/clipboard.min.js"></script>
  29. <script src="../_static/copybutton.js"></script>
  30. <script>let toggleHintShow = 'Click to show';</script>
  31. <script>let toggleHintHide = 'Click to hide';</script>
  32. <script>let toggleOpenOnPrint = 'true';</script>
  33. <script src="../_static/togglebutton.js"></script>
  34. <script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
  35. <script src="../_static/sphinx-book-theme.d59cb220de22ca1c485ebbdc042f0030.js"></script>
  36. <script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
  37. const thebe_selector = ".thebe,.cell"
  38. const thebe_selector_input = "pre"
  39. const thebe_selector_output = ".output, .cell_output"
  40. </script>
  41. <script async="async" src="../_static/sphinx-thebe.js"></script>
  42. <script>window.MathJax = {"tex": {"macros": {"covMat": "\\boldsymbol{\\Sigma}", "data": "\\mathcal{D}", "defeq": "\\triangleq", "diag": "\\mathrm{diag}", "discreteState": "s", "dotstar": "\\odot", "dynamicsFn": "\\mathbf{f}", "floor": ["\\lfloor#1\\rfloor", 1], "gainMatrix": "\\mathbf{K}", "gainMatrixReverse": "\\mathbf{G}", "gauss": "\\mathcal{N}", "gaussInfo": "\\mathcal{N}_{\\text{info}}", "hidden": "\\mathbf{x}", "hiddenScalar": "x", "hmmInit": "\\boldsymbol{\\pi}", "hmmInitScalar": "\\pi", "hmmObs": "\\mathbf{B}", "hmmObsScalar": "B", "hmmTrans": "\\mathbf{A}", "hmmTransScalar": "A", "infoMat": "\\precMat", "input": "\\mathbf{u}", "inputs": "\\input", "inv": ["{#1}^{-1}", 1], "keyword": ["\\textbf{#1}", 1], "ldsDyn": "\\mathbf{F}", "ldsDynIn": "\\mathbf{B}", "initMean": "\\boldsymbol{\\mean}_0", "initCov": "\\boldsymbol{\\covMat}_0", "ldsObs": "\\mathbf{H}", "ldsObsIn": "\\mathbf{D}", "ldsTrans": "\\ldsDyn", "ldsTransIn": "\\ldsDynIn", "obsCov": "\\mathbf{R}", "obsNoise": "\\boldsymbol{r}", "map": "\\mathrm{map}", "measurementFn": "\\mathbf{h}", "mean": "\\boldsymbol{\\mu}", "mle": "\\mathrm{mle}", "nlatents": "n_x", "nhidden": "\\nlatents", "ninputs": "n_u", "nobs": "n_y", "nsymbols": "n_y", "nstates": "n_s", "obs": "\\mathbf{y}", "obsScalar": "y", "observed": "\\obs", "obsFn": "\\measurementFn", "params": "\\boldsymbol{\\theta}", "precMean": "\\boldsymbol{\\eta}", "precMat": "\\boldsymbol{\\Lambda}", "real": "\\mathbb{R}", "sigmoid": "\\sigma", "softmax": "\\boldsymbol{\\sigma}", "trans": "\\mathsf{T}", "transpose": ["{#1}^{\\trans}", 1], "transCov": "\\mathbf{Q}", "transNoise": "\\mathbf{q}", "valpha": "\\boldsymbol{\\alpha}", "vbeta": "\\boldsymbol{\\beta}", "vdelta": "\\boldsymbol{\\delta}", "vepsilon": "\\boldsymbol{\\epsilon}", "vlambda": "\\boldsymbol{\\lambda}", "vLambda": "\\boldsymbol{\\Lambda}", "vmu": "\\boldsymbol{\\mu}", "vpi": "\\boldsymbol{\\pi}", "vsigma": "\\boldsymbol{\\sigma}", "vSigma": "\\boldsymbol{\\Sigma}", "vone": "\\boldsymbol{1}", "vzero": "\\boldsymbol{0}"}}, "options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
  43. <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
  44. <link rel="index" title="Index" href="../genindex.html" />
  45. <link rel="search" title="Search" href="../search.html" />
  46. <meta name="viewport" content="width=device-width, initial-scale=1" />
  47. <meta name="docsearch:language" content="None">
  48. <!-- Google Analytics -->
  49. </head>
  50. <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
  51. <div class="container-fluid" id="banner"></div>
  52. <div class="container-xl">
  53. <div class="row">
  54. <div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
  55. <div class="navbar-brand-box">
  56. <a class="navbar-brand text-wrap" href="../index.html">
  57. <h1 class="site-logo" id="site-title">State Space Models: A Modern Approach</h1>
  58. </a>
  59. </div><form class="bd-search d-flex align-items-center" action="../search.html" method="get">
  60. <i class="icon fas fa-search"></i>
  61. <input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
  62. </form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
  63. <div class="bd-toc-item active">
  64. <ul class="nav bd-sidenav">
  65. <li class="toctree-l1">
  66. <a class="reference internal" href="../root.html">
  67. State Space Models: A Modern Approach
  68. </a>
  69. </li>
  70. </ul>
  71. <ul class="nav bd-sidenav">
  72. <li class="toctree-l1 has-children">
  73. <a class="reference internal" href="ssm/ssm_index.html">
  74. State Space Models
  75. </a>
  76. <input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/>
  77. <label for="toctree-checkbox-1">
  78. <i class="fas fa-chevron-down">
  79. </i>
  80. </label>
  81. <ul>
  82. <li class="toctree-l2">
  83. <a class="reference internal" href="ssm/ssm_intro.html">
  84. What are State Space Models?
  85. </a>
  86. </li>
  87. <li class="toctree-l2">
  88. <a class="reference internal" href="ssm/hmm.html">
  89. Hidden Markov Models
  90. </a>
  91. </li>
  92. <li class="toctree-l2">
  93. <a class="reference internal" href="ssm/lds.html">
  94. Linear Gaussian SSMs
  95. </a>
  96. </li>
  97. <li class="toctree-l2">
  98. <a class="reference internal" href="ssm/nlds.html">
  99. Nonlinear Gaussian SSMs
  100. </a>
  101. </li>
  102. <li class="toctree-l2">
  103. <a class="reference internal" href="ssm/inference.html">
  104. States estimation (inference)
  105. </a>
  106. </li>
  107. <li class="toctree-l2">
  108. <a class="reference internal" href="ssm/learning.html">
  109. Parameter estimation (learning)
  110. </a>
  111. </li>
  112. </ul>
  113. </li>
  114. <li class="toctree-l1 has-children">
  115. <a class="reference internal" href="hmm/hmm_index.html">
  116. Hidden Markov Models
  117. </a>
  118. <input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/>
  119. <label for="toctree-checkbox-2">
  120. <i class="fas fa-chevron-down">
  121. </i>
  122. </label>
  123. <ul>
  124. <li class="toctree-l2">
  125. <a class="reference internal" href="hmm/hmm_filter.html">
  126. HMM filtering (forwards algorithm)
  127. </a>
  128. </li>
  129. <li class="toctree-l2">
  130. <a class="reference internal" href="hmm/hmm_smoother.html">
  131. HMM smoothing (forwards-backwards algorithm)
  132. </a>
  133. </li>
  134. <li class="toctree-l2">
  135. <a class="reference internal" href="hmm/hmm_viterbi.html">
  136. Viterbi algorithm
  137. </a>
  138. </li>
  139. <li class="toctree-l2">
  140. <a class="reference internal" href="hmm/hmm_parallel.html">
  141. Parallel HMM smoothing
  142. </a>
  143. </li>
  144. <li class="toctree-l2">
  145. <a class="reference internal" href="hmm/hmm_sampling.html">
  146. Forwards-filtering backwards-sampling algorithm
  147. </a>
  148. </li>
  149. </ul>
  150. </li>
  151. <li class="toctree-l1 has-children">
  152. <a class="reference internal" href="lgssm/lgssm_index.html">
  153. Linear-Gaussian SSMs
  154. </a>
  155. <input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/>
  156. <label for="toctree-checkbox-3">
  157. <i class="fas fa-chevron-down">
  158. </i>
  159. </label>
  160. <ul>
  161. <li class="toctree-l2">
  162. <a class="reference internal" href="lgssm/kalman_filter.html">
  163. Kalman filtering
  164. </a>
  165. </li>
  166. <li class="toctree-l2">
  167. <a class="reference internal" href="lgssm/kalman_smoother.html">
  168. Kalman (RTS) smoother
  169. </a>
  170. </li>
  171. <li class="toctree-l2">
  172. <a class="reference internal" href="lgssm/kalman_parallel.html">
  173. Parallel Kalman Smoother
  174. </a>
  175. </li>
  176. <li class="toctree-l2">
  177. <a class="reference internal" href="lgssm/kalman_sampling.html">
  178. Forwards-filtering backwards sampling
  179. </a>
  180. </li>
  181. </ul>
  182. </li>
  183. <li class="toctree-l1 has-children">
  184. <a class="reference internal" href="extended/extended_index.html">
  185. Extended (linearized) methods
  186. </a>
  187. <input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/>
  188. <label for="toctree-checkbox-4">
  189. <i class="fas fa-chevron-down">
  190. </i>
  191. </label>
  192. <ul>
  193. <li class="toctree-l2">
  194. <a class="reference internal" href="extended/extended_filter.html">
  195. Extended Kalman filtering
  196. </a>
  197. </li>
  198. <li class="toctree-l2">
  199. <a class="reference internal" href="extended/extended_smoother.html">
  200. Extended Kalman smoother
  201. </a>
  202. </li>
  203. <li class="toctree-l2">
  204. <a class="reference internal" href="extended/extended_parallel.html">
  205. Parallel extended Kalman smoothing
  206. </a>
  207. </li>
  208. </ul>
  209. </li>
  210. <li class="toctree-l1 has-children">
  211. <a class="reference internal" href="unscented/unscented_index.html">
  212. Unscented methods
  213. </a>
  214. <input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" type="checkbox"/>
  215. <label for="toctree-checkbox-5">
  216. <i class="fas fa-chevron-down">
  217. </i>
  218. </label>
  219. <ul>
  220. <li class="toctree-l2">
  221. <a class="reference internal" href="unscented/unscented_filter.html">
  222. Unscented filtering
  223. </a>
  224. </li>
  225. <li class="toctree-l2">
  226. <a class="reference internal" href="unscented/unscented_smoother.html">
  227. Unscented smoothing
  228. </a>
  229. </li>
  230. </ul>
  231. </li>
  232. <li class="toctree-l1">
  233. <a class="reference internal" href="quadrature/quadrature_index.html">
  234. Quadrature and cubature methods
  235. </a>
  236. </li>
  237. <li class="toctree-l1">
  238. <a class="reference internal" href="postlin/postlin_index.html">
  239. Posterior linearization
  240. </a>
  241. </li>
  242. <li class="toctree-l1">
  243. <a class="reference internal" href="adf/adf_index.html">
  244. Assumed Density Filtering
  245. </a>
  246. </li>
  247. <li class="toctree-l1">
  248. <a class="reference internal" href="vi/vi_index.html">
  249. Variational inference
  250. </a>
  251. </li>
  252. <li class="toctree-l1">
  253. <a class="reference internal" href="pf/pf_index.html">
  254. Particle filtering
  255. </a>
  256. </li>
  257. <li class="toctree-l1">
  258. <a class="reference internal" href="smc/smc_index.html">
  259. Sequential Monte Carlo
  260. </a>
  261. </li>
  262. <li class="toctree-l1">
  263. <a class="reference internal" href="learning/learning_index.html">
  264. Offline parameter estimation (learning)
  265. </a>
  266. </li>
  267. <li class="toctree-l1">
  268. <a class="reference internal" href="tracking/tracking_index.html">
  269. Multi-target tracking
  270. </a>
  271. </li>
  272. <li class="toctree-l1">
  273. <a class="reference internal" href="ensemble/ensemble_index.html">
  274. Data assimilation using Ensemble Kalman filter
  275. </a>
  276. </li>
  277. <li class="toctree-l1">
  278. <a class="reference internal" href="bnp/bnp_index.html">
  279. Bayesian non-parametric SSMs
  280. </a>
  281. </li>
  282. <li class="toctree-l1">
  283. <a class="reference internal" href="changepoint/changepoint_index.html">
  284. Changepoint detection
  285. </a>
  286. </li>
  287. <li class="toctree-l1">
  288. <a class="reference internal" href="timeseries/timeseries_index.html">
  289. Timeseries forecasting
  290. </a>
  291. </li>
  292. <li class="toctree-l1">
  293. <a class="reference internal" href="gp/gp_index.html">
  294. Markovian Gaussian processes
  295. </a>
  296. </li>
  297. <li class="toctree-l1">
  298. <a class="reference internal" href="ode/ode_index.html">
  299. Differential equations and SSMs
  300. </a>
  301. </li>
  302. <li class="toctree-l1">
  303. <a class="reference internal" href="control/control_index.html">
  304. Optimal control
  305. </a>
  306. </li>
  307. <li class="toctree-l1">
  308. <a class="reference internal" href="../bib.html">
  309. Bibliography
  310. </a>
  311. </li>
  312. </ul>
  313. </div>
  314. </nav> <!-- To handle the deprecated key -->
  315. <div class="navbar_extra_footer">
  316. Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
  317. </div>
  318. </div>
  319. <main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
  320. <div class="topbar container-xl fixed-top">
  321. <div class="topbar-contents row">
  322. <div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
  323. <div class="col pl-md-4 topbar-main">
  324. <button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
  325. data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
  326. aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
  327. title="Toggle navigation" data-toggle="tooltip" data-placement="left">
  328. <i class="fas fa-bars"></i>
  329. <i class="fas fa-arrow-left"></i>
  330. <i class="fas fa-arrow-up"></i>
  331. </button>
  332. <div class="dropdown-buttons-trigger">
  333. <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
  334. class="fas fa-download"></i></button>
  335. <div class="dropdown-buttons">
  336. <!-- ipynb file if we had a myst markdown file -->
  337. <a class="dropdown-buttons"
  338. href="../_sources/chapters/scratch.ipynb"><button type="button"
  339. class="btn btn-secondary topbarbtn" title="Download notebook file" data-toggle="tooltip"
  340. data-placement="left">.ipynb</button></a>
  341. <!-- Download raw file -->
  342. <a class="dropdown-buttons" href="../_sources/chapters/scratch.md"><button type="button"
  343. class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
  344. data-placement="left">.md</button></a>
  345. <!-- Download PDF via print -->
  346. <button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
  347. onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
  348. </div>
  349. </div>
  350. <!-- Source interaction buttons -->
  351. <div class="dropdown-buttons-trigger">
  352. <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
  353. aria-label="Connect with source repository"><i class="fab fa-github"></i></button>
  354. <div class="dropdown-buttons sourcebuttons">
  355. <a class="repository-button"
  356. href="https://github.com/probml/ssm-book"><button type="button" class="btn btn-secondary topbarbtn"
  357. data-toggle="tooltip" data-placement="left" title="Source repository"><i
  358. class="fab fa-github"></i>repository</button></a>
  359. <a class="issues-button"
  360. href="https://github.com/probml/ssm-book/issues/new?title=Issue%20on%20page%20%2Fchapters/scratch.html&body=Your%20issue%20content%20here."><button
  361. type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
  362. title="Open an issue"><i class="fas fa-lightbulb"></i>open issue</button></a>
  363. </div>
  364. </div>
  365. <!-- Full screen (wrap in <a> to have style consistency -->
  366. <a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
  367. data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
  368. title="Fullscreen mode"><i
  369. class="fas fa-expand"></i></button></a>
  370. <!-- Launch buttons -->
  371. <div class="dropdown-buttons-trigger">
  372. <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
  373. aria-label="Launch interactive content"><i class="fas fa-rocket"></i></button>
  374. <div class="dropdown-buttons">
  375. <a class="binder-button" href="https://mybinder.org/v2/gh/probml/ssm-book/main?urlpath=tree/chapters/scratch.md"><button type="button"
  376. class="btn btn-secondary topbarbtn" title="Launch Binder" data-toggle="tooltip"
  377. data-placement="left"><img class="binder-button-logo"
  378. src="../_static/images/logo_binder.svg"
  379. alt="Interact on binder">Binder</button></a>
  380. </div>
  381. </div>
  382. </div>
  383. <!-- Table of contents -->
  384. <div class="d-none d-md-block col-md-2 bd-toc show noprint">
  385. <div class="tocsection onthispage pt-5 pb-3">
  386. <i class="fas fa-list"></i> Contents
  387. </div>
  388. <nav id="bd-toc-nav" aria-label="Page">
  389. <ul class="visible nav section-nav flex-column">
  390. <li class="toc-h2 nav-item toc-entry">
  391. <a class="reference internal nav-link" href="#python">
  392. Python
  393. </a>
  394. </li>
  395. <li class="toc-h2 nav-item toc-entry">
  396. <a class="reference internal nav-link" href="#images">
  397. Images
  398. </a>
  399. </li>
  400. <li class="toc-h2 nav-item toc-entry">
  401. <a class="reference internal nav-link" href="#math">
  402. Math
  403. </a>
  404. </li>
  405. </ul>
  406. </nav>
  407. </div>
  408. </div>
  409. </div>
  410. <div id="main-content" class="row">
  411. <div class="col-12 col-md-9 pl-md-3 pr-md-0">
  412. <!-- Table of contents that is only displayed when printing the page -->
  413. <div id="jb-print-docs-body" class="onlyprint">
  414. <h1>Scratchpad</h1>
  415. <!-- Table of contents -->
  416. <div id="print-main-content">
  417. <div id="jb-print-toc">
  418. <div>
  419. <h2> Contents </h2>
  420. </div>
  421. <nav aria-label="Page">
  422. <ul class="visible nav section-nav flex-column">
  423. <li class="toc-h2 nav-item toc-entry">
  424. <a class="reference internal nav-link" href="#python">
  425. Python
  426. </a>
  427. </li>
  428. <li class="toc-h2 nav-item toc-entry">
  429. <a class="reference internal nav-link" href="#images">
  430. Images
  431. </a>
  432. </li>
  433. <li class="toc-h2 nav-item toc-entry">
  434. <a class="reference internal nav-link" href="#math">
  435. Math
  436. </a>
  437. </li>
  438. </ul>
  439. </nav>
  440. </div>
  441. </div>
  442. </div>
  443. <div>
  444. <div class="tex2jax_ignore mathjax_ignore section" id="scratchpad">
  445. <span id="ch-intro"></span><h1>Scratchpad<a class="headerlink" href="#scratchpad" title="Permalink to this headline">¶</a></h1>
  446. <p>In this chapter, we do blah.
  447. Specifically</p>
  448. <ul class="simple">
  449. <li><p>foo</p></li>
  450. <li><p>bar.</p></li>
  451. <li><p>baz</p></li>
  452. </ul>
  453. <p>For more details, see
  454. <a class="reference internal" href="hmm/hmm_index.html#ch-hmm"><span class="std std-ref">Hidden Markov Models</span></a> and <span id="id1">[<a class="reference internal" href="../bib.html#id18" title="Simo Sarkka. Bayesian Filtering and Smoothing. Cambridge University Press, 2013. URL: https://users.aalto.fi/~ssarkka/pub/cup_book_online_20131111.pdf.">Sar13</a>]</span>.</p>
  455. <div class="section" id="python">
  456. <h2>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h2>
  457. <p>We’re now ready to start coding.</p>
  458. <div class="cell docutils container">
  459. <div class="cell_input docutils container">
  460. <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">rcParams</span><span class="p">,</span> <span class="n">cycler</span>
  461. <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
  462. <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
  463. <span class="n">plt</span><span class="o">.</span><span class="n">ion</span><span class="p">()</span>
  464. </pre></div>
  465. </div>
  466. </div>
  467. </div>
  468. <div class="cell docutils container">
  469. <div class="cell_input docutils container">
  470. <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Fixing random state for reproducibility</span>
  471. <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</span>
  472. <span class="n">N</span> <span class="o">=</span> <span class="mi">10</span>
  473. <span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">logspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span> <span class="o">+</span> <span class="n">ii</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">N</span><span class="p">)]</span>
  474. <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
  475. <span class="n">cmap</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">cm</span><span class="o">.</span><span class="n">coolwarm</span>
  476. <span class="n">rcParams</span><span class="p">[</span><span class="s1">&#39;axes.prop_cycle&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">cycler</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="n">cmap</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">N</span><span class="p">)))</span>
  477. <span class="kn">from</span> <span class="nn">matplotlib.lines</span> <span class="kn">import</span> <span class="n">Line2D</span>
  478. <span class="n">custom_lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">Line2D</span><span class="p">([</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">cmap</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span> <span class="n">lw</span><span class="o">=</span><span class="mi">4</span><span class="p">),</span>
  479. <span class="n">Line2D</span><span class="p">([</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">cmap</span><span class="p">(</span><span class="mf">.5</span><span class="p">),</span> <span class="n">lw</span><span class="o">=</span><span class="mi">4</span><span class="p">),</span>
  480. <span class="n">Line2D</span><span class="p">([</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">color</span><span class="o">=</span><span class="n">cmap</span><span class="p">(</span><span class="mf">1.</span><span class="p">),</span> <span class="n">lw</span><span class="o">=</span><span class="mi">4</span><span class="p">)]</span>
  481. <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
  482. <span class="n">lines</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  483. <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">custom_lines</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;Cold&#39;</span><span class="p">,</span> <span class="s1">&#39;Medium&#39;</span><span class="p">,</span> <span class="s1">&#39;Hot&#39;</span><span class="p">]);</span>
  484. </pre></div>
  485. </div>
  486. </div>
  487. <div class="cell_output docutils container">
  488. <img alt="../_images/scratch_2_0.png" src="../_images/scratch_2_0.png" />
  489. </div>
  490. </div>
  491. <div class="cell docutils container">
  492. <div class="cell_input docutils container">
  493. <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
  494. <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
  495. <span class="kn">import</span> <span class="nn">jax</span>
  496. <span class="kn">import</span> <span class="nn">jax.numpy</span> <span class="k">as</span> <span class="nn">jnp</span>
  497. <span class="nb">print</span><span class="p">(</span><span class="n">jax</span><span class="o">.</span><span class="n">devices</span><span class="p">())</span>
  498. </pre></div>
  499. </div>
  500. </div>
  501. <div class="cell_output docutils container">
  502. <div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
  503. </pre></div>
  504. </div>
  505. <div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[CpuDevice(id=0)]
  506. </pre></div>
  507. </div>
  508. </div>
  509. </div>
  510. </div>
  511. <div class="section" id="images">
  512. <h2>Images<a class="headerlink" href="#images" title="Permalink to this headline">¶</a></h2>
  513. <!---
  514. ![](https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg)
  515. <img src="https://github.com/probml/probml-notebooks/blob/main/images/cat_dog.jpg"
  516. style="height:200">
  517. -->
  518. <div class="figure align-default" id="cat-dog">
  519. <a class="reference internal image-reference" href="../_images/cat_dog.jpg"><img alt="../_images/cat_dog.jpg" src="../_images/cat_dog.jpg" style="width: 320.0px; height: 240.0px;" /></a>
  520. <p class="caption"><span class="caption-text">A photo of a cat and a dog.</span><a class="headerlink" href="#cat-dog" title="Permalink to this image">¶</a></p>
  521. </div>
  522. <div class="figure align-default" id="cat-dog2">
  523. <a class="reference internal image-reference" href="../_images/cat_dog.jpg"><img alt="../_images/cat_dog.jpg" src="../_images/cat_dog.jpg" style="height: 300px;" /></a>
  524. <p class="caption"><span class="caption-text">Another photo of a cat and a dog.</span><a class="headerlink" href="#cat-dog2" title="Permalink to this image">¶</a></p>
  525. </div>
  526. <p>In <code class="xref std std-numref docutils literal notranslate"><span class="pre">cat_dog</span></code>
  527. we show catdog.
  528. In <code class="xref std std-numref docutils literal notranslate"><span class="pre">Figure</span> <span class="pre">%s</span></code> we show catdog2, its twin.</p>
  529. <div class="admonition note">
  530. <p class="admonition-title">Note</p>
  531. <p>I am a useful note!</p>
  532. </div>
  533. </div>
  534. <div class="section" id="math">
  535. <h2>Math<a class="headerlink" href="#math" title="Permalink to this headline">¶</a></h2>
  536. <p>Here is <span class="math notranslate nohighlight">\(\N=10\)</span> and blah. <span class="math notranslate nohighlight">\(\floor{42.3}= 42\)</span>. Let’s try again.</p>
  537. <p>We have <span class="math notranslate nohighlight">\(E= mc^2\)</span>, and also</p>
  538. <div class="math notranslate nohighlight" id="equation-foo">
  539. <span class="eqno">()<a class="headerlink" href="#equation-foo" title="Permalink to this equation">¶</a></span>\[a x^2 + bx+ c = 0\]</div>
  540. <p>From <a class="reference internal" href="#equation-foo">()</a>, it follows that</p>
  541. <div class="math notranslate nohighlight">
  542. \[\begin{split}
  543. \begin{align}
  544. 0 &amp;= a x^2 + bx+ c \\
  545. 0 &amp;= a x^2 + bx+ c
  546. \end{align}
  547. \end{split}\]</div>
  548. </div>
  549. </div>
  550. <script type="text/x-thebe-config">
  551. {
  552. requestKernel: true,
  553. binderOptions: {
  554. repo: "binder-examples/jupyter-stacks-datascience",
  555. ref: "master",
  556. },
  557. codeMirrorConfig: {
  558. theme: "abcdef",
  559. mode: "python"
  560. },
  561. kernelOptions: {
  562. kernelName: "python3",
  563. path: "./chapters"
  564. },
  565. predefinedOutput: true
  566. }
  567. </script>
  568. <script>kernelName = 'python3'</script>
  569. </div>
  570. <!-- Previous / next buttons -->
  571. <div class='prev-next-area'>
  572. </div>
  573. </div>
  574. </div>
  575. <footer class="footer">
  576. <p>
  577. By Kevin Murphy, Scott Linderman, et al.<br/>
  578. &copy; Copyright 2021.<br/>
  579. </p>
  580. </footer>
  581. </main>
  582. </div>
  583. </div>
  584. <script src="../_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
  585. </body>
  586. </html>