Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

[ff-2388] get_bandit_actions: supply actions as a dict instead of list#53

Merged
schmit merged 6 commits intomainfrom
ff-2388/switch-to-dict
Jun 10, 2024
Merged

[ff-2388] get_bandit_actions: supply actions as a dict instead of list#53
schmit merged 6 commits intomainfrom
ff-2388/switch-to-dict

Conversation

@schmit
Copy link

@schmit schmit commented Jun 10, 2024

Fixes: #ff-2388

Motivation and Context

Currently actions are supplied as a list, which does not guarantee that the action keys are unique. To ensure uniqueness, require a dictionary mapping actions to their contexts instead

Description

  • Change interface to use Dict instead of List
  • Update bandit.py to use dicts for computation instead of lists
  • Update tests to supply Dicts instead of Lists
  • Minor version bump

How has this been tested?

All tests pass

optimality_gap = (
max(score for _, score in action_scores) - action_scores[selected_idx][1]
)
optimality_gap = max(action_scores.values()) - action_scores[selected_action]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet bonus refactor!

Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📈 Love it!

subject_key: str,
subject_attributes: Attributes,
actions_with_contexts: List[ActionContext],
actions: ActionContexts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still keep this namedactions_with_contexts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about it -- given that we expect a dictionary now, I think it's more obvious that we need extra information to go with the key

@@ -1 +1 @@
__version__ = "3.1.4"
__version__ = "3.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this interface change is a non-backward compatible breaking change, but fine doing the 3.2 thing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup my thought exactly

assert pytest.approx(evaluation.action_weight, rel=1e-2) == 0.4926


def test_bandit_no_action_contexts():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

flag_key,
subject_key,
subject_attributes,
{"action1": Attributes.empty(), "action2": Attributes.empty()},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@schmit schmit merged commit d7a4a69 into main Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants