nlds.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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>Nonlinear Gaussian SSMs &#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. <link rel="next" title="States estimation (inference)" href="inference.html" />
  47. <link rel="prev" title="Linear Gaussian SSMs" href="lds.html" />
  48. <meta name="viewport" content="width=device-width, initial-scale=1" />
  49. <meta name="docsearch:language" content="None">
  50. <!-- Google Analytics -->
  51. </head>
  52. <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
  53. <div class="container-fluid" id="banner"></div>
  54. <div class="container-xl">
  55. <div class="row">
  56. <div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
  57. <div class="navbar-brand-box">
  58. <a class="navbar-brand text-wrap" href="../../index.html">
  59. <h1 class="site-logo" id="site-title">State Space Models: A Modern Approach</h1>
  60. </a>
  61. </div><form class="bd-search d-flex align-items-center" action="../../search.html" method="get">
  62. <i class="icon fas fa-search"></i>
  63. <input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
  64. </form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
  65. <div class="bd-toc-item active">
  66. <ul class="nav bd-sidenav">
  67. <li class="toctree-l1">
  68. <a class="reference internal" href="../../root.html">
  69. State Space Models: A Modern Approach
  70. </a>
  71. </li>
  72. </ul>
  73. <ul class="current nav bd-sidenav">
  74. <li class="toctree-l1 current active has-children">
  75. <a class="reference internal" href="ssm_index.html">
  76. State Space Models
  77. </a>
  78. <input checked="" class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/>
  79. <label for="toctree-checkbox-1">
  80. <i class="fas fa-chevron-down">
  81. </i>
  82. </label>
  83. <ul class="current">
  84. <li class="toctree-l2">
  85. <a class="reference internal" href="ssm_intro.html">
  86. What are State Space Models?
  87. </a>
  88. </li>
  89. <li class="toctree-l2">
  90. <a class="reference internal" href="hmm.html">
  91. Hidden Markov Models
  92. </a>
  93. </li>
  94. <li class="toctree-l2">
  95. <a class="reference internal" href="lds.html">
  96. Linear Gaussian SSMs
  97. </a>
  98. </li>
  99. <li class="toctree-l2 current active">
  100. <a class="current reference internal" href="#">
  101. Nonlinear Gaussian SSMs
  102. </a>
  103. </li>
  104. <li class="toctree-l2">
  105. <a class="reference internal" href="inference.html">
  106. States estimation (inference)
  107. </a>
  108. </li>
  109. <li class="toctree-l2">
  110. <a class="reference internal" href="learning.html">
  111. Parameter estimation (learning)
  112. </a>
  113. </li>
  114. </ul>
  115. </li>
  116. <li class="toctree-l1 has-children">
  117. <a class="reference internal" href="../hmm/hmm_index.html">
  118. Hidden Markov Models
  119. </a>
  120. <input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/>
  121. <label for="toctree-checkbox-2">
  122. <i class="fas fa-chevron-down">
  123. </i>
  124. </label>
  125. <ul>
  126. <li class="toctree-l2">
  127. <a class="reference internal" href="../hmm/hmm_filter.html">
  128. HMM filtering (forwards algorithm)
  129. </a>
  130. </li>
  131. <li class="toctree-l2">
  132. <a class="reference internal" href="../hmm/hmm_smoother.html">
  133. HMM smoothing (forwards-backwards algorithm)
  134. </a>
  135. </li>
  136. <li class="toctree-l2">
  137. <a class="reference internal" href="../hmm/hmm_viterbi.html">
  138. Viterbi algorithm
  139. </a>
  140. </li>
  141. <li class="toctree-l2">
  142. <a class="reference internal" href="../hmm/hmm_parallel.html">
  143. Parallel HMM smoothing
  144. </a>
  145. </li>
  146. <li class="toctree-l2">
  147. <a class="reference internal" href="../hmm/hmm_sampling.html">
  148. Forwards-filtering backwards-sampling algorithm
  149. </a>
  150. </li>
  151. </ul>
  152. </li>
  153. <li class="toctree-l1 has-children">
  154. <a class="reference internal" href="../lgssm/lgssm_index.html">
  155. Linear-Gaussian SSMs
  156. </a>
  157. <input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/>
  158. <label for="toctree-checkbox-3">
  159. <i class="fas fa-chevron-down">
  160. </i>
  161. </label>
  162. <ul>
  163. <li class="toctree-l2">
  164. <a class="reference internal" href="../lgssm/kalman_filter.html">
  165. Kalman filtering
  166. </a>
  167. </li>
  168. <li class="toctree-l2">
  169. <a class="reference internal" href="../lgssm/kalman_smoother.html">
  170. Kalman (RTS) smoother
  171. </a>
  172. </li>
  173. <li class="toctree-l2">
  174. <a class="reference internal" href="../lgssm/kalman_parallel.html">
  175. Parallel Kalman Smoother
  176. </a>
  177. </li>
  178. <li class="toctree-l2">
  179. <a class="reference internal" href="../lgssm/kalman_sampling.html">
  180. Forwards-filtering backwards sampling
  181. </a>
  182. </li>
  183. </ul>
  184. </li>
  185. <li class="toctree-l1 has-children">
  186. <a class="reference internal" href="../extended/extended_index.html">
  187. Extended (linearized) methods
  188. </a>
  189. <input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/>
  190. <label for="toctree-checkbox-4">
  191. <i class="fas fa-chevron-down">
  192. </i>
  193. </label>
  194. <ul>
  195. <li class="toctree-l2">
  196. <a class="reference internal" href="../extended/extended_filter.html">
  197. Extended Kalman filtering
  198. </a>
  199. </li>
  200. <li class="toctree-l2">
  201. <a class="reference internal" href="../extended/extended_smoother.html">
  202. Extended Kalman smoother
  203. </a>
  204. </li>
  205. <li class="toctree-l2">
  206. <a class="reference internal" href="../extended/extended_parallel.html">
  207. Parallel extended Kalman smoothing
  208. </a>
  209. </li>
  210. </ul>
  211. </li>
  212. <li class="toctree-l1 has-children">
  213. <a class="reference internal" href="../unscented/unscented_index.html">
  214. Unscented methods
  215. </a>
  216. <input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" type="checkbox"/>
  217. <label for="toctree-checkbox-5">
  218. <i class="fas fa-chevron-down">
  219. </i>
  220. </label>
  221. <ul>
  222. <li class="toctree-l2">
  223. <a class="reference internal" href="../unscented/unscented_filter.html">
  224. Unscented filtering
  225. </a>
  226. </li>
  227. <li class="toctree-l2">
  228. <a class="reference internal" href="../unscented/unscented_smoother.html">
  229. Unscented smoothing
  230. </a>
  231. </li>
  232. </ul>
  233. </li>
  234. <li class="toctree-l1">
  235. <a class="reference internal" href="../quadrature/quadrature_index.html">
  236. Quadrature and cubature methods
  237. </a>
  238. </li>
  239. <li class="toctree-l1">
  240. <a class="reference internal" href="../postlin/postlin_index.html">
  241. Posterior linearization
  242. </a>
  243. </li>
  244. <li class="toctree-l1">
  245. <a class="reference internal" href="../adf/adf_index.html">
  246. Assumed Density Filtering
  247. </a>
  248. </li>
  249. <li class="toctree-l1">
  250. <a class="reference internal" href="../vi/vi_index.html">
  251. Variational inference
  252. </a>
  253. </li>
  254. <li class="toctree-l1">
  255. <a class="reference internal" href="../pf/pf_index.html">
  256. Particle filtering
  257. </a>
  258. </li>
  259. <li class="toctree-l1">
  260. <a class="reference internal" href="../smc/smc_index.html">
  261. Sequential Monte Carlo
  262. </a>
  263. </li>
  264. <li class="toctree-l1">
  265. <a class="reference internal" href="../learning/learning_index.html">
  266. Offline parameter estimation (learning)
  267. </a>
  268. </li>
  269. <li class="toctree-l1">
  270. <a class="reference internal" href="../tracking/tracking_index.html">
  271. Multi-target tracking
  272. </a>
  273. </li>
  274. <li class="toctree-l1">
  275. <a class="reference internal" href="../ensemble/ensemble_index.html">
  276. Data assimilation using Ensemble Kalman filter
  277. </a>
  278. </li>
  279. <li class="toctree-l1">
  280. <a class="reference internal" href="../bnp/bnp_index.html">
  281. Bayesian non-parametric SSMs
  282. </a>
  283. </li>
  284. <li class="toctree-l1">
  285. <a class="reference internal" href="../changepoint/changepoint_index.html">
  286. Changepoint detection
  287. </a>
  288. </li>
  289. <li class="toctree-l1">
  290. <a class="reference internal" href="../timeseries/timeseries_index.html">
  291. Timeseries forecasting
  292. </a>
  293. </li>
  294. <li class="toctree-l1">
  295. <a class="reference internal" href="../gp/gp_index.html">
  296. Markovian Gaussian processes
  297. </a>
  298. </li>
  299. <li class="toctree-l1">
  300. <a class="reference internal" href="../ode/ode_index.html">
  301. Differential equations and SSMs
  302. </a>
  303. </li>
  304. <li class="toctree-l1">
  305. <a class="reference internal" href="../control/control_index.html">
  306. Optimal control
  307. </a>
  308. </li>
  309. <li class="toctree-l1">
  310. <a class="reference internal" href="../../bib.html">
  311. Bibliography
  312. </a>
  313. </li>
  314. </ul>
  315. </div>
  316. </nav> <!-- To handle the deprecated key -->
  317. <div class="navbar_extra_footer">
  318. Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
  319. </div>
  320. </div>
  321. <main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
  322. <div class="topbar container-xl fixed-top">
  323. <div class="topbar-contents row">
  324. <div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
  325. <div class="col pl-md-4 topbar-main">
  326. <button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
  327. data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
  328. aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
  329. title="Toggle navigation" data-toggle="tooltip" data-placement="left">
  330. <i class="fas fa-bars"></i>
  331. <i class="fas fa-arrow-left"></i>
  332. <i class="fas fa-arrow-up"></i>
  333. </button>
  334. <div class="dropdown-buttons-trigger">
  335. <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
  336. class="fas fa-download"></i></button>
  337. <div class="dropdown-buttons">
  338. <!-- ipynb file if we had a myst markdown file -->
  339. <!-- Download raw file -->
  340. <a class="dropdown-buttons" href="../../_sources/chapters/ssm/nlds.ipynb"><button type="button"
  341. class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
  342. data-placement="left">.ipynb</button></a>
  343. <!-- Download PDF via print -->
  344. <button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
  345. onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
  346. </div>
  347. </div>
  348. <!-- Source interaction buttons -->
  349. <div class="dropdown-buttons-trigger">
  350. <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
  351. aria-label="Connect with source repository"><i class="fab fa-github"></i></button>
  352. <div class="dropdown-buttons sourcebuttons">
  353. <a class="repository-button"
  354. href="https://github.com/probml/ssm-book"><button type="button" class="btn btn-secondary topbarbtn"
  355. data-toggle="tooltip" data-placement="left" title="Source repository"><i
  356. class="fab fa-github"></i>repository</button></a>
  357. <a class="issues-button"
  358. href="https://github.com/probml/ssm-book/issues/new?title=Issue%20on%20page%20%2Fchapters/ssm/nlds.html&body=Your%20issue%20content%20here."><button
  359. type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
  360. title="Open an issue"><i class="fas fa-lightbulb"></i>open issue</button></a>
  361. </div>
  362. </div>
  363. <!-- Full screen (wrap in <a> to have style consistency -->
  364. <a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
  365. data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
  366. title="Fullscreen mode"><i
  367. class="fas fa-expand"></i></button></a>
  368. <!-- Launch buttons -->
  369. <div class="dropdown-buttons-trigger">
  370. <button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
  371. aria-label="Launch interactive content"><i class="fas fa-rocket"></i></button>
  372. <div class="dropdown-buttons">
  373. <a class="binder-button" href="https://mybinder.org/v2/gh/probml/ssm-book/main?urlpath=tree/chapters/ssm/nlds.ipynb"><button type="button"
  374. class="btn btn-secondary topbarbtn" title="Launch Binder" data-toggle="tooltip"
  375. data-placement="left"><img class="binder-button-logo"
  376. src="../../_static/images/logo_binder.svg"
  377. alt="Interact on binder">Binder</button></a>
  378. <a class="colab-button" href="https://colab.research.google.com/github/probml/ssm-book/blob/main/chapters/ssm/nlds.ipynb"><button type="button" class="btn btn-secondary topbarbtn"
  379. title="Launch Colab" data-toggle="tooltip" data-placement="left"><img class="colab-button-logo"
  380. src="../../_static/images/logo_colab.png"
  381. alt="Interact on Colab">Colab</button></a>
  382. </div>
  383. </div>
  384. </div>
  385. <!-- Table of contents -->
  386. <div class="d-none d-md-block col-md-2 bd-toc show noprint">
  387. <div class="tocsection onthispage pt-5 pb-3">
  388. <i class="fas fa-list"></i> Contents
  389. </div>
  390. <nav id="bd-toc-nav" aria-label="Page">
  391. <ul class="visible nav section-nav flex-column">
  392. <li class="toc-h2 nav-item toc-entry">
  393. <a class="reference internal nav-link" href="#example-tracking-a-1d-pendulum">
  394. Example: tracking a 1d pendulum
  395. </a>
  396. </li>
  397. </ul>
  398. </nav>
  399. </div>
  400. </div>
  401. </div>
  402. <div id="main-content" class="row">
  403. <div class="col-12 col-md-9 pl-md-3 pr-md-0">
  404. <!-- Table of contents that is only displayed when printing the page -->
  405. <div id="jb-print-docs-body" class="onlyprint">
  406. <h1>Nonlinear Gaussian SSMs</h1>
  407. <!-- Table of contents -->
  408. <div id="print-main-content">
  409. <div id="jb-print-toc">
  410. <div>
  411. <h2> Contents </h2>
  412. </div>
  413. <nav aria-label="Page">
  414. <ul class="visible nav section-nav flex-column">
  415. <li class="toc-h2 nav-item toc-entry">
  416. <a class="reference internal nav-link" href="#example-tracking-a-1d-pendulum">
  417. Example: tracking a 1d pendulum
  418. </a>
  419. </li>
  420. </ul>
  421. </nav>
  422. </div>
  423. </div>
  424. </div>
  425. <div>
  426. <div class="cell docutils container">
  427. <div class="cell_input docutils container">
  428. <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># meta-data does not work yet in VScode</span>
  429. <span class="c1"># https://github.com/microsoft/vscode-jupyter/issues/1121</span>
  430. <span class="p">{</span>
  431. <span class="s2">&quot;tags&quot;</span><span class="p">:</span> <span class="p">[</span>
  432. <span class="s2">&quot;hide-cell&quot;</span>
  433. <span class="p">]</span>
  434. <span class="p">}</span>
  435. <span class="c1">### Install necessary libraries</span>
  436. <span class="k">try</span><span class="p">:</span>
  437. <span class="kn">import</span> <span class="nn">jax</span>
  438. <span class="k">except</span><span class="p">:</span>
  439. <span class="c1"># For cuda version, see https://github.com/google/jax#installation</span>
  440. <span class="o">%</span><span class="k">pip</span> install --upgrade &quot;jax[cpu]&quot;
  441. <span class="kn">import</span> <span class="nn">jax</span>
  442. <span class="k">try</span><span class="p">:</span>
  443. <span class="kn">import</span> <span class="nn">distrax</span>
  444. <span class="k">except</span><span class="p">:</span>
  445. <span class="o">%</span><span class="k">pip</span> install --upgrade distrax
  446. <span class="kn">import</span> <span class="nn">distrax</span>
  447. <span class="k">try</span><span class="p">:</span>
  448. <span class="kn">import</span> <span class="nn">jsl</span>
  449. <span class="k">except</span><span class="p">:</span>
  450. <span class="o">%</span><span class="k">pip</span> install git+https://github.com/probml/jsl
  451. <span class="kn">import</span> <span class="nn">jsl</span>
  452. <span class="k">try</span><span class="p">:</span>
  453. <span class="kn">import</span> <span class="nn">rich</span>
  454. <span class="k">except</span><span class="p">:</span>
  455. <span class="o">%</span><span class="k">pip</span> install rich
  456. <span class="kn">import</span> <span class="nn">rich</span>
  457. </pre></div>
  458. </div>
  459. </div>
  460. </div>
  461. <div class="cell docutils container">
  462. <div class="cell_input docutils container">
  463. <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  464. <span class="s2">&quot;tags&quot;</span><span class="p">:</span> <span class="p">[</span>
  465. <span class="s2">&quot;hide-cell&quot;</span>
  466. <span class="p">]</span>
  467. <span class="p">}</span>
  468. <span class="c1">### Import standard libraries</span>
  469. <span class="kn">import</span> <span class="nn">abc</span>
  470. <span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span>
  471. <span class="kn">import</span> <span class="nn">functools</span>
  472. <span class="kn">import</span> <span class="nn">itertools</span>
  473. <span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">NamedTuple</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Tuple</span>
  474. <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
  475. <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
  476. <span class="kn">import</span> <span class="nn">jax</span>
  477. <span class="kn">import</span> <span class="nn">jax.numpy</span> <span class="k">as</span> <span class="nn">jnp</span>
  478. <span class="kn">from</span> <span class="nn">jax</span> <span class="kn">import</span> <span class="n">lax</span><span class="p">,</span> <span class="n">vmap</span><span class="p">,</span> <span class="n">jit</span><span class="p">,</span> <span class="n">grad</span>
  479. <span class="kn">from</span> <span class="nn">jax.scipy.special</span> <span class="kn">import</span> <span class="n">logit</span>
  480. <span class="kn">from</span> <span class="nn">jax.nn</span> <span class="kn">import</span> <span class="n">softmax</span>
  481. <span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">partial</span>
  482. <span class="kn">from</span> <span class="nn">jax.random</span> <span class="kn">import</span> <span class="n">PRNGKey</span><span class="p">,</span> <span class="n">split</span>
  483. <span class="kn">import</span> <span class="nn">inspect</span>
  484. <span class="kn">import</span> <span class="nn">inspect</span> <span class="k">as</span> <span class="nn">py_inspect</span>
  485. <span class="kn">import</span> <span class="nn">rich</span>
  486. <span class="kn">from</span> <span class="nn">rich</span> <span class="kn">import</span> <span class="n">inspect</span> <span class="k">as</span> <span class="n">r_inspect</span>
  487. <span class="kn">from</span> <span class="nn">rich</span> <span class="kn">import</span> <span class="nb">print</span> <span class="k">as</span> <span class="n">r_print</span>
  488. <span class="k">def</span> <span class="nf">print_source</span><span class="p">(</span><span class="n">fname</span><span class="p">):</span>
  489. <span class="n">r_print</span><span class="p">(</span><span class="n">py_inspect</span><span class="o">.</span><span class="n">getsource</span><span class="p">(</span><span class="n">fname</span><span class="p">))</span>
  490. </pre></div>
  491. </div>
  492. </div>
  493. </div>
  494. <div class="tex2jax_ignore mathjax_ignore section" id="nonlinear-gaussian-ssms">
  495. <span id="sec-nlds-intro"></span><h1>Nonlinear Gaussian SSMs<a class="headerlink" href="#nonlinear-gaussian-ssms" title="Permalink to this headline">¶</a></h1>
  496. <p>In this section, we consider SSMs in which the dynamics and/or observation models are nonlinear,
  497. but the process noise and observation noise are Gaussian.
  498. That is,</p>
  499. <div class="amsmath math notranslate nohighlight" id="equation-c863ff79-4ff3-4d89-8f2f-8e3236e21d41">
  500. <span class="eqno">(10)<a class="headerlink" href="#equation-c863ff79-4ff3-4d89-8f2f-8e3236e21d41" title="Permalink to this equation">¶</a></span>\[\begin{align}
  501. \hidden_t &amp;= \dynamicsFn(\hidden_{t-1}, \inputs_t) + \transNoise_t \\
  502. \obs_t &amp;= \obsFn(\hidden_{t}, \inputs_t) + \obsNoise_t
  503. \end{align}\]</div>
  504. <p>where <span class="math notranslate nohighlight">\(\transNoise_t \sim \gauss(\vzero,\transCov)\)</span>
  505. and <span class="math notranslate nohighlight">\(\obsNoise_t \sim \gauss(\vzero,\obsCov)\)</span>.
  506. This is a very widely used model class. We give some examples below.</p>
  507. <div class="section" id="example-tracking-a-1d-pendulum">
  508. <span id="sec-pendulum"></span><h2>Example: tracking a 1d pendulum<a class="headerlink" href="#example-tracking-a-1d-pendulum" title="Permalink to this headline">¶</a></h2>
  509. <div class="figure align-default" id="fig-pendulum">
  510. <a class="reference internal image-reference" href="../../_images/pendulum.png"><img alt="../../_images/pendulum.png" src="../../_images/pendulum.png" style="width: 132.5px; height: 147.5px;" /></a>
  511. <p class="caption"><span class="caption-number">Fig. 4 </span><span class="caption-text">Illustration of a pendulum swinging.
  512. <span class="math notranslate nohighlight">\(g\)</span> is the force of gravity,
  513. <span class="math notranslate nohighlight">\(w(t)\)</span> is a random external force,
  514. and <span class="math notranslate nohighlight">\(\alpha\)</span> is the angle wrt the vertical.
  515. Based on <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> fig 3.10.</span><a class="headerlink" href="#fig-pendulum" title="Permalink to this image">¶</a></p>
  516. </div>
  517. <p>Consider a simple pendulum of unit mass and length swinging from
  518. a fixed attachment, as in
  519. <a class="reference internal" href="#fig-pendulum"><span class="std std-numref">Fig. 4</span></a>.
  520. Such an object is in principle entirely deterministic in its behavior.
  521. However, in the real world, there are often unknown forces at work
  522. (e.g., air turbulence, friction).
  523. We will model these by a continuous time random Gaussian noise process <span class="math notranslate nohighlight">\(w(t)\)</span>.
  524. This gives rise to the following differential equation:</p>
  525. <div class="amsmath math notranslate nohighlight" id="equation-78ce6a00-cbb6-4416-abd3-66bf4f7ba2f2">
  526. <span class="eqno">(11)<a class="headerlink" href="#equation-78ce6a00-cbb6-4416-abd3-66bf4f7ba2f2" title="Permalink to this equation">¶</a></span>\[\begin{align}
  527. \frac{d^2 \alpha}{d t^2}
  528. = -g \sin(\alpha) + w(t)
  529. \end{align}\]</div>
  530. <p>We can write this as a nonlinear SSM by defining the state to be
  531. <span class="math notranslate nohighlight">\(\hidden_1(t) = \alpha(t)\)</span> and <span class="math notranslate nohighlight">\(\hidden_2(t) = d\alpha(t)/dt\)</span>.
  532. Thus</p>
  533. <div class="amsmath math notranslate nohighlight" id="equation-433778d9-4d3b-454f-a329-13f4b08bf8ad">
  534. <span class="eqno">(12)<a class="headerlink" href="#equation-433778d9-4d3b-454f-a329-13f4b08bf8ad" title="Permalink to this equation">¶</a></span>\[\begin{align}
  535. \frac{d \hidden}{dt}
  536. = \begin{pmatrix} \hiddenScalar_2 \\ -g \sin(\hiddenScalar_1) \end{pmatrix}
  537. + \begin{pmatrix} 0 \\ 1 \end{pmatrix} w(t)
  538. \end{align}\]</div>
  539. <p>If we discretize this step size <span class="math notranslate nohighlight">\(\Delta\)</span>,
  540. we get the following
  541. formulation <span id="id2">[<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> p74:</p>
  542. <div class="amsmath math notranslate nohighlight" id="equation-71eae374-1157-4249-bba9-8fc8be4cf8e4">
  543. <span class="eqno">(13)<a class="headerlink" href="#equation-71eae374-1157-4249-bba9-8fc8be4cf8e4" title="Permalink to this equation">¶</a></span>\[\begin{align}
  544. \underbrace{
  545. \begin{pmatrix} \hiddenScalar_{1,t} \\ \hiddenScalar_{2,t} \end{pmatrix}
  546. }_{\hidden_t}
  547. =
  548. \underbrace{
  549. \begin{pmatrix} \hiddenScalar_{1,t-1} + \hiddenScalar_{2,t-1} \Delta \\
  550. \hiddenScalar_{2,t-1} -g \sin(\hiddenScalar_{1,t-1}) \Delta \end{pmatrix}
  551. }_{\dynamicsFn(\hidden_{t-1})}
  552. +\transNoise_{t-1}
  553. \end{align}\]</div>
  554. <p>where <span class="math notranslate nohighlight">\(\transNoise_{t-1} \sim \gauss(\vzero,\transCov)\)</span> with</p>
  555. <div class="amsmath math notranslate nohighlight" id="equation-88f7e233-8b42-444d-b419-cd5928adbc29">
  556. <span class="eqno">(14)<a class="headerlink" href="#equation-88f7e233-8b42-444d-b419-cd5928adbc29" title="Permalink to this equation">¶</a></span>\[\begin{align}
  557. \transCov = q^c \begin{pmatrix}
  558. \frac{\Delta^3}{3} &amp; \frac{\Delta^2}{2} \\
  559. \frac{\Delta^2}{2} &amp; \Delta
  560. \end{pmatrix}
  561. \end{align}\]</div>
  562. <p>where <span class="math notranslate nohighlight">\(q^c\)</span> is the spectral density (continuous time variance)
  563. of the continuous-time noise process.</p>
  564. <p>If we observe the angular position, we
  565. get the linear observation model
  566. <span class="math notranslate nohighlight">\(\obsFn(\hidden_t) = \alpha_t = \hiddenScalar_{1,t}\)</span>.
  567. If we only observe the horizontal position,
  568. we get the nonlinear observation model
  569. <span class="math notranslate nohighlight">\(\obsFn(\hidden_t) = \sin(\alpha_t) = \sin(\hiddenScalar_{1,t})\)</span>.</p>
  570. </div>
  571. </div>
  572. <script type="text/x-thebe-config">
  573. {
  574. requestKernel: true,
  575. binderOptions: {
  576. repo: "binder-examples/jupyter-stacks-datascience",
  577. ref: "master",
  578. },
  579. codeMirrorConfig: {
  580. theme: "abcdef",
  581. mode: "python"
  582. },
  583. kernelOptions: {
  584. kernelName: "python3",
  585. path: "./chapters/ssm"
  586. },
  587. predefinedOutput: true
  588. }
  589. </script>
  590. <script>kernelName = 'python3'</script>
  591. </div>
  592. <!-- Previous / next buttons -->
  593. <div class='prev-next-area'>
  594. <a class='left-prev' id="prev-link" href="lds.html" title="previous page">
  595. <i class="fas fa-angle-left"></i>
  596. <div class="prev-next-info">
  597. <p class="prev-next-subtitle">previous</p>
  598. <p class="prev-next-title">Linear Gaussian SSMs</p>
  599. </div>
  600. </a>
  601. <a class='right-next' id="next-link" href="inference.html" title="next page">
  602. <div class="prev-next-info">
  603. <p class="prev-next-subtitle">next</p>
  604. <p class="prev-next-title">States estimation (inference)</p>
  605. </div>
  606. <i class="fas fa-angle-right"></i>
  607. </a>
  608. </div>
  609. </div>
  610. </div>
  611. <footer class="footer">
  612. <p>
  613. By Kevin Murphy, Scott Linderman, et al.<br/>
  614. &copy; Copyright 2021.<br/>
  615. </p>
  616. </footer>
  617. </main>
  618. </div>
  619. </div>
  620. <script src="../../_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
  621. </body>
  622. </html>