Skip to content

Conversation

@Nepomuk5665
Copy link

Summary

  • Fixes operator precedence bug in BradleyTerryMlePairedCompSubjectiveModel.resolve_model() where n / pp*2 was evaluated as (n/pp)*2 instead of the intended n / pp**2

Problem

In sureal/pc_subjective_model.py line 263, the code reads:

lbda_ij = n / pp*2

Due to Python's operator precedence (division and multiplication have equal precedence and are evaluated left-to-right), this computes (n / pp) * 2, which is incorrect.

The mathematical formula specified in the comment on line 256 states:

# lambda_ij = n_ij / (p_i + p_j)^2, i != j

Line 262 correctly implements this for lbda_ii:

lbda_ii = np.sum(-alpha / np.tile(p, (M, 1)).T**2 + n / pp**2, axis=1)

Fix

Changed line 263 from:

lbda_ij = n / pp*2

to:

lbda_ij = n / pp**2

Impact

This affects the covariance matrix calculation (cova_p, cova_v) and the standard deviation (stdv_p, stdv_v) outputs of the Bradley-Terry MLE model. The quality scores themselves are not affected, only their uncertainty estimates.

Note: The existing tests will need their expected values updated since they were calibrated against the buggy implementation.

In resolve_model(), line 263 used 'n / pp*2' which evaluates as '(n/pp)*2'
due to Python's left-to-right evaluation for operators with same precedence.

The formula comment on line 256 clearly states:
  lambda_ij = n_ij / (p_i + p_j)^2, i != j

And line 262 correctly uses 'pp**2' for the same formula in lbda_ii.

This change fixes lbda_ij to use 'pp**2' (exponentiation) instead of 'pp*2'
(multiplication), matching the mathematical formula specification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant