PIXELBANKv9.1.0
Menu

Bradley-Terry Preference Probability

Compute the Bradley-Terry preference probability.

The Bradley-Terry model gives the probability that response A is preferred over response B: P(A>B)=erAerA+erB=σ(rA−rB)P(A > B) = \frac{e^{r_A}}{e^{r_A} + e^{r_B}} = \sigma(r_A - r_B)

where σ is the sigmoid function and r_A, r_B are reward scores.

Input: r_A r_B (two floats) Output: P(A > B), rounded to 4 decimal places.

Example:

Input:
2.0 1.0
Output:
0.7311
Reasoning:
  • The input values are rA=2.0r_A = 2.0 and rB=1.0r_B = 1.0, representing the reward scores.
  • We calculate the probability P(A>B)P(A > B) using the Bradley-Terry model: P(A>B)=erAerA+erB=e2.0e2.0+e1.0P(A > B) = \frac{e^{r_A}}{e^{r_A} + e^{r_B}} = \frac{e^{2.0}}{e^{2.0} + e^{1.0}}.
  • Substituting the values, we get: P(A>B)=e2.0e2.0+e1.0=7.3897.389+2.718=7.38910.107P(A > B) = \frac{e^{2.0}}{e^{2.0} + e^{1.0}} = \frac{7.389}{7.389 + 2.718} = \frac{7.389}{10.107}.
  • The final probability is calculated as: P(A>B)=7.38910.107≈0.7311P(A > B) = \frac{7.389}{10.107} \approx 0.7311 when rounded to 4 decimal places.

Constraints:

  • -100 <= r_A, r_B <= 100
  • Use numerically stable sigmoid
  • Round to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.