Premium problem68. Inferring the Bus Population

Medium Locked

Two bus companies serve one route. A company A bus is late with probability p_late_a, a company B bus with probability p_late_b. You watched a late bus and, from that, you believe with probability posterior_a that it was company A.

Return the ratio of A buses to B buses in the population that would justify that belief.

This is Bayes run backwards: you have the posterior and the likelihoods, and you want the prior. Solve

posterior=x⋅pAx⋅pA+(1−x)⋅pB\text{posterior} = \frac{x \cdot p_A}{x \cdot p_A + (1-x)\cdot p_B}

for the fraction xx of A buses, then return x/(1−x)x / (1 - x).

Input

p_late_a = 0.5
p_late_b = 0.1
posterior_a = 0.5

Output

0.20000000000000004

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)