Skip to content

Align get_treatment_costs columns with the conditions it returns - #1065

Open
arpitjain099 wants to merge 1 commit into
uber:masterfrom
arpitjain099:fix/treatment-cost-column-order
Open

arpitjain099 wants to merge 1 commit into
uber:masterfrom
arpitjain099:fix/treatment-cost-column-order

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

get_treatment_costs returns the cost arrays and a sorted conditions list from one call, and get_actual_value and CounterfactualValueEstimator both read column j as the cost of conditions[j]. The columns were filled in cc_dict iteration order, so that alignment only held when the dict was already written in the same order.

Writing the same costs in a different order rotates them:

{"control": 0.0, "treatment1": 2.0, "treatment2": 7.0}  ->  [100.0, 98.0, 93.0]
{"treatment1": 2.0, "treatment2": 7.0, "control": 0.0}  ->  [ 98.0, 93.0, 100.0]

The first row is the right answer in both cases, since a control unit should pay nothing. The columns now follow conditions_sorted, so the width is len(conditions) as documented rather than len(cc_dict), and an arm with no declared cost raises KeyError instead of returning a short array.

One test added to tests/test_value_optimization.py; it fails on master with the second row above. The existing test passes either way, since its dict is already control-first.

The cost arrays and the conditions list are returned from one call, and
get_actual_value and CounterfactualValueEstimator both read column j as the
cost of conditions[j]. Filling the columns in cc_dict iteration order made
that alignment depend on how the caller happened to write the dict, so the
same costs in a different key order charged each unit a different arm's cost.

Build the columns from conditions_sorted instead, which also gives the array
the documented width of len(conditions).

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