Showing posts with label probability. Show all posts
Showing posts with label probability. Show all posts

Saturday, August 3, 2013

Two stories – Oakland First Fridays, Black Ravens and Pink Flamingoes

Only one of the following two stories is true.

Oakland First Fridays: Maya and Elsa were with me at work yesterday, August 2nd, and overheard me making plans to go to Oakland's First Friday – a street/gallery food/art/music/people-watching festival. Maya asked whether I was going to take them. I said, “No, you will be with your mom tonight.”.
Elsa - “Are we with you next Friday?”
I - “Yes.”
Elsa - “Can we go with you to Oakland First Friday next week?”

Black Ravens and Pink Flamingoes:
Maya, Elsa and I were walking along the bay in Redwood Shores with Heather, a colleague. It was close to dusk and we saw a number of birds: a small number of red-winged blackbirds, crows, moor hens and cormorants, all mostly black; and a few killdeer, snowy egrets, a mourning dove nesting in a flowerpot at the entrance to Heather and Chris' home, scrub jays, great blue herons and clapper rails, all non-black. We also saw nine black ravens. I casually said, “Hmm, looks like all ravens are black.”, which seemed to go un-noticed at the time. Soon after, we saw another raven, which was also black. Heather said, “Oh, that raven is black, looks like you are right that all ravens are black.”

A short while later, Maya pointed out a pink flamingo.


Maya said, “Look Dad, a pink flamingo! Looks like you are even more right that all ravens are black!”

“What in the world do pink flamingoes have to do with black ravens?”

“Daa-ad! They do, I read it in my 'Great Philosophers' book and searched for it online! You said that 'All ravens are black.' That is logically equivalent to it's contrapositive, 'All non-black objects are non-ravens.' When Heather saw an additional raven and it was black, she pointed out (and you did not disagree) that it was evidence in favor of your original proposition that 'All ravens are black.' The contrapositive I just mentioned is logically equivalent. So when we see a non-black object (it is pink) and it is not a raven (since it is a flamingo), you should agree that it is evidence in favor of 'All ravens are black.'!”

“Oh god! Can't you just read some normal book about tribes of cats or that girl Parsnip or something who shot her little sister with an arrow? I suppose you are right!”
“Dad, okay, it seems to make sense logically, but I don't know if it is true in some statistical sense, all that “SQL, SQL, standard error and p-value” stuff you keep talking about now.”

“Let's take a crack at it. Let's denote
Proposition 1: “All ravens are black.” For the sake of simplicity let's just say that we are talking about birds and that we are trying to see if (the set of individual birds that are) ravens have some special property that distinguishes them from all birds (as individuals, not species). Then, practically speaking, the contrapositive and logical equivalent of Prop. 1 is
Proposition 2: “All non-black birds are non-ravens.”
Prior to Heather's observation, the evidence we had looked like
All birds of all colors Black non-Black All colors
Ravens 9 0 9
non-Ravens 50 8 58
All birds 59 8 67

Then she saw a black raven, and our evidence changed to
All birds of all colors Black non-Black All colors
Ravens 10 0 10
non-Ravens 50 8 58
All birds 60 8 68
And we agreed that this helped verify that prop 1 is true, in the sense that it allowed us to be more confident that Prop. 1 is true.

Then you saw a pink flamingo, and our evidence became
All birds of all colors Black non-Black All colors
Ravens 10 0 10
non-Ravens 50 9 59
All birds 60 9 69
And you are saying that this also allows us to be more confident that Prop. 1 is true. Let's forget about Prop.2 for a while. So for verifying that “All ravens are black.”, a pink flamingo is worth as much as a black raven. I can't think with concrete numbers, so let's use some abcedra:

All birds of all colors Black non-Black All colors
Ravens a 0 a
non-Ravens b c b+c
All birds a+b c a+b+c

On the basis of this evidence, the probability of any bird being non-black is
p = c/(a+b+c).

How much evidence is there to reject the hypothesis that some ravens are non-black? The specific null hypothesis in this case is
H : “Some raven-birds are non-black.”,
since we are hypothesizing that raven-birds are just any other individual bird, some of which are non-black.

Now, if the above H were true, and we make 'a' observations of birds which happen to be ravens, the probability P of getting 0 non-black is the product of the probabilities that each observed bird in this set of ravens is non-black, i.e. P = (1-p)*(1-p)*... a times = (1-p)a.
(Or you can use B[p,a](i) = C(a,i)*(1-p)^(a-i)*p^i for i = 0.)

This is the P-value, the probability of the consequence of the null hypothesis in this experiment, that we can use to reject the null hypothesis with 1-P degree of confidence. Recall that the smaller that P is, the more confidence we have in rejecting the Null Hypothesis, or “accepting the validity of proposition 1”.

So now we can ask about the relative merits of observing a black raven or a pink flamingo. Which additional observation reduces the P-value more? Let's use calclueless, since I am not secretive enough to do discrete math. What that means is we want to compare the marginal change (partial derivative) in the P-value when we make an additional observation of a black raven a → a + 1 vs. when we see a pink flamingo c → c + 1.

Since ln(P) = a*ln(1-p),
(d/d a) ln(P) = ln(1-p) and some work shows that the change in the P-value by observing a black raven, adding 1 to a:
(d/d a)P = P * ln(1-p),
which is less than 0, meaning that observing a black raven does reduce the P-value and increases the confidence in “All ravens are black.”!

Similarly,
(d/d c)p = (1-p)/(a + b+ c) ( > 0)
(d/d p)P = -a*P/(1 – p) (< 0) .

Simplifying, the change in the P-value by observing a pink flamingo, adding 1 to c:
(d/d c)P = -a*P/(a+b+c),
which is less than 0, meaning that observing a pink flamingo also reduces the P-value and increases the confidence in “All ravens are black.”!

The question that now remains is wether pink flamingoes are more valuable evidence than black ravens, i.e. which change decreases the P-value more:
|(d/d c)P| ?> |(d/d a)P|, which is equivalent, since P > 0, to
|(d/d c)ln(P)| ?> |(d/d a)ln(P)|
working through algebra
a/(a+b+c) ?> -ln(1-p).

Simplifying,
the condition we are looking for is

e^(a/(a+b+c)) ?> 1+ c/(a+b)

For a = 10, b = 50 and c = 8, it turns out that this is just marginally true!
A pink flamingo is just as valuable as a black raven in verifying that all ravens are black!
See the plot below

Since most birds are actually non-black, had we seen already a very large number of non-black non-ravens:

All birds of all colors Black non-Black All colors
Ravens 10 0 10
non-Ravens 50 90 140
All birds 60 90 150
Then the incremental value of seeing a pink flamingo would have been much less than that of seeing a black raven, for two reasons, one since we would have had a large proportion of non-black birds, the expected proportion of non-black ravens would have been correspondingly higher, making it all the more unlikely to see no non-black ravens amongst the additional ravens. Second, as the graph above shows, the incremental value of each non-black non-raven when we've already seen a lot does very little to increase our confidence that all ravens are black. For example, in the Rann of Kutch “Another pink flamingo, ho hum!
So, Maya, does it now make statistical sense that your pink flamingo sighting was just as important as Heather's black raven sighting for verifying that all ravens are black?”

Yes, Dad, I think I want to be a doctor when I grow up.”

The next day, we went out for lunch, and suddenly Elsa piped up, “Dad! More black ravens! I just saw an orange chicken!”

Can they fly?”

Sunday, November 4, 2012

Answers for "Man from the South" probability questions

Links to Dahl's  "Man from the South"

The questions are repeated in this post.

Preliminary answers

Q1. What does American Boy think is the probability of his lighter lighting during any single attempt?


Most people accept a bet when they think the odds are at least 50-50. Since Man from the South and American Boy have had time to negotiate the terms and think about it, both think they can win it. So as neutral observers we can consider the probability that the American Boy will win the bet to be 0.5.

So what does this tell us about what he thinks is the probability of the lighter lighting on any one attempt? Let this probability be p. The probability that he will win the bet, i.e. that it will light N times out of N trials, is pN. We just decided that this is ½, for N=10. So,
p10 = ½
I was driving and couldn't very well use my laptop (my phone is not a very smart phone), leave alone the log tables, slide rule or abacus in my back seat. And I can't do powers of 1/10 in my head, not in general. But I can calculate powers of numbers near 1! So let's calculate q=1-p instead, which is bound to be small since the boy is so sure of success.
½ = (1-q)N ~ 1-qN, so for N= 10, q=0.5/10 = 0.05.
Which gives us our first answer: p = 95%, which we know is a bit of an overestimate. (The exact answer is 93.3%.)

But this is like focusing on conversion ratio and not on cost-per-action.

Q4. Were there to have been a 9th attempt, and were American Boy to have failed in it, what would he have lost?


A: His left pinky, those were the terms of the bet. So American Boy is staking his pinky every time! All but the last time, if he wins, all he wins is the right to stay in the game, if he loses, chop-chop (and the right to play!)

So this is kinda sorta like conversion attribution: every bid-request we (RFI) win and then every impression we serve only gives us the right to stay in the game, in the sense that if we don't serve the impression we certainly won't get attribution credit.

Q2. How many fingers to a Cadillac?

On the face of it, it would seem to be one finger to a Cadillac, C = F, since if he loses, he loses a finger, and if he wins, he wins a Cadillac. But as we saw above, the American Boy stakes his one finger 10 times and thus faces 10 opportunities to lose his finger vs. one opportunity to win the Cadillac. So,
10F = C


After the eighth successful attempt, 

Man from the South's wife surprises them and ends the game. She sends American Boy away empty handed.

Q3. How should he have been compensated, if at all?

Aha! “How to distribute the spoils in an interrupted game?” The very question that my colleague Jack pointed out was the leading cause of the rise of probability theory!
The way I think of this is in terms of “vesting”. Each time they play and American Boy wins, he wins a 10th of a Caddy, but, BUT, he only gets to keep his winnings (the entire Cadillac) if he keeps his head (figuratively) and finger (literally) for 10 trials. American Boy can't get cold feet and walk out after say 5 trials and demand half a Cadillac – so really he can get cold feet and walk out but he can't drive off. So there are two possibilities. Under one, the Man from the South gets cold feet and decides not to play anymore. In this case he forfeits his Cadillac, which was held in escrow by the narrator. Under the other possibility, the “authorities” intervene. Since neither party has broken their terms, in this case I think American Boy gets to keep his “unvested” winnings, which would be 8/10 of a Cadillac. Now since the Cadillac wasn't the possession of the Man to begin with, but belonged to the “authorities”, … this isn't a math problem anymore. (By the way, who intervened and broke up Cardano and Pascal's poker game?)

Legal opinions? Aji, Joanne?

Q1 (Re-evaluated). What does American Boy think is the probability of his lighter lighting during any single attempt?


Most people accept a bet when they think it is a game with at least a zero sum in their favor. Since Man from the South and American Boy have had time to negotiate the terms and think about it, both think they can win it. So as neutral observers we can consider the game to be a zero-sum game.

What does it mean for this to be a zero-sum game? Winnings * probability of winning – losses * probability of losing = 0! Which yields:
p = 1/(W/L + 1). (Check: if W are high, p is low; if W are nearly 0, p is nearly 1 and if W=L, p =1/2.)

In our case the winnings are the Cadillac C, the losses are the finger F and the probability P of winning the entire game is P = pN, where p is the probability of the lighter lighting in a single trial. Combining things we have
C*P – F*(1-P) = 1, or P = 1/(C/F + 1)
Putting in C/F = 10,
p10 = 1/11

1/11 = (1-q)N ~ 1-qN, so for N= 10, q=1/11 = 0.1.
Which gives us 78.7%.

Really? Would you play that game with a lighter which only lights less than 80% of the time? I think that the Man from the South has fuddled the American Boy into undervaluing his finger, by making him think he is wagering a finger vs. a Cadillac, whereas really he is wagering a finger against a 10th of a Cadillac.

Some preliminaries

If you aren't interested in the nuts and bolts, skip them, but this is so anyone can check my work.
Notation: Sum[i, 0, Infinity] f(i) is to be interpreted as the sum of the function or series f(i) over the index i from i=0 to i= Infinity. Then,
Sum[n,0,Infinity] pn = 1/(1-p)
Sum[n,0,N] pn = (1-pN+1)/(1-p)
and
Sum[n,1,N] pn = (1-pN)*p/(1-p)

Look at the following table of outcomes of consecutive tosses and the overall probabilities
W ← 1 → L
1: p (1-p) (End)
2: p2 p(1-p) (End)
3: p3 p2(1-p) (End)
So after n trials, the probability of winning all is pn and the probability of losing any is
(1-p)* Sum[i,0,n-1] pi = (1-p) * (1-pn)/(1-p) = 1-pn = 1- prob(Winning). Which is good since it indicates I can still sum correctly.

Back to the problem, to get a handle on 

what if anything AB deserves when the game is stopped.

From making the last, Nth, trial a zero-sum game, we know that
pN = 1/(C/F + 1). We've assumed that AB wins 1/N th of a Cadillac (virtually) when his lighter lights. So assuming the first trial is also a 0-sum game, we have:
p*C/N = (1-p) *F, which resolves as
p = (C/NF + 1) ^(-1).

Can these two equations be solved simultaneously for both C/F and p?
Yes, but the solution is i) independent of N and ii) meaningless:
We have (1+C/NF)^N = (1 + C/F), but the RHS is simply the first two terms in the binomial expansion for the LHS, so the equality holds only when C/F = 0 and p =1.

So one of our assumptions above is wrong. 

Let's try another tack. 

Assume that at the nth trial, AB wins some unknown portion of the Cadillac a(n)*C. (When Ari and I were talking about this last week, Ari guessed, “Wouldn't it be some quadratic or increasing portion that he wins?” Ari's motivation was to take into account the wearing out of the flint, the gas running out, the thumb getting tired, AB getting nervous etc. Dahl, spends an entire paragraph describing the care and attention to detail taken by AB, after each light, he blows on the lighter, closes the lighter, waits a few seconds perhaps for gas pressure to build up again, re-opens it and then flicks it once. ) What we know is that
Sum[n,1,N] a(n) = 1, over the course of the entire game, if he survives, he wins the entire Cadillac. So at every trial, AB stands to lose not just his finger and the right to play, but also the “won but not vested” portion of the Cadillac, and he stands to win some portion of the remaining.

At the last, Nth trial: W : L
p : (1-p)
a(N)C : F + (1-a(N))C
Using the 0-sum equation, we get:
a(N) = (1 +F/C)(1-p).
Great, so now we have ONE equation and 3 unknowns: a(N), F/C and p. But we also know that if the game is 0-Sum over all: p^N * C = F*(1-p^N),
which yields:
0 < p = (1+C/F)^(-1/N) < 1. So now at least we have two equations for three unknowns, and the solution for p is valid. This doesn't guarantee that 0


If we knew C/F, we could solve the problem. However, clearly, C=F is no longer valid. C = 10F could be used for AB's assumption. We also have another source of information: The Man from the South's wife explains that he has lost eleven cars and taken forty-seven fingers. Assuming that he considers these equivalent, we have 11C = 47F
so,

The fraction C/F is the ratio of the value of one Cadillac to the value of one Finger.


But all this hasn't answered the question of 
what AB deserves when the game is interrupted. 
Also, we've assumed that the entire game is 0-sum and that the last trial is 0-sum. Can't we make use of the assumption that 

every trial is also 0 sum 

to see if we can figure out the intermediate non-vested winnings?

Recall that at the nth trial, AB stakes his previous winnings and his finger for a chance to win a(n)*C portion of the Cadillac. So the 0-Sum equation for the nth trial is:
a(n)*C = (1/p -1) *(F + C* Sum[i, 0, n-1] a(i)). The resulting recursion relation is for a geometric series!
a(n+1) = (1/p)* a(n),
whose solution is
a(n) = a(0)/p^n.
Note immediately that a(0) != 0, so AB has to stake (even if only virtually) something more than just his finger. 

We find a(0) 

by using the fact that the total portion of the Cadillac gained over 10 trials is 1:
1 = Sum[i,1,N] a(i) = a(0) * Sum[i,1,N] (1/p)^i = a(0) * (1/p^N -1)/(1-p), or

a(0) = (1-p)/(1/p^N – 1)

For the first trial (note that this is independent information since so far we have used the recursion relation and established a(0) using the “normalization”, but we haven't yet used any 

“initial conditions”):

a(1)*C = (1/p – 1) * ( F + a(0)*C), which yields
C/F = ((1/p)N -1)/p, which is a different relationship between C/F, N and p than we had previously. I am not sure I can invert this to yield p(C/F), but it can certainly be numerically solved.

Let us also calculate the virtual winnings after each trial:

W(n) = C*Sum[i,1,n]a(i) = C*a(0)*(1/p^n -1)/(1-p), which simplifies to
W(n) = ((1/p)n - 1)/((1/p)N - 1)

So given p we could calculate C/F (or vice versa), a(0), a(n) and W(n)


Working on the “wife's numbers”, we see that the American Boy should be compensated with 66% of the Cadillac when the wife interrupts the game after the 8th trial.

How do the winnings increase as the trials proceed:

Winnings in units of "Cadillacs"
 
which look like
Levenfeld curve


Conclusion and final answers:

Q1. What does American Boy think is the probability of his lighter lighting during any single attempt?
About 80%.

Q2. How many fingers to a Cadillac?
In American Boy's valuation based on his behaviour, 10 fingers to a Cadillac.

After the eighth successful attempt, Man from the South's wife surprises them and ends the game. She sends American Boy away empty handed.

Q3. How should he have been compensated, if at all?
With 60 or 66% of a Cadillac. I would go with 66%, which is based on the Man from the South's experienced equivalence between Cadillacs and fingers.

Q4. Were there to have been a 9th attempt, and were American Boy to have failed in it, what would he have lost?
Ah, his finger, of course, and, his virtual stake, which is 3.9 % of a Cadillac. How could he have lost something he never had to begin with? Well, for the bet to proceed, AB would have had to ask the narrator to spot him 4% of a Cadillac, or its cash equivalent, or its (OUCH) finger equivalent, which is 17% (3.9% * 4.3 F/C).
If AB's lighter fails during the game, he loses 1.17 fingers since he would have to sell 0.17 fingers to the Man from the South to pay off the debt to the narrator. If AB's lighter doesn't fail during the game, he simply returns the cash or Cadillac equivalent from whoever he borrowed it, and is ahead one Cadillac. 

Why did I ever think of approaching the problem this way, with a “virtual stake”? In particle physics, one can borrow virtual particles from the vaccuum in order to simplify calculations. It is all halal as long as the virtual particles don't violate any conservation laws for quantum numbers and the mass-energy of the particles exists for a short enough duration of time that Heisenberg's Uncertainty principle is not violated. The really interesting thing is that these virtual particles have real effects: A pair of uncharged conducting plates will attract each other because a virtual charged particle – anti-particle pair will come into existence from the vacuum for a brief time, and the effective dipole and its images will cause the plates to experience an attractive force. Don't believe me, look up the Casimir Effect.

What happens if you grab those particles and forcibly separate them from each other and prevent them from annihilating each other as any decent particle-anti-particle pair should do? You end up creating a Black Hole-White Hole pair, which you can then use for superluminal transportation and as a time-machine! (Okay, I just made that up, but is it really any crappier than “The Secret” or Deepak Chopra?)

Back to reality: The Man from the South's wife explains that he has lost eleven cars and taken forty-seven fingers.

Q5. What does Man from the South think is the probability that American Boy's lighter will light during a single attempt?
86%.

Q6. How many fingers to a Cadillac does Man from the South figure?
Th ratio of the values is C/F = 47/11.

Q7. Do your answers to Q3 and Q4 change?
Yes.

Added on 16th Nov. 2012
What was Fermat and Pascal's approach? Instead of looking backwards, they looked forward and calculated the probability (on the condition of the current circumstances) of winning or losing the game and divided the spoils accordingly. So if AB has a probability of p of lighting the lighter and has already done so 8 times, the probability that he will then do so 10 times is simply p^2 and the probability that he will lose is (1-p^2). According to this approach, AB wins p^2 of the Cadillac and loses 1- p^2 of his pinky. I think this is close to Jon's suggestion, who strongly felt that since the game hadn't finished AB would have to lose part of his finger in exchange for part of the Cadillac.

Thursday, November 1, 2012

Probability questions from "Man from the South"

The Man from the South (see earlier post) and the American Boy negotiate terms and make a bet: If the American Boy lights his lighter 10 times in a row he gets Man from the South's Cadillac. If the lighter fails to light during one of those 10 attempts Man from the South immediately cuts off American Boy's left pinky, and keeps it.

Think about the following questions in any order. You can make any assumptions, come up with an approximation, an estimate, a minimum or maximum.

Q1. What does American Boy think is the probability of his lighter lighting during any single attempt?

Q2. How many fingers to a Cadillac?

After the eighth successful attempt, Man from the South's wife surprises them and ends the game. She sends American Boy away empty handed.

Q3. How should he have been compensated, if at all?

Q4. Were there to have been a 9th attempt, and were American Boy to have failed in it, what would he have lost?

The Man from the South's wife explains that he has lost eleven cars and taken forty-seven fingers.

Q5. What does Man from the South think is the probability that American Boy's lighter will light during a single attempt?

Q6. How many fingers to a Cadillac does Man from the South figure?

Q7. Do your answers to Q3 and Q4 change?

I don't necessarily have answers to all the questions, but here they are.

Wednesday, October 31, 2012

Probability and "Man from the South"

A few nights ago I read Roald Dahl's "Man from the South", which brings to mind Dahl (surely no relation of Borges' Dahlmann) as a combination of Poe, Borges and O. Henry, and surely no writer of children's books. A RocketFuel colleague, Ari, pointed out a Hitchcock movie based on the story, which I might get around to watching some nice and bright sunny Saturday morning. To tranquilize myself after reading the rather macabre tale at night, I fell to thinking about some rather interesting probability questions based on the events described.

I want to give you the chance to read the story first, and I really hope, post your own questions, before I raise my questions in a blog in a couple of days. Then, a few days later, I'll give my solutions, which, because of possible differing assumptions, may be different from yours. I'll also add the takes of people who talk to me about it.

Yet another RFI colleague, Jack, referred me to a wikipedia article and pointed out that I was not the first to start thinking about probability motivated by games of chance. Late by a whisker again, Jeeves, dash it all!