{"id":23196,"date":"2023-03-07T06:05:08","date_gmt":"2023-03-07T06:05:08","guid":{"rendered":"https:\/\/www.booksofall.com\/in\/?post_type=product&#038;p=23196"},"modified":"2023-03-07T06:05:09","modified_gmt":"2023-03-07T06:05:09","slug":"kalman-and-bayesian-filters-in-python","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/","title":{"rendered":"Kalman and Bayesian Filters in Python"},"content":{"rendered":"<h2>Chapter 1 &#8211; The g-h Filter<\/h2>\n<h3>1.1 Building Intuition via Thought Experiments<\/h3>\n<p>Imagine that we live in a world without scales &#8211; the devices you stand on to weigh yourself. One day at work a co-worker comes running up to you and announces her invention of a \u2018scale\u2019 to you. After she explains, you eagerly stand on it and announce the results: \u201c172 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pound_(mass)\">lbs<\/a>\u201d. You are ecstatic &#8211; for the first time in your life you know what you weigh. More importantly, dollar signs dance in your eyes as you imagine selling this device to weight loss clinics across the world! This is fantastic!<\/p>\n<p>Another co-worker hears the commotion and comes over to find out what has you so excited. You explain the invention and once again step onto the scale, and proudly proclaim the result: \u201c161 lbs.\u201d And then you hesitate, confused.<\/p>\n<p>\u201cIt read 172 lbs a few seconds ago\u201d, you complain to your co-worker.<br \/>\n\u201cI never said it was accurate,\u201d she replies.<\/p>\n<p>Sensors are inaccurate. This is the motivation behind a huge body of work in filtering, and solving this problem is the topic of this book. I could just provide the solutions that have been developed over the last half century, but these solutions were developed by asking very basic, fundamental questions into the nature of what we know and how we know it. Before we attempt the math, let\u2019s follow that journey of discovery, and see if it informs our intuition about filtering.<\/p>\n<p><b>Try Another Scale\u00a0<\/b><\/p>\n<p>Is there any way we can improve upon this result? The obvious, first thing to try is get a better sensor.<\/p>\n<p>Unfortunately, your co-worker informs you that she has built 10 scales, and they all operate with about the same accuracy. You have her bring out another scale, and you weigh yourself on one, and then on the other. The first scale (A) reads \u201c160 lbs\u201d, and the second (B) reads \u201c170 lbs\u201d. What can we conclude about your weight?<\/p>\n<p>Well, what are our choices?<\/p>\n<ul>\n<li>We could choose to only believe A, and assign 160lbs to our weight estimate.<\/li>\n<li>We could choose to only believe B, and assign 170lbs to our weight.<\/li>\n<li>We could choose a number less than both A and B.<\/li>\n<li>We could choose a number greater than both A and B.<\/li>\n<li>We could choose a number between A and B.<\/li>\n<\/ul>\n<p>The first two choices are plausible, but we have no reason to favor one scale over the other. Why would we choose to believe A instead of B? We have no reason for such a belief. The third and fourth choices are irrational. The scales are admittedly not very accurate, but there is no reason at all to choose a number outside of the range of what they both measured. The final choice is the only reasonable one. If both scales are inaccurate, and as likely to give a result above my actual weight as below it, more often than not the answer is somewhere between A and B.<\/p>\n<p>In mathematics this concept is formalized as\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Expected_value\"><i>expected value<\/i><\/a>, and we will cover it in depth later. For now ask yourself what would be the \u2018usual\u2019 thing to happen if we took one million readings. Some of the times both scales will read too low, sometimes both will read too high, and the rest of the time they will straddle the actual weight. If they straddle the actual weight then certainly we should choose a number between A and B. If they don\u2019t straddle then we don\u2019t know if they are both too high or low, but by choosing a number between A and B we at least mitigate the effect of the worst measurement. For example, suppose our actual weight is 180 lbs. 160 lbs is a big error. But if we choose a weight between 160 lbs and 170 lbs our estimate will be better than 160 lbs. The same argument holds if both scales returned a value greater than the actual weight.<\/p>\n<p>We will deal with this more formally later, but for now I hope it is clear that our best estimate is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Average\">average<\/a> of A and B.<\/p>\n<p>(160 + 170)\/2 = 165<\/p>\n<p>We can look at this graphically. I have plotted the measurements of A and B with an assumed error of \u00b1 8 lbs. The measurements falls between 160 and 170 so the only weight that makes sense must lie within 160 and 170 lbs.<\/p>\n<p id=\"OUOVcfk\"><img loading=\"lazy\" decoding=\"async\" width=\"702\" height=\"238\" class=\"alignnone size-full wp-image-23200 \" src=\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/img_6406d192f1fc9.png\" alt=\"\" \/><\/p>\n<p>A word on how I generated this plot. I import code from the module book_plots in the kf_book subdirectory. Generating this plot takes a lot of boilerplate <a href=\"https:\/\/www.python.org\/\">Python<\/a> that isn\u2019t interesting to read. I take this tack often in the book. When the cell is run plot_errorbars() gets called and the plot is inserted into the book.<\/p>\n<p>If this is your first time using <a href=\"https:\/\/jupyter.org\/\">Jupyter Notebook<\/a>, the code above is in a\u00a0<i>cell<\/i>. The text \u201cIn [2]:\u201d labels this as a cell where you can enter input, and the number in the bracket denotes that this cell was run second. To run the cell, click on it with your mouse so that it has focus, then press CTRL+ENTER on the keyboard. As we continue you will be able to alter the code inside the cells and rerun them. Try changing the values \u201c160\u201d, \u201c170\u201d, and \u201c8\u201d to some other value and run the cell. The printed output should change depending on what you entered.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 750px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/-cc-by-4-0-kalman-and-bayesian-filters-in-python-19mduzvvh1?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":23201,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!"},"product_brand":[],"product_cat":[365],"product_tag":[],"class_list":{"0":"post-23196","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-mathematics-subjects","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Kalman and Bayesian Filters in Python - BooksOffAll Indian<\/title>\n<meta name=\"description\" content=\"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"hi_IN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kalman and Bayesian Filters in Python - BooksOffAll Indian\" \/>\n<meta property=\"og:description\" content=\"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOffAll Indian\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-07T06:05:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"\u0905\u0928\u0941\u092e\u093e\u0928\u093f\u0924 \u092a\u0922\u093c\u0928\u0947 \u0915\u093e \u0938\u092e\u092f\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 \u092e\u093f\u0928\u091f\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/\",\"url\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/\",\"name\":\"Kalman and Bayesian Filters in Python - BooksOffAll Indian\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/in\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg\",\"datePublished\":\"2023-03-07T06:05:08+00:00\",\"dateModified\":\"2023-03-07T06:05:09+00:00\",\"description\":\"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#breadcrumb\"},\"inLanguage\":\"hi-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"hi-IN\",\"@id\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg\",\"width\":\"827\",\"height\":\"1169\",\"caption\":\"Kalman and Bayesian Filters in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/in\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/in\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Kalman and Bayesian Filters in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/in\/#website\",\"url\":\"https:\/\/www.booksofall.com\/in\/\",\"name\":\"BooksOffAll Indian\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/in\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/in\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"hi-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/in\/#organization\",\"name\":\"BooksOffAll Indian\",\"url\":\"https:\/\/www.booksofall.com\/in\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"hi-IN\",\"@id\":\"https:\/\/www.booksofall.com\/in\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOffAll Indian\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/in\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Kalman and Bayesian Filters in Python - BooksOffAll Indian","description":"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/","og_locale":"hi_IN","og_type":"article","og_title":"Kalman and Bayesian Filters in Python - BooksOffAll Indian","og_description":"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!","og_url":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/","og_site_name":"BooksOffAll Indian","article_modified_time":"2023-03-07T06:05:09+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg","twitter_misc":{"\u0905\u0928\u0941\u092e\u093e\u0928\u093f\u0924 \u092a\u0922\u093c\u0928\u0947 \u0915\u093e \u0938\u092e\u092f":"4 \u092e\u093f\u0928\u091f"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/","url":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/","name":"Kalman and Bayesian Filters in Python - BooksOffAll Indian","isPartOf":{"@id":"https:\/\/www.booksofall.com\/in\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg","datePublished":"2023-03-07T06:05:08+00:00","dateModified":"2023-03-07T06:05:09+00:00","description":"Kalman and Bayesian filters in Python are tools used for estimation and prediction based on noisy and uncertain data. Learn more here!","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#breadcrumb"},"inLanguage":"hi-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"hi-IN","@id":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#primaryimage","url":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg","contentUrl":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2023\/03\/Kalman-and-Bayesian-Filters-in-Python.jpg","width":"827","height":"1169","caption":"Kalman and Bayesian Filters in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/in\/kalman-and-bayesian-filters-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/in\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/in\/categories\/"},{"@type":"ListItem","position":3,"name":"Kalman and Bayesian Filters in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/in\/#website","url":"https:\/\/www.booksofall.com\/in\/","name":"BooksOffAll Indian","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/in\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/in\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"hi-IN"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/in\/#organization","name":"BooksOffAll Indian","url":"https:\/\/www.booksofall.com\/in\/","logo":{"@type":"ImageObject","inLanguage":"hi-IN","@id":"https:\/\/www.booksofall.com\/in\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/in\/wp-content\/uploads\/sites\/13\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOffAll Indian"},"image":{"@id":"https:\/\/www.booksofall.com\/in\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/product\/23196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/media\/23201"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/media?parent=23196"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/product_brand?post=23196"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/product_cat?post=23196"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/in\/wp-json\/wp\/v2\/product_tag?post=23196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}