Assume that there is a bernoulli distribution whose probability is unknown to us and may occasionally change.
What we have on hand are non-uniformly sample results (0/1) with timestamp information.
What should we do to visualize the changing probability overtime?

The actual data I'm handling are pull results of a gasha game. The probability we focus on are expected to be at the scale of about 0.1%~1%, and the probability change event are relatively rare (with 10k~50k samples in between)
Also, it would be helpful if the solution could extend to discrete distribution with more than 2 results, so that I may visualize the probability of all pull results at once, instead of drawing one figure for each result.


1 Answer 1


Cumulatively, the probability of getting the rare pull will increase over time. This probability will also get very close to 1 (100%) after sufficient pulls. 0.1%–1% would mean that, on average, 100–1000 pulls are required to get the rare pull.

Considering that the probability change happens only once and after a fixed number of samples $k$, then the pulls are continued for $n-k$ where $n$ is the number of pulls done. Whenever a rare pull is obtained, the targeted number of rare pulls cumulatively increases by 1, which is $m-1$ where m is the new target. Therefore, the probability function $P(X = m)$ can be written as follows:

$$P(X = m) = \binom n m (1 - p)^{n - m} p ^ m$$

Accounting for the probability change, the equation derived from the law of total probability becomes the following:

$$P(X = m) = \sum^m_{i = 0} P(X = i) P(X' = m - i) $$ $$P(X = i) = \binom k i (1 - p)^{k - i} p ^ i $$

With this part denoting the probability function after the probability change:

$$P(X' = m - i) = \binom {n - k}{m - i} p' ^ m - i(1 - p')^{n - k + i} $$

With the equations above, the final function looks like this:

$$P(X = m) = \sum^m_{i = 0} \binom k i (1 - p)^{k - i} p ^ i \binom {n - k}{m - i} p' ^ m - i(1 - p')^{n - k + i} $$

Once you have your function written in code, you can make it accept more parameters so that your probability is different for different targets, possibly in subplots, depending on the class provided in another variable. One point per timestamp should always use $m - 1$ if the sample results are 0 and plot $m$ when the sample result is 1.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.