Select your font size 
 
about us products & services consulting & support news & events contact us
Discussion of the canonical formula for Bayes Inference.

Deriving Bayes' Theorem - Ontario

print this article 
 

You are now in a position to discuss the canonical formula for Bayes inference. The derivation of Bayes formula follows naturally from the definition of conditional probability using the probability format:

P(A | B) = P(A & B) / P(B)

Using some algebra, this equation can be rewritten as:

P(A & B) = P(A | B) P(B)

The same right-hand value can also be computed using A as the conditioning variable:

P(A & B) = P(B | A) P(A)

Given this equivalence, you can write:

P(A | B) P(B) = P(B | A) P(A)

Simplifying, you arrive at Bayes theorem:

P(A | B) = P(B | A) P(A) / P(B)

Notice that this formula for computing a conditional probability is similiar to the original formula with the exception that the joint probability P(A & B) that used to appear in the numerator has been replaced with the equivalent expression P(B | A) P(A).

Computing the full posterior

Bayesian inference is often put forth as a prescriptive framework for hypothesis testing. Using this framework, it is standard to replace P(A | B) with P(H | E) where H stands for hypothesis and E stands for evidence. Bayes inference rule then looks like this:

P(H | E) = P(E | H) P(H) / P(E)

In words, the formula says that the posterior probability of a hypothesis given the evidence P(H | E) is equal to the likelihood of the evidence given the hypothesis P(E | H) multiplied by the prior probability of the hypothesis P(H). You can ignore P(E) as only serving a normalization role (in other words, ensuring the sum of all the cell probabilities is 1.0). You can thus mentally simplify the equation to:

P(H | E) = P(E | H) P(H)

The prior distribution P(H) in this equation can be represented in PHP as an indexed array of probability values (as shown):

var $priors = array();

The $priors array is expected to contain a list of numbers denoting the prior probability of each hypothesis. In the context of medical diagnosis, the $priors array might contain the prevalence rates of each hypothesized disease in the population. Alternatively, the array might contain a medical specialist's best guess as to the prior probability of each disease under consideration given everything they know about each disease and current conditions.

The exact nature of the full posterior probability computation is made clearer by seeing that the posterior and likelihood terms appear in a PHP implementation as two-dimensional arrays (the closest you can currently get to a matrix datatype in PHP).

Listing 3. The posterior and likelihood terms appear in a PHP implementation as 2D arrays
<?php

// $m denotes the number of hypothesis
// $n denotes the number of evidence patterns

$m = 3;
$n = 4;

$priors      = getPriorDistribution();
$likelihoods = getlikelihoodDistribution();
$evidence    = getEvidenceDistribution();

for($e=0; $e < $n; $e++) {
  for ($h=0; $h < $m; $h++) {
    $posterior[$e][$h] = $priors[$h]
       * $likelihoods[$h][$e] / $evidence[$e];
  }
}

?>

For now, ignore the issue of how the $prior, $likelihood, and $evidence distribution values are computed from raw data. You can posit magical get functions to obtain these values. The previous code shows how the values of the posterior probability matrix are computed by looping over the evidence items and the hypothesis alternatives.

The order of the index elements $e and $h in the posterior matrix might be puzzling until you realize that in PHP the evidence key should appear first in the posterior matrix because it is a lookup key. If you access the posterior matrix using an evidence key $e, it will return an array containing the probability of each hypothesis under consideration (such as, +cancer, -cancer) given the particular evidence key you have supplied (like +test). The code above computes the full posterior distribution over all evidence keys. To compute a row of the full posterior distribution for a particular evidence key, you would use this formula:

Figure 2. Formula to compute posterior distribution
Formula to compute posterior distribution



Page:   1  2  3  4  5  6  7  8  9  10  11 Next Page: Medical diagnosis wizard

The content shown in this page was first published by IBM developerWorks and is reprinted with permission from Paul Meagher (www.datavore.com)


Most Recent Website and Regional Updates

 Transparen Corporation Canada Day Celebrations July 1, 2006
Transparen Corp. is proud of its Canadian heritage, and gladly celebrates Canada Day every year. Look back at previous Canada Days to learn about Transparen's history.

 
 Timing Upgrades - Factors Affecting Time Between Purchases for Tech Toys
It is possible to understand client purchase decisions by performing a regression analysis. By forming strategies based on the results, companies can optimize strategic programs to maximize profits.

 
 Federal Candidates Weigh In On Fairness
McGuinty government posts responses to Ontario?s call for fairness.

 
 Ontario Pays Tribute To Fallen Firefighters
McGuinty government honours families at Queen?s Park, fire fighter memorial.

 
 Ontario Celebrates Its Olympic Athletes
Premier McGuinty Passes The Torch With Pan Am Bid

 
 Ontario Supports Craft Brewers
The Government of Ontario is making an $8-million commitment to help ensure the prosperity of small brewers for many years to come.

 
 New Honda Engine Plant Drives Green Jobs
McGuinty Government Calls Plant A Vote Of Confidence In Ontario?s Skilled Workers

 
 Turning Innovation Into Ontario Jobs
Today, the government intends to introduce Ideas for the Future Act, 2008, that, if passed, would provide a 10-year corporate income tax exemption for new companies that turn home-grown ideas into Ontario jobs and products.

 
 Speaking Up For Ontario
Premier urges Ontarians to sign petition and stand up for fairness.

 
 Improving Care for Ontario?s Youngest Patients
McGuinty Government Improving Access To Care And Reducing Wait Times For Kids

 
 Moving Ontario Forward, Together
McGuinty Government?s Latest Progress Report Tells Stories Of Real People

 
 Making Ontario More Competitive At Home And Abroad
Cabinet Shuffle Focuses On Strengthening Economy

 

Google
 
Web transparen.com

Contact Information

Related Information

 
  TORONTO ON
LONDON ON
OTTAWA ON
HAMILTON ON
 
 
E C M | © 2003-2007 Transparen Corp.      

Standardized Services: Data Recovery Service / Creative Services / Premium Web Hosting Services / System Administration Tech Support Services
Recent Projects: Full-Service Mortgage and Financing Company / System to manage flights from Vancouver to Tofino / Photo exchange verification service
Our Vancouver BC Server Proudly Hosts: automated parking and revenue control systems, leafside lane at southlands, cost effective alternative power sources, the photo genie, pacific forage bag supply, sunburst medical, neosonic design, roger mahler photography - passionate, intriguing, desirable, the connection between east and west, affordable flights to victoria and tofino, low interest mortgage brokers in vancouver, richmond, surrey, toronto, mortgage brokers in calgary
Toronto, Ottawa, Kanata, Hamilton, London - view entire list