hmm_filter.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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>HMM filtering (forwards algorithm) &#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 = {"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="HMM smoothing (forwards-backwards algorithm)" href="hmm_smoother.html" />
  47. <link rel="prev" title="Hidden Markov Models" href="hmm.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">
  75. <a class="reference internal" href="../scratch.html">
  76. Scratchpad
  77. </a>
  78. </li>
  79. <li class="toctree-l1">
  80. <a class="reference internal" href="../ssm/ssm.html">
  81. What are State Space Models?
  82. </a>
  83. </li>
  84. <li class="toctree-l1 current active has-children">
  85. <a class="reference internal" href="hmm_index.html">
  86. Inference in discrete SSMs
  87. </a>
  88. <input checked="" class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/>
  89. <label for="toctree-checkbox-1">
  90. <i class="fas fa-chevron-down">
  91. </i>
  92. </label>
  93. <ul class="current">
  94. <li class="toctree-l2">
  95. <a class="reference internal" href="hmm.html">
  96. Hidden Markov Models
  97. </a>
  98. </li>
  99. <li class="toctree-l2 current active">
  100. <a class="current reference internal" href="#">
  101. HMM filtering (forwards algorithm)
  102. </a>
  103. </li>
  104. <li class="toctree-l2">
  105. <a class="reference internal" href="hmm_smoother.html">
  106. HMM smoothing (forwards-backwards algorithm)
  107. </a>
  108. </li>
  109. <li class="toctree-l2">
  110. <a class="reference internal" href="hmm_viterbi.html">
  111. Viterbi algorithm
  112. </a>
  113. </li>
  114. <li class="toctree-l2">
  115. <a class="reference internal" href="hmm_parallel.html">
  116. Parallel HMM smoothing
  117. </a>
  118. </li>
  119. <li class="toctree-l2">
  120. <a class="reference internal" href="hmm_sampling.html">
  121. Forwards-filtering backwards-sampling algorithm
  122. </a>
  123. </li>
  124. </ul>
  125. </li>
  126. <li class="toctree-l1 has-children">
  127. <a class="reference internal" href="../lgssm/lgssm_index.html">
  128. Inference in linear-Gaussian SSMs
  129. </a>
  130. <input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/>
  131. <label for="toctree-checkbox-2">
  132. <i class="fas fa-chevron-down">
  133. </i>
  134. </label>
  135. <ul>
  136. <li class="toctree-l2">
  137. <a class="reference internal" href="../lgssm/kalman_filter.html">
  138. Kalman filtering
  139. </a>
  140. </li>
  141. <li class="toctree-l2">
  142. <a class="reference internal" href="../lgssm/kalman_smoother.html">
  143. Kalman (RTS) smoother
  144. </a>
  145. </li>
  146. <li class="toctree-l2">
  147. <a class="reference internal" href="../lgssm/kalman_parallel.html">
  148. Parallel Kalman Smoother
  149. </a>
  150. </li>
  151. <li class="toctree-l2">
  152. <a class="reference internal" href="../lgssm/kalman_sampling.html">
  153. Forwards-filtering backwards sampling
  154. </a>
  155. </li>
  156. </ul>
  157. </li>
  158. <li class="toctree-l1 has-children">
  159. <a class="reference internal" href="../extended/extended_index.html">
  160. Extended (linearized) methods
  161. </a>
  162. <input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/>
  163. <label for="toctree-checkbox-3">
  164. <i class="fas fa-chevron-down">
  165. </i>
  166. </label>
  167. <ul>
  168. <li class="toctree-l2">
  169. <a class="reference internal" href="../extended/extended_filter.html">
  170. Extended Kalman filtering
  171. </a>
  172. </li>
  173. <li class="toctree-l2">
  174. <a class="reference internal" href="../extended/extended_smoother.html">
  175. Extended Kalman smoother
  176. </a>
  177. </li>
  178. <li class="toctree-l2">
  179. <a class="reference internal" href="../extended/extended_parallel.html">
  180. Parallel extended Kalman smoothing
  181. </a>
  182. </li>
  183. </ul>
  184. </li>
  185. <li class="toctree-l1 has-children">
  186. <a class="reference internal" href="../unscented/unscented_index.html">
  187. Unscented 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="../unscented/unscented_filter.html">
  197. Unscented filtering
  198. </a>
  199. </li>
  200. <li class="toctree-l2">
  201. <a class="reference internal" href="../unscented/unscented_smoother.html">
  202. Unscented smoothing
  203. </a>
  204. </li>
  205. </ul>
  206. </li>
  207. <li class="toctree-l1">
  208. <a class="reference internal" href="../quadrature/quadrature_index.html">
  209. Quadrature and cubature methods
  210. </a>
  211. </li>
  212. <li class="toctree-l1">
  213. <a class="reference internal" href="../postlin/postlin_index.html">
  214. Posterior linearization
  215. </a>
  216. </li>
  217. <li class="toctree-l1">
  218. <a class="reference internal" href="../adf/adf_index.html">
  219. Assumed Density Filtering
  220. </a>
  221. </li>
  222. <li class="toctree-l1">
  223. <a class="reference internal" href="../vi/vi_index.html">
  224. Variational inference
  225. </a>
  226. </li>
  227. <li class="toctree-l1">
  228. <a class="reference internal" href="../pf/pf_index.html">
  229. Particle filtering
  230. </a>
  231. </li>
  232. <li class="toctree-l1">
  233. <a class="reference internal" href="../smc/smc_index.html">
  234. Sequential Monte Carlo
  235. </a>
  236. </li>
  237. <li class="toctree-l1 has-children">
  238. <a class="reference internal" href="../learning/learning_index.html">
  239. Offline parameter estimation (learning)
  240. </a>
  241. <input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" type="checkbox"/>
  242. <label for="toctree-checkbox-5">
  243. <i class="fas fa-chevron-down">
  244. </i>
  245. </label>
  246. <ul>
  247. <li class="toctree-l2">
  248. <a class="reference internal" href="../learning/em.html">
  249. Expectation Maximization (EM)
  250. </a>
  251. </li>
  252. <li class="toctree-l2">
  253. <a class="reference internal" href="../learning/sgd.html">
  254. Stochastic Gradient Descent (SGD)
  255. </a>
  256. </li>
  257. <li class="toctree-l2">
  258. <a class="reference internal" href="../learning/vb.html">
  259. Variational Bayes (VB)
  260. </a>
  261. </li>
  262. <li class="toctree-l2">
  263. <a class="reference internal" href="../learning/mcmc.html">
  264. Markov Chain Monte Carlo (MCMC)
  265. </a>
  266. </li>
  267. </ul>
  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/hmm/hmm_filter.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/hmm/hmm_filter.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/hmm/hmm_filter.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/hmm/hmm_filter.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>
  388. </div>
  389. </div>
  390. <div id="main-content" class="row">
  391. <div class="col-12 col-md-9 pl-md-3 pr-md-0">
  392. <!-- Table of contents that is only displayed when printing the page -->
  393. <div id="jb-print-docs-body" class="onlyprint">
  394. <h1>HMM filtering (forwards algorithm)</h1>
  395. <!-- Table of contents -->
  396. <div id="print-main-content">
  397. <div id="jb-print-toc">
  398. </div>
  399. </div>
  400. </div>
  401. <div>
  402. <div class="tex2jax_ignore mathjax_ignore section" id="hmm-filtering-forwards-algorithm">
  403. <h1>HMM filtering (forwards algorithm)<a class="headerlink" href="#hmm-filtering-forwards-algorithm" title="Permalink to this headline">¶</a></h1>
  404. <div class="math notranslate nohighlight">
  405. \[\newcommand\floor[1]{\lfloor#1\rfloor}\]</div>
  406. <div class="cell docutils container">
  407. <div class="cell_input docutils container">
  408. <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
  409. </pre></div>
  410. </div>
  411. </div>
  412. <div class="cell_output docutils container">
  413. <div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>42
  414. </pre></div>
  415. </div>
  416. </div>
  417. </div>
  418. </div>
  419. <script type="text/x-thebe-config">
  420. {
  421. requestKernel: true,
  422. binderOptions: {
  423. repo: "binder-examples/jupyter-stacks-datascience",
  424. ref: "master",
  425. },
  426. codeMirrorConfig: {
  427. theme: "abcdef",
  428. mode: "python"
  429. },
  430. kernelOptions: {
  431. kernelName: "python3",
  432. path: "./chapters/hmm"
  433. },
  434. predefinedOutput: true
  435. }
  436. </script>
  437. <script>kernelName = 'python3'</script>
  438. </div>
  439. <!-- Previous / next buttons -->
  440. <div class='prev-next-area'>
  441. <a class='left-prev' id="prev-link" href="hmm.html" title="previous page">
  442. <i class="fas fa-angle-left"></i>
  443. <div class="prev-next-info">
  444. <p class="prev-next-subtitle">previous</p>
  445. <p class="prev-next-title">Hidden Markov Models</p>
  446. </div>
  447. </a>
  448. <a class='right-next' id="next-link" href="hmm_smoother.html" title="next page">
  449. <div class="prev-next-info">
  450. <p class="prev-next-subtitle">next</p>
  451. <p class="prev-next-title">HMM smoothing (forwards-backwards algorithm)</p>
  452. </div>
  453. <i class="fas fa-angle-right"></i>
  454. </a>
  455. </div>
  456. </div>
  457. </div>
  458. <footer class="footer">
  459. <p>
  460. By Kevin Murphy, Scott Linderman, et al.<br/>
  461. &copy; Copyright 2021.<br/>
  462. </p>
  463. </footer>
  464. </main>
  465. </div>
  466. </div>
  467. <script src="../../_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
  468. </body>
  469. </html>