find_p

tennis_probability.find_p(probability: float, accuracy_threshold: float) float

This functions finds the p value from the probability of winning a game.

This p value is later used for all other functions to calculate the probability of winning. This is calculated using binary search. This assumes that the probability passed in is the probability of winning the entire match, with 0 points played.

Parameters:
  • probability – The probability of player A winning the entire match.

  • accuracy_threshold – The threshold of when to stop looking for the p value. Looks for the p value while high - low > accuracy_threshold. For example, a threshold of 0.001 would make sure that three first three digits of the p value is correct, meaning that if the p value is 0.51, it would get 0.510 and then an arbitrary amount of follow up numbers. After running this once with a threshold of 0.001 and a p value of 0.51, the function returned 0.51025390625.

Raises:

InvalidProbability – When the probability is invalid.

Returns:

A p value that is within accuracy_threshold of the real midpoint. If the search stops due to the threshold being reached, the mid is returned. In other words, the average of the high and low of the binary search is returned.