<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Random Hacks: Tag Robots</title>
    <link>http://www.randomhacks.net/articles/tag/Robots?tag=Robots</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Technology and Other Fun Stuff</description>
    <item>
      <title>Robot localization using a particle system monad</title>
      <description>&lt;p&gt;&lt;b&gt;Refactoring Probability Distributions:&lt;/b&gt;
&lt;a href="http://www.randomhacks.net/articles/2007/02/21/refactoring-probability-distributions" title="PerhapsT"&gt;part 1&lt;/a&gt;, &lt;a href="http://www.randomhacks.net/articles/2007/02/21/randomly-sampled-distributions" title="Random sampling"&gt;part 2&lt;/a&gt;, &lt;a href="http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests" title="Bayes' rule"&gt;part 3&lt;/a&gt;, &lt;a href="http://www.randomhacks.net/articles/2007/03/03/smart-classification-with-haskell" title="Bayesian classification"&gt;part 4&lt;/a&gt;, &lt;b&gt;part 5&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Welcome to the 5th (and final) installment of &lt;i&gt;Refactoring Probability
Distributions!&lt;/i&gt;  Today, let&amp;#8217;s begin with an example from 
&lt;a href="http://seattle.intel-research.net/people/jhightower/pubs/fox2003bayesian/fox2003bayesian.pdf" title="Fox and colleagues, 2003"&gt;Bayesian Filters for Location Estimation&lt;/a&gt; (PDF), an excellent paper by Fox and colleagues.&lt;/p&gt;

&lt;p&gt;In their example, we have a robot in a hallway with 3 doors.  Unfortunately, we don&amp;#8217;t know &lt;i&gt;where&lt;/i&gt; in the hallway the robot is located:&lt;/p&gt;

&lt;p style="text-align: center"&gt;&lt;img
src="http://www.randomhacks.net/files/robot-door-1.png" title="Robot at
first door" /&gt;&lt;/p&gt;

&lt;p&gt;The vertical black lines are &amp;#8220;particles.&amp;#8221;  Each particle represents a
possible location of our robot, chosen at random along the hallway.  At
first, our particles are spread along the entire hallway (the top
row of black lines). Each particle begins life with a weight of 100%, represented by the height of the black line.&lt;/p&gt;

&lt;p&gt;Now imagine that our robot has a &amp;#8220;door sensor,&amp;#8221; which currently tells us that
we&amp;#8217;re in front of a door. This allows us to rule out any particle which is located &lt;i&gt;between&lt;/i&gt; doors. &lt;/p&gt;

&lt;p&gt;So we multiply the weight of each particle by 100% (if it&amp;#8217;s in front of a door) or 0% (if it&amp;#8217;s between doors), which gives us the lower row of particles. If our sensor was less accurate, we might use 90% and 10%, respectively.&lt;/p&gt;

&lt;p&gt;What would this example look like in Haskell?  We &lt;i&gt;could&lt;/i&gt; build a
giant list of particles (with weights), but that would require us to do a
lot of bookkeeping by hand.  Instead, we use a &lt;a href="http://www.randomhacks.net/articles/2007/03/12/monads-in-15-minutes" title="Monads in 15 minutes"&gt;monad&lt;/a&gt; to hide all the
details, allowing us to work with a single particle at a time.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_haskell "&gt;&lt;span class='varid'&gt;localizeRobot&lt;/span&gt; &lt;span class='keyglyph'&gt;::&lt;/span&gt; &lt;span class='conid'&gt;WPS&lt;/span&gt; &lt;span class='conid'&gt;Int&lt;/span&gt;
&lt;span class='varid'&gt;localizeRobot&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt; &lt;span class='keyword'&gt;do&lt;/span&gt;
  &lt;span class='comment'&gt;-- Pick a random starting location.&lt;/span&gt;
  &lt;span class='comment'&gt;-- This will be our first particle.&lt;/span&gt;
  &lt;span class='varid'&gt;pos1&lt;/span&gt; &lt;span class='keyglyph'&gt;&amp;lt;-&lt;/span&gt; &lt;span class='varid'&gt;uniform&lt;/span&gt; &lt;span class='keyglyph'&gt;[&lt;/span&gt;&lt;span class='num'&gt;0&lt;/span&gt;&lt;span class='keyglyph'&gt;..&lt;/span&gt;&lt;span class='num'&gt;299&lt;/span&gt;&lt;span class='keyglyph'&gt;]&lt;/span&gt;
  &lt;span class='comment'&gt;-- We know we're at a door.  Particles&lt;/span&gt;
  &lt;span class='comment'&gt;-- in front of a door get a weight of&lt;/span&gt;
  &lt;span class='comment'&gt;-- 100%, others get 0%.&lt;/span&gt;
  &lt;span class='keyword'&gt;if&lt;/span&gt; &lt;span class='varid'&gt;doorAtPosition&lt;/span&gt; &lt;span class='varid'&gt;pos1&lt;/span&gt;
    &lt;span class='keyword'&gt;then&lt;/span&gt; &lt;span class='varid'&gt;weight&lt;/span&gt; &lt;span class='num'&gt;1&lt;/span&gt;
    &lt;span class='keyword'&gt;else&lt;/span&gt; &lt;span class='varid'&gt;weight&lt;/span&gt; &lt;span class='num'&gt;0&lt;/span&gt;
  &lt;span class='comment'&gt;-- ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What happens if our robot drives forward?&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.randomhacks.net/articles/2007/04/19/robot-localization-particle-system-monad"&gt;Read More&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 19 Apr 2007 20:43:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:d14628b2-732e-4b87-934f-c6373df35a5c</guid>
      <author>Eric Kidd</author>
      <link>http://www.randomhacks.net/articles/2007/04/19/robot-localization-particle-system-monad</link>
      <category>Haskell</category>
      <category>Math</category>
      <category>Monads</category>
      <category>Probability</category>
      <category>Robots</category>
      <trackback:ping>http://www.randomhacks.net/articles/trackback/399</trackback:ping>
    </item>
  </channel>
</rss>
