PHP
  Home arrow PHP arrow Page 3 - Implement Bayesian inference using PHP...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Implement Bayesian inference using PHP, Part 1
By: developerWorks
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 23
    2005-01-05

    Table of Contents:
  • Implement Bayesian inference using PHP, Part 1
  • Conditional probability
  • Learning from experience
  • Conditional probability and SQL
  • Frequency versus probability format
  • Deriving Bayes Theorem
  • Medical diagnosis wizard
  • Implementing the calculation with Bayes.php
  • Sensitivity analysis
  • Resources

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Implement Bayesian inference using PHP, Part 1 - Learning from experience


    (Page 3 of 10 )

    To appreciate how the getConditionalProbabiltity function might be used in practice, consider a doctor confronted with the problem of determining whether a patient has cancer given that the patient tested positive on some cancer test. The test could be something as simple as a "yes" or "no" answer to a question (such as, were you ever exposed to high levels of radiation?) or it could be the result of a physical examination of the patient.

    To compute the conditional probability of cancer given a positive test result, the doctor might tally the number of past cases where cancer and a positive test result occurred together and divide by the overall number of positive test results. The following code computes this probability based on a total of four past cases where this co-variation information was collected -- perhaps from the doctor's personal experiences with this particular cancer test.

    Listing 2. Computing a conditional probability using getConditionalProbabiltity

    <?php

    require "getConditionalProbability.php";

    /**
    * The elements of the $Data array use this coding convention:
    *
    * +cancer - patient has cancer
    * -cancer - patient does not have cancer
    * +test   - patient tested positive on cancer test
    * -test   - patient tested negative on cancer test
    */

    $Data[0] = array("+cancer", "+test");
    $Data[1] = array("-cancer", "-test");
    $Data[2] = array("+cancer", "+test");
    $Data[3] = array("-cancer", "+test");

    // specify query variable $A and conditioning variable $B
    $A = "+cancer";
    $B = "+test";

    // compute the conditional probability of having cancer given 1)
    // a positive test and 2) a sample of covariation data
    $probability = getConditionalProbabilty($A, $B, $Data);

    echo "P($A|$B) = $probability";

    // P(+cancer|+test) = 0.66666666666667

    ?>

    As you can see, the probability of having cancer given:

    1. A positive test result

    2. The data collected to date is estimated at 67 percent. In other words, in the next 100 cases where a patient tests positive, the best point estimate is that in 67 of those cases, the patient will actually have cancer. The doctor will need to weight this probability along with other information to arrive at a final diagnosis if one is warranted.

    I can summarize what has been demonstrated here in more radical terms as follows:

    An agent that derives a conditional probability estimate using the enumeration method appears to learn from experience and will provide an optimal estimate of the true conditional probability if it has enough representative data to draw upon.

    If I replace the hypothetical doctor with a software agent implementing the enumeration algorithm above and being fed a steady diet of the case data, I might expect the agent's conditional probability estimates to become increasingly more reliable and accurate. I might say that such an agent is capable of "learning from experience."

    If this is so, perhaps I want to ask what the relationship is between this simple enumeration technique for computing a conditional probability and more legitimate examples of "learning from experience," such as the semi-automated classification of spam using Bayes methods. In the next section, I will show a simple spam filter can be constructed using the enumerative power of a database.

    More PHP Articles
    More By developerWorks


       · Definately worth reading.j.olson[url=http://www.linuxloggers.com/]Linux Help...
       · good article, for all science computer fields.
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT