<?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: Bayes' rule in Haskell, or why drug tests don't work</title>
    <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Technology and Other Fun Stuff</description>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by John Beattie</title>
      <description>&lt;p&gt;&amp;#8220;The moral of this story: No matter how accurate our drug test, we shouldn’t bother to run it unless we have probable cause.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;This can be related to the current security strategy at airports. Look for &amp;#8216;carnival booth algorithm&amp;#8217; for a description of the strategy and for criticism of it.&lt;/p&gt;


	&lt;p&gt;At first sight, I thought that your remark above leads to the conclusion that the airport security strategy is right: which is to say, select people for extra screening based on their ethnic background.&lt;/p&gt;


	&lt;p&gt;But in fact, it does the opposite: one should only select people for extra screening based on whether there is &amp;#8216;probable cause&amp;#8217;, i.e. on careful, human surveillance.&lt;/p&gt;</description>
      <pubDate>Tue, 26 Jun 2007 03:31:30 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:9d844d1e-b3c8-4a8c-a888-9c8bab93a421</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-469</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Allan E</title>
      <description>&lt;p&gt;Regarding David&amp;#8217;s comment &amp;#8220;condition is just guard&amp;#8221;, this doesn&amp;#8217;t work unless PerhapsT is a MonadPlus instance&amp;#8230; but in the darcs implementation there&amp;#8217;s a note on how this leads to ambiguous semantics.&lt;/p&gt;


	&lt;p&gt;Can we remove the ambiguity by picking the one for which&lt;/p&gt;


&lt;blockquote&gt;
	&lt;p&gt;condition = guard&lt;/p&gt;

&lt;/blockquote&gt;




	&lt;p&gt;works?&lt;/p&gt;</description>
      <pubDate>Thu, 14 Jun 2007 02:21:12 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:00f2cccc-3308-483f-b000-c9b2df9b75e4</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-468</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Max Lybbert</title>
      <description>&lt;p&gt;Unfortunately I just barely ran across this blog today.  I like it, and will be coming back.  So, although this is very late, you may consider looking at the &lt;span class="caps"&gt;CRM114&lt;/span&gt; Discriminator (http://crm114.sourceforge.net/ ), which is supposed to be a language with Bayesian filtering (and Markov chaining, and &amp;#8230;) built in.  But its design looks a little more like Perl than Lisp or Haskell.&lt;/p&gt;</description>
      <pubDate>Mon, 07 May 2007 17:20:06 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:5ba10006-5129-4812-b126-8978a36f90db</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-434</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Eric</title>
      <description>&lt;p&gt;(Re-reads the paper.)&lt;/p&gt;


	&lt;p&gt;Yeah, it looks as though I had generalized accidentally from Shan&amp;#8217;s treatment of interrogative pronouns (&amp;#8220;who&amp;#8221;, etc.) to pronouns in general.&lt;/p&gt;


	&lt;p&gt;And I don&amp;#8217;t pretend to understand the linguistic implications of focus, so I should probably refrain from commenting on Pointed Set monads until I read more papers. :-)&lt;/p&gt;


	&lt;p&gt;But my larger question involved the semantics of ambiguous sentences.  Specifically, I was interested in the relationship between natural language parsing and the resulting semantics in such sentences as:&lt;/p&gt;


&lt;blockquote&gt;Fruit flies like a banana.&lt;/blockquote&gt;

	&lt;p&gt;This classic example can be parsed in two fairly plausible ways:&lt;/p&gt;


&lt;blockquote&gt;
(Fruit flies)-NP (like-VP a banana).&lt;br /&gt;
Fruit-NP (flies-VP (like a banana)).&lt;/blockquote&gt;

	&lt;p&gt;(There&amp;#8217;s also a bunch of horribly bad parses which treat &amp;#8220;fruit&amp;#8221; as a &lt;a href="http://www.answers.com/fruit&amp;#38;r=67" rel="nofollow"&gt;transitive verb&lt;/a&gt;. Hey, it&amp;#8217;s in the dictionary.)&lt;/p&gt;


	&lt;p&gt;But these sentences aren&amp;#8217;t that different from:&lt;/p&gt;


&lt;blockquote&gt;Frank called Mark, and he got pretty upset.&lt;/blockquote&gt;

	&lt;p&gt;...where &amp;#8220;he&amp;#8221; could refer to either Frank or Mark. This sentence would become much less ambiguous if we could estimate the following probabilities from the surrounding context:&lt;/p&gt;


&lt;blockquote&gt;
P(Frank got upset|context)&lt;br /&gt;
P(Mark got upset|context)
&lt;/blockquote&gt;

	&lt;p&gt;So, my question: Given Chung-chieh Shan&amp;#8217;s framework, and the various probability monads (with or without Bayesian conditioning), can we assign reasonable semantics to ambiguous sentences?&lt;/p&gt;


	&lt;p&gt;As I said earlier, I don&amp;#8217;t have the foggiest idea of how to answer this question. :-)&lt;/p&gt;</description>
      <pubDate>Tue, 13 Mar 2007 08:32:23 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:daf321e5-2674-4027-9960-c9b977aa227f</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-358</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Chris</title>
      <description>&lt;p&gt;I recently read Shan&amp;#8217;s paper.  Mind-blowingly awesome. But the Set and Pointed Set monads aren&amp;#8217;t used there for fuzzy categories or for ambiguous referents.  (He actually uses the reader/environment monad to deal with different variable assignments, like with &amp;#8220;he&amp;#8221; having multiple possible referents.)&lt;/p&gt;


	&lt;p&gt;In the paper, Sets and Pointed Sets are used for the semantics of questions and focus, respectively.  Consider a sentence like &amp;#8220;Who ordered a tuna sandwich?&amp;#8221;  The idea is that the semantic interpretation of a question like this would be a set of interpretations something like ordered(x,tuna sandwich) for every x in some contextually given set of alternatives.  It might be broad &amp;#8211; the &amp;#8220;who&amp;#8221; could be any person or even any animate &amp;#8211; but more typically it would be more restricted &amp;#8211; the people in a restaurant, the friends you picked up lunch for, etc.&lt;/p&gt;


	&lt;p&gt;Shan then uses pointed sets to deal with what could be answers to such questions: &amp;#8220;John was the one that had the tuna sandwich.&amp;#8221;  This is like picking one of the alternatives out of that context set.  But you still need to care about the rest of the set of alternatives.  Consider &amp;#8220;Only John ordered a tuna sandwich&amp;#8221;.  The truth of such a sentence depends on the set of options: it&amp;#8217;s more likely to be true if only your friends are under consideration than if every living human being is.&lt;/p&gt;


	&lt;p&gt;So, in this context, I don&amp;#8217;t think Bayesianifying the Set/Pointed Set monads buys you anything.  (Not to say there might not be other linguistic uses of Bayesian monads.)&lt;/p&gt;</description>
      <pubDate>Tue, 13 Mar 2007 02:05:48 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:4e74b6ef-955e-4215-a7fe-959d0596b141</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-357</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by George Martkov</title>
      <description>&lt;p&gt;Its&amp;#8217; extremely real-life haskellish  reading! Thanks Eric. I rss you.&lt;/p&gt;


	&lt;p&gt;Also there&amp;#8217;re simple reason why &lt;a href="http://detoxproducts.info/" rel="nofollow"&gt;drug tests don&amp;#8217;t work&lt;/a&gt; )))&lt;/p&gt;</description>
      <pubDate>Sun, 11 Mar 2007 22:06:14 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:deda0b4f-292e-4c70-b6fc-f0ea6e3f15bd</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-350</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Eric</title>
      <description>&lt;p&gt;David: Thanks for helping people get started!&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve now set up a Darcs repository with all the necessary bits:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;darcs get http://www.randomhacks.net/darcs/probability&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Mon, 05 Mar 2007 08:02:51 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:090262c0-12e3-41cd-9616-43afd9f6ce7a</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-325</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by David House</title>
      <description>&lt;p&gt;Huh. Sorry about those appearing in boxes; they didn&amp;#8217;t when I previewed the comment. Methinks someone&amp;#8217;s comment &lt;span class="caps"&gt;CSS&lt;/span&gt; is leaking into the comments themselves :)&lt;/p&gt;</description>
      <pubDate>Thu, 01 Mar 2007 12:10:14 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9f9dae1c-33eb-4936-8ac2-f3539feac27a</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-321</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by David House</title>
      <description>&lt;p&gt;A few comments before I play with this a little more:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;You need a &lt;code&gt;Fractional&lt;/code&gt; instance for &lt;code&gt;Prob&lt;/code&gt; as you&amp;#8217;re using division in &lt;code&gt;onlyJust&lt;/code&gt;. This is fine, you can just derive it.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Functor&lt;/code&gt; instance for &lt;code&gt;FDist'&lt;/code&gt; isn&amp;#8217;t needed; there&amp;#8217;s already an &lt;code&gt;instance (Functor m) =&amp;gt; Functor (MaybeT m)&lt;/code&gt; in the &lt;code&gt;MaybeT&lt;/code&gt; module.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;condition&lt;/code&gt; is just &lt;code&gt;guard&lt;/code&gt;.&lt;/li&gt;&lt;/ol&gt;

	&lt;p&gt;For anyone that&amp;#8217;s interested in playing with this themselves, I&amp;#8217;ve pastebinned &lt;a href="http://pastebin.com/891574" rel="nofollow"&gt;a file&lt;/a&gt; which contains all the code you&amp;#8217;ll need. Fire up GHCi on it!&lt;/p&gt;</description>
      <pubDate>Thu, 01 Mar 2007 12:08:28 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8fe74d76-4364-4742-823e-74bbd21bf06b</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-320</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Danno</title>
      <description>&lt;p&gt;Sir, you just blew my mind.&lt;/p&gt;


	&lt;p&gt;Really learning Haskell is continually moving up on my priority scale.&lt;/p&gt;</description>
      <pubDate>Fri, 23 Feb 2007 18:38:26 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:27668e2f-2e43-416d-b12d-8e52db2d9013</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-315</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Eric</title>
      <description>&lt;p&gt;Judging from what dons told me last night, including MaybeT in the standard Haskell libraries would be  uncontroversial&amp;#8212;it&amp;#8217;s just a matter of somebody making the proposal and going through the process.&lt;/p&gt;


	&lt;p&gt;A note for anyone trying to follow along at home:&lt;/p&gt;


	&lt;p&gt;You may want to grab a MaybeT implementation from the &lt;a href="http://haskell.org/haskellwiki/New_monads" rel="nofollow"&gt;New monads page&lt;/a&gt;, and take a look at &lt;a href="http://www.randomhacks.net/articles/2007/02/21/refactoring-probability-distributions" rel="nofollow"&gt;part 1&lt;/a&gt; and &lt;a href="http://www.randomhacks.net/articles/2007/02/21/randomly-sampled-distributions" rel="nofollow"&gt;part 2&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;My apologies if this stuff is still a bit hard to get running. I hope to put up a Darcs repository soon. In the meantime, please feel free to post questions here!&lt;/p&gt;</description>
      <pubDate>Fri, 23 Feb 2007 12:40:43 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4b14aa5b-308f-41d6-aed9-498c9172e182</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-314</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Adam Langley</title>
      <description>&lt;p&gt;Is there a good reason why MaybeT isn&amp;#8217;t in the standard libraries? A MaybeT (esp with liftIO) is usually something I end up needing.&lt;/p&gt;</description>
      <pubDate>Fri, 23 Feb 2007 12:12:31 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2ac0d563-b07a-4a5f-9df8-e2042372cdb0</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-313</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by alpheccar</title>
      <description>&lt;p&gt;I really like this serie of posts about probabilities and Haskell !&lt;/p&gt;</description>
      <pubDate>Fri, 23 Feb 2007 09:24:27 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ec8836ba-b362-42b0-99a4-17bb66581c7f</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-312</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Eric</title>
      <description>&lt;p&gt;Interesting! Is there a good introduction to fuzzy categories for non-linguists?&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;IIRC&lt;/span&gt;, Shan uses the Set monad to represent ambiguous referents. The idea is that if the pronoun &amp;#8220;he&amp;#8221; might represent one of two people, you can do the calculation either way. (You can see the connection to logic programming here.)&lt;/p&gt;


	&lt;p&gt;Using a probability distribution monad, you could say, &amp;#8220;We&amp;#8217;re talking about Frank with 90% probability, and Mike with 10% probability.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Of course, it&amp;#8217;s not clear (to me, at least) how this relates to probabilistic parsing, or what the ability to use Bayes&amp;#8217; rule actually buys us.&lt;/p&gt;


	&lt;p&gt;And as for fuzzy categories, well, I really shouldn&amp;#8217;t have looked, but &lt;a href="http://www.case.edu/artsci/math/wells/pub/ctcs.html" rel="nofollow"&gt;here you go&lt;/a&gt;:&lt;/p&gt;


&lt;blockquote&gt;
	&lt;p&gt;Chapter 15 introduces toposes.  A topos is a kind of generalized set theory in which the logic is intuitionistic instead of classical&amp;#8230;  Categories of fuzzy sets are recognized as almost toposes, and modest sets, which are thought by many to be the best semantic model of polymorphic lambda calculus, live in a specific topos.&lt;/p&gt;

&lt;/blockquote&gt;




	&lt;p&gt;Anyway, that&amp;#8217;s category theory for you.&lt;/p&gt;</description>
      <pubDate>Fri, 23 Feb 2007 08:11:51 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:d021cda7-7ada-4914-a995-498bf907a1c6</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-311</link>
    </item>
    <item>
      <title>"Bayes' rule in Haskell, or why drug tests don't work" by Michael</title>
      <description>&lt;p&gt;Ah, thanks for the link to the Shan paper&amp;#8212;I had not seen it before, and it&amp;#8217;s a very interesting read.&lt;/p&gt;


	&lt;p&gt;As to what would come of using a Bayesian monad in place of Set, I cannot say, though it sounds to me like it might lead to a good model for a semantics including fuzzy categories (in the natural language sense, rather than the category theoretic, even assuming CT &lt;em&gt;has&lt;/em&gt; a sense of &amp;#8220;fuzzy category&amp;#8221;).&lt;/p&gt;</description>
      <pubDate>Thu, 22 Feb 2007 19:41:55 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b5da4e01-4ecf-4637-b43d-5708dc4f9a56</guid>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests#comment-307</link>
    </item>
    <item>
      <title>Bayes' rule in Haskell, or why drug tests don't work</title>
      <description>&lt;p&gt;Part 3 of Refactoring Probability Distributions.&lt;br /&gt;
&lt;small&gt;(Part 1: &lt;a href="http://www.randomhacks.net/articles/2007/02/21/refactoring-probability-distributions"&gt;PerhapsT&lt;/a&gt;,
Part 2: &lt;a href="http://www.randomhacks.net/articles/2007/02/21/randomly-sampled-distributions"&gt;Sampling functions&lt;/a&gt;)&lt;/small&gt;&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;i&gt;A very senior Microsoft developer who moved to Google told
    me that Google works and thinks at a higher level of abstraction than
    Microsoft. &amp;#8220;Google uses Bayesian filtering the way Microsoft uses the if
    statement,&amp;#8221; he said.&lt;/i&gt; -&lt;a href="http://www.joelonsoftware.com/oldnews/pages/October2005.html"&gt;Joel Spolsky&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I really love this quote, because it&amp;#8217;s &lt;a href="http://weblog.raganwald.com/archives/2005_10_01_archive.html"&gt;insanely provocative&lt;/a&gt;
to any language designer.  What &lt;i&gt;would&lt;/i&gt; a programming language look
like if Bayes&amp;#8217; rule were as simple as an &lt;code&gt;if&lt;/code&gt; statement?&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s start with a toy problem, and refactor it until Bayes&amp;#8217; rule is baked
right into our programming language.&lt;/p&gt;

&lt;p&gt;Imagine, for a moment, that we&amp;#8217;re in charge of administering drug tests for
a small business.  We&amp;#8217;ll represent each employee&amp;#8217;s test results (and drug use) as follows:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_haskell "&gt;&lt;span class='keyword'&gt;data&lt;/span&gt; &lt;span class='conid'&gt;Test&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt; &lt;span class='conid'&gt;Pos&lt;/span&gt; &lt;span class='keyglyph'&gt;|&lt;/span&gt; &lt;span class='conid'&gt;Neg&lt;/span&gt;
  &lt;span class='keyword'&gt;deriving&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;Show&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='conid'&gt;Eq&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt;

&lt;span class='keyword'&gt;data&lt;/span&gt; &lt;span class='conid'&gt;HeroinStatus&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt; &lt;span class='conid'&gt;User&lt;/span&gt; &lt;span class='keyglyph'&gt;|&lt;/span&gt; &lt;span class='conid'&gt;Clean&lt;/span&gt;
  &lt;span class='keyword'&gt;deriving&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;Show&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='conid'&gt;Eq&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Assuming that 0.1% of our employees have used heroin recently, and that our test is 99%
accurate, we can model the testing process as follows:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_haskell "&gt;&lt;span class='varid'&gt;drugTest1&lt;/span&gt; &lt;span class='keyglyph'&gt;::&lt;/span&gt; &lt;span class='conid'&gt;Dist&lt;/span&gt; &lt;span class='varid'&gt;d&lt;/span&gt; &lt;span class='keyglyph'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='varid'&gt;d&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;HeroinStatus&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='conid'&gt;Test&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt;
&lt;span class='varid'&gt;drugTest1&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt; &lt;span class='keyword'&gt;do&lt;/span&gt;
  &lt;span class='varid'&gt;heroinStatus&lt;/span&gt; &lt;span class='keyglyph'&gt;&amp;lt;-&lt;/span&gt; &lt;span class='varid'&gt;percentUser&lt;/span&gt; &lt;span class='num'&gt;0.1&lt;/span&gt;
  &lt;span class='varid'&gt;testResult&lt;/span&gt; &lt;span class='keyglyph'&gt;&amp;lt;-&lt;/span&gt;
    &lt;span class='keyword'&gt;if&lt;/span&gt; &lt;span class='varid'&gt;heroinStatus&lt;/span&gt; &lt;span class='varop'&gt;==&lt;/span&gt; &lt;span class='conid'&gt;User&lt;/span&gt;
      &lt;span class='keyword'&gt;then&lt;/span&gt; &lt;span class='varid'&gt;percentPos&lt;/span&gt; &lt;span class='num'&gt;99&lt;/span&gt;
      &lt;span class='keyword'&gt;else&lt;/span&gt; &lt;span class='varid'&gt;percentPos&lt;/span&gt; &lt;span class='num'&gt;1&lt;/span&gt;
  &lt;span class='varid'&gt;return&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='varid'&gt;heroinStatus&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='varid'&gt;testResult&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt;

&lt;span class='comment'&gt;-- Some handy distributions.&lt;/span&gt;
&lt;span class='varid'&gt;percentUser&lt;/span&gt; &lt;span class='varid'&gt;p&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt; &lt;span class='varid'&gt;percent&lt;/span&gt; &lt;span class='varid'&gt;p&lt;/span&gt; &lt;span class='conid'&gt;User&lt;/span&gt; &lt;span class='conid'&gt;Clean&lt;/span&gt;
&lt;span class='varid'&gt;percentPos&lt;/span&gt; &lt;span class='varid'&gt;p&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt; &lt;span class='varid'&gt;percent&lt;/span&gt; &lt;span class='varid'&gt;p&lt;/span&gt; &lt;span class='conid'&gt;Pos&lt;/span&gt; &lt;span class='conid'&gt;Neg&lt;/span&gt;

&lt;span class='comment'&gt;-- A weighted distribution with two elements.&lt;/span&gt;
&lt;span class='varid'&gt;percent&lt;/span&gt; &lt;span class='varid'&gt;p&lt;/span&gt; &lt;span class='varid'&gt;x1&lt;/span&gt; &lt;span class='varid'&gt;x2&lt;/span&gt; &lt;span class='keyglyph'&gt;=&lt;/span&gt;
  &lt;span class='varid'&gt;weighted&lt;/span&gt; &lt;span class='keyglyph'&gt;[&lt;/span&gt;&lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='varid'&gt;x1&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='varid'&gt;p&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='varid'&gt;x2&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt; &lt;span class='num'&gt;100&lt;/span&gt;&lt;span class='comment'&gt;-&lt;/span&gt;&lt;span class='varid'&gt;p&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt;&lt;span class='keyglyph'&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This code is based our &lt;a href="http://www.randomhacks.net/articles/2007/02/21/randomly-sampled-distributions"&gt;FDist monad&lt;/a&gt;, which is in turn based on
&lt;a href="http://web.engr.oregonstate.edu/~erwig/pfp/"&gt;PFP&lt;/a&gt;.  Don&amp;#8217;t worry if it seems slightly mysterious; you can think of the
&amp;ldquo;&lt;code&gt;&amp;lt;-&lt;/code&gt;&amp;#8221; operator as choosing an element from a probability
distribution.&lt;/p&gt;

&lt;p&gt;Running our drug test shows every possible combination of the two
variables:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_haskell "&gt;&lt;span class='varop'&gt;&amp;gt;&lt;/span&gt; &lt;span class='varid'&gt;exact&lt;/span&gt; &lt;span class='varid'&gt;drugTest1&lt;/span&gt;
&lt;span class='keyglyph'&gt;[&lt;/span&gt;&lt;span class='conid'&gt;Perhaps&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;User&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;&lt;span class='conid'&gt;Pos&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt; &lt;span class='num'&gt;0.1&lt;/span&gt;&lt;span class='varop'&gt;%&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;
 &lt;span class='conid'&gt;Perhaps&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;User&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;&lt;span class='conid'&gt;Neg&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt; &lt;span class='num'&gt;0.0&lt;/span&gt;&lt;span class='varop'&gt;%&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;
 &lt;span class='conid'&gt;Perhaps&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;Clean&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;&lt;span class='conid'&gt;Pos&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt; &lt;span class='num'&gt;1.0&lt;/span&gt;&lt;span class='varop'&gt;%&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;
 &lt;span class='conid'&gt;Perhaps&lt;/span&gt; &lt;span class='layout'&gt;(&lt;/span&gt;&lt;span class='conid'&gt;Clean&lt;/span&gt;&lt;span class='layout'&gt;,&lt;/span&gt;&lt;span class='conid'&gt;Neg&lt;/span&gt;&lt;span class='layout'&gt;)&lt;/span&gt; &lt;span class='num'&gt;98.9&lt;/span&gt;&lt;span class='varop'&gt;%&lt;/span&gt;&lt;span class='keyglyph'&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you look carefully, we have a problem.  Most of the employees who test
positive are actually clean!  Let&amp;#8217;s tweak our code a bit, and try to zoom
in on the positive test results.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests"&gt;Read More&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 22 Feb 2007 18:11:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:fffdc914-d289-4ac8-bde5-7bbb02451aeb</guid>
      <author>Eric Kidd</author>
      <link>http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests</link>
      <category>Haskell</category>
      <category>Math</category>
      <category>Monads</category>
      <category>Probability</category>
      <category>Recommended</category>
      <trackback:ping>http://www.randomhacks.net/articles/trackback/306</trackback:ping>
    </item>
  </channel>
</rss>
