Skip to content

Fix CounterfactualUnitSelector.predict crash when sigma is exactly zero - #1066

Open
arpitjain099 wants to merge 1 commit into
uber:masterfrom
arpitjain099:fix/unit-selection-zero-sigma
Open

arpitjain099 wants to merge 1 commit into
uber:masterfrom
arpitjain099:fix/unit-selection-zero-sigma

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

CounterfactualUnitSelector.predict() raises UnboundLocalError on plain two-decimal payoffs. _gain_equality_check compares complier + defier against alwaystaker + nevertaker, while _obj_func_midp computes sigma = beta - gamma - theta + delta. Float addition is not associative, so with payoffs 1.30, 7.93, 2.63 and 9.26, 1.30 + 9.26 is 10.56 and 7.93 + 2.63 is 10.559999999999999. The check sends predict() down the bounds path, where sigma is exactly 0.0 and neither branch assigns a bound.

So elif sigma > 0: becomes else:. At sigma zero all eight p expressions reduce to one value, so either orientation gives the same midpoint; over 20000 draws constrained to that case the largest gap was 7.1e-15. The test added here fails on master.

_gain_equality_check tests (complier + defier) == (alwaystaker + nevertaker) while _obj_func_midp computes sigma = beta - gamma - theta + delta. Float addition is not associative, so the two disagree and predict() can reach the bounds path with sigma exactly 0.0, where neither branch assigned a bound. At sigma zero all eight p expressions reduce to one value, so both orientations return the same midpoint.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>

This branch has not been deployed

No deployments
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