“Be kind, for everyone you meet is fighting a hard battle” - Often attributed to Plato but likely from Ian McLaren (pseudonym of Reverend John Watson)

Friday, October 18, 2019

Am I safe to break in?

I saw a commercial for the Google Home Speaker in which the spokesperson was touting the speaker's ability to scare off burglars by playing the sound of a barking dog. I realize there are multiple systems out there to achieve this but that's not my point. I started thinking about this in terms of Bayesian inference. If I'm a burglar and, during an attempted intrusion, I hear the sound of a vicious dog, what's the likelihood that there's actually a dog ready to attack?


This is analogous to the archetypal example of Bayesian inference wherein the likelihood of actual breast cancer is evaluated in light of a positive mammogram ("test"). The "test" in this case would be listening for the sound of a barking dog prior to breaking into a home. A true positive would be hearing a barking dog when there is such a dog (analogous to a positive mammogram and actual breast cancer). A false positive would be hearing a barking dog when none exists, i.e., when the Home Speaker sounds a dog alarm but there is no dog.

In order to come up with an estimate of my safety when breaking in should I hear a barking dog, I need to have an estimate for:

  • The fraction of homes have appropriate (i.e., big and scary) dogs (analogous to how many women have breast cancer).
  • The fraction of homes have a barking dog sound generator (analogous to a false positive).
  • The fraction of the time that, if there is a big, scary dog in the house, it will bark and I will hear it (analogous to a true positive).
I'll estimate that 40% (0.4 fraction) of homes have a dog, and 30% of those are of a size that would deter me. I'll estimate that 2% (0.02 fraction) of homes have a dog sound generator. I'll estimate that 90% (0.9 fraction) that I case a home with an appropriate dog, that dog will bark and I will hear it.

In the table below, I've shown that 12% of homes have a big (barking) dog, and 88% do not. When I hear a big, scary dog, I'm in the "Test pos" row. The 0.108 entry is the 0.12 fraction of homes with a big, scary dog * the 0.9 fraction that the dog will bark and I will hear it. The 0.0176 entry is the 0.88 fraction of homes with no big, scary dog * the 0.02 fraction of homes with a barking dog sound generator.

Actual big dog No actual big dog
0.12 0.88
Test pos (heard barking big dog) 0.108 0.0176
Test neg (didn't hear barking big dog) 0.012 0.8624

Now, the probability of a true positive (I hear a big, scary dog and there's actually one in the house) is the number of true positives divided by the total number of positives, or 0.108/(0.108+0.0176)=0.8599 or about 86%. Of course, this number will vary, depending on the actual values for the needed parameters but I think that this is in the ballpark.

Moral of the story: If I'm intending to burgle a house and I hear a big, scary dog, I'd best move on.