DEV Community

Cover image for Probabilistic Reasoning (Bite-size Article)
koshirok096
koshirok096

Posted on

Probabilistic Reasoning (Bite-size Article)

Introduction

In the real world, not everything can be determined with a simple “yes” or “no.”

  • A medical test came back positive — but does that really mean the person is sick? There’s still a chance they aren’t.
  • An incoming email — is it spam, and with what probability?
  • While driving, is that dark object in front of the car a person or just a garbage bag?

In these situations where we can’t be 100% certain, Probabilistic Reasoning is the idea of handling possibilities by assigning numbers (probabilities) to them.


A Dog’s Bark and a Burglar

Probabilistic Reasoning means “reasoning about uncertainty using probability.” To illustrate this, let’s look at a simple example.

In a certain town, the probability of a burglar coming is 1%. If a burglar comes, your dog will bark 90% of the time. However, even when there is no burglar, your dog still barks 5% of the time at night.

Given these conditions, we want to answer: “If the dog barks at night, what is the probability that a burglar is actually present?”

Using Probabilistic Reasoning (via Bayes’ theorem), we can write a short JavaScript example:

// Probabilistic reasoning with a dog and a burglar (Bayesian update)

function posteriorThief(priorThief, sensitivity, specificity) {
  const falseAlarm = 1 - specificity;
  // Bayes' theorem
  return (sensitivity * priorThief) /
         (sensitivity * priorThief + falseAlarm * (1 - priorThief));
}

// Prior probability: a burglar comes 1% of the time
const priorThief = 0.01;
// Sensitivity: if a burglar comes, the dog barks 90% of the time
const sensitivity = 0.90;
// Specificity: if there is no burglar, the dog stays quiet 95% of the time
// (meaning a 5% false alarm rate)
const specificity = 0.95;

const result = posteriorThief(priorThief, sensitivity, specificity);
console.log("Probability that a burglar is present when the dog barks =",
            (result * 100).toFixed(1), "%");
Enter fullscreen mode Exit fullscreen mode

The result will be:

Probability that a burglar is present when the dog barks = 15.4 %
Enter fullscreen mode Exit fullscreen mode

So, “the dog barked = there’s a burglar” does not hold true.
In fact, the probability of a burglar actually being there is only about 15%. Because the prior probability of a burglary (1%) is so low, the posterior probability doesn’t rise very high, even with the evidence of barking.

This is the essence of Probabilistic Reasoning: updating our beliefs under uncertainty using probabilities.


Other familiar applications include:

  • Spam detection: “This email is 95% likely to be spam.”

  • Weather forecasts: “There’s a 70% chance of rain tomorrow.”

  • Autonomous driving: “There’s a 70% chance that the object ahead is a person — stop the car.”

In our daily lives, we constantly benefit from such probability-based reasoning.


Conclusion

Probabilistic Reasoning, and the ideas derived from it, are applied in countless aspects of everyday life.
In particular, in hot fields like AI technology and data science, these concepts are used to enable rational decisions such as: “We don’t know for sure, but the likelihood is about this much.”

Thank you for reading.

Top comments (0)