Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor MAB and Strategy Classes with Cold Start Methods and Enhanced Validation #35

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

shaharbar1
Copy link
Collaborator

Refactor MAB and Strategy Classes with Cold Start Methods and Enhanced Validation

Change log:

  1. Moved Strategy, Model, and MAB to strategy.py, model.py, and to the new mab.py. base.py is now only for definitions and abstract PyBanditsBaseModel.
  2. Introduced TailoredBaseMab as a child of BaseMab. The new abstract MAB should hold any common functionality for all MABs that are tailored for a specific strategy. Consequently, all MABs except for BaseMab are now inheriting from the new class.
  3. The from_state functionality is now directly inherited by all MABs from BaseMab.
  4. Replaced all cold_start methods in cmab.py and smab.py with cold_start_instantiate stemming from TailoredBaseMab. Correspondingly, updated test cases to use the new cold_start_instantiate methods.
  5. Introduced numerize_field and get_expected_value_from_state methods in the Strategy class to handle default values and state extraction. Added field_validator for exploit_p in BestActionIdentification and subsidy_factor in CostControlBandit to ensure proper default handling and validation.
  6. Merged common functionality into a new CostControlStrategy abstract class, which is now inherited by CostControlBandit and MultiObjectiveCostControlBandit. Simplified the select_action methods by using helper methods like _evaluate_and_select and _reduce.
  7. Plugged get_pareto_front into a new MultiObjectiveStrategy abstract class, which is now inherited by MultiObjectiveBandit and MultiObjectiveCostControlBandit.
  8. In model.py. Removed the redundant BaseBetaMO and BaseBayesianLogisticRegression. Added cold_start_instantiate method to BetaMO and BayesianLogisticRegression models.
  9. Added extract_argument_names_from_function under utils.py to allow extract function parameter names by handle.
  10. Changed tes_base.py into test_mab.py.
  11. Updated deprecated linter settings in pyproject.toml.

@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 2 times, most recently from 0748967 to 29723e1 Compare August 12, 2024 08:26
Copy link
Collaborator

@adarmiento adarmiento left a comment

Choose a reason for hiding this comment

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

This set of changes are breaking, so should also include a version increase in the tomlfile :)

Some comments (for nitpicking) are written only for the first instance for some repeating events

pybandits/cmab.py Outdated Show resolved Hide resolved
pybandits/mab.py Show resolved Hide resolved
pybandits/mab.py Outdated Show resolved Hide resolved
pybandits/mab.py Show resolved Hide resolved
pybandits/mab.py Show resolved Hide resolved
pybandits/strategy.py Outdated Show resolved Hide resolved
pybandits/strategy.py Outdated Show resolved Hide resolved
pybandits/strategy.py Show resolved Hide resolved
pybandits/strategy.py Outdated Show resolved Hide resolved
pybandits/strategy.py Outdated Show resolved Hide resolved
@shaharbar1
Copy link
Collaborator Author

@adarmiento Thank you for the thorough inspection of the code! Much appreciated!

@shaharbar1
Copy link
Collaborator Author

This set of changes are breaking, so should also include a version increase in the tomlfile :)

Some comments (for nitpicking) are written only for the first instance for some repeating events

We will release a major version after this PR is merged 🙏

@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 7 times, most recently from fb27dcf to 61a8c49 Compare August 22, 2024 08:05
@shaharbar1 shaharbar1 added the enhancement New feature or request label Sep 4, 2024
pybandits/utils.py Outdated Show resolved Hide resolved
@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 5 times, most recently from aa4ff23 to 073821c Compare September 5, 2024 19:53
pybandits/strategy.py Outdated Show resolved Hide resolved
@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 2 times, most recently from ed27032 to da916fa Compare September 8, 2024 07:41
@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 3 times, most recently from 847158b to 9404315 Compare September 25, 2024 07:11
@shaharbar1 shaharbar1 enabled auto-merge (squash) September 25, 2024 07:19
@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 6 times, most recently from f092097 to bd08425 Compare September 25, 2024 09:33
pybandits/consts.py Outdated Show resolved Hide resolved
pybandits/mab.py Outdated Show resolved Hide resolved
pybandits/mab.py Outdated Show resolved Hide resolved
actions: Dict[ActionId, Model],
epsilon: Optional[Float01] = None,
default_action: Optional[ActionId] = None,
**strategy_kwargs,
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add docstring

@@ -73,32 +118,44 @@ class BestActionIdentification(Strategy):

Parameters
----------
exploit_p: Float_0_1 (default=0.5)
exploit_p: Optional[Float01], 0.5 if not specified
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's call this class BestActionIdentificationBandit to keep it homogeneous with the others

@shaharbar1 shaharbar1 force-pushed the feature/mab_refactor branch 4 times, most recently from ed5a5a2 to eb3dbef Compare September 26, 2024 08:36
…d Validation

 Change log:
 1. Moved Strategy, Model, and MAB to strategy.py, model.py, and to the new mab.py. base.py is now only for definitions and abstract PyBanditsBaseModel. The abstract MAB now allows for all childs to either accept strategy instance as parameter, or to get the strategy parameters and instantiate correspondingly.
 2. The from_state functionality is now directly inherited by all MABs from BaseMab.
 3. Replaced all cold_start methods in cmab.py and smab.py with cold_start stemming from BaseMab. Correspondingly, updated test cases to use the new cold_start_instantiate methods.
 4. Introduced numerize_field and get_expected_value_from_state methods in the Strategy class to handle default values and state extraction. Added field_validator for exploit_p in BestActionIdentification and subsidy_factor in CostControlBandit to ensure proper default handling and validation.
 5. Merged common functionality into a new CostControlStrategy abstract class, which is now inherited by CostControlBandit and MultiObjectiveCostControlBandit. Simplified the select_action methods by using helper methods like _evaluate_and_select and _reduce.
 6. Plugged get_pareto_front into a new MultiObjectiveStrategy abstract class, which is now inherited by MultiObjectiveBandit and MultiObjectiveCostControlBandit.
 7. In model.py. Removed the redundant BaseBetaMO and BaseBayesianLogisticRegression. Added cold_start_instantiate method to BetaMO and BayesianLogisticRegression models.
 8. Added extract_argument_names_from_function under utils.py to allow extract function parameter names by handle.
 9. Changed test_base.py into test_mab.py.
 10. Updated deprecated linter settings in pyproject.toml.
 11. Added test_smab_mo_cc_update test on test_smab.py.
 12. Changed version to 1.0.0 on pyproject.toml.
Copy link
Collaborator

@dariodandrea dariodandrea left a comment

Choose a reason for hiding this comment

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

Very good changes in the library @Shahar-Bar !

@shaharbar1 shaharbar1 merged commit cddda5c into develop Sep 26, 2024
4 checks passed
@shaharbar1 shaharbar1 deleted the feature/mab_refactor branch September 26, 2024 08:41
shaharbar1 added a commit that referenced this pull request Sep 26, 2024
…d Validation (#63)

Refactor MAB and Strategy Classes with Cold Start Methods and Enhanced Validation (#35)

### Changes
 * Moved Strategy, Model, and MAB to strategy.py, model.py, and to the new mab.py. base.py is now only for definitions and abstract PyBanditsBaseModel. The abstract MAB now allows for all childs to either accept strategy instance as parameter, or to get the strategy parameters and instantiate correspondingly.
 * The from_state functionality is now directly inherited by all MABs from BaseMab.
 * Replaced all cold_start methods in cmab.py and smab.py with cold_start stemming from BaseMab. Correspondingly, updated test cases to use the new cold_start_instantiate methods.
 * Introduced numerize_field and get_expected_value_from_state methods in the Strategy class to handle default values and state extraction. Added field_validator for exploit_p in BestActionIdentification and subsidy_factor in CostControlBandit to ensure proper default handling and validation.
 * Merged common functionality into a new CostControlStrategy abstract class, which is now inherited by CostControlBandit and MultiObjectiveCostControlBandit. Simplified the select_action methods by using helper methods like _evaluate_and_select and _reduce.
 * Plugged get_pareto_front into a new MultiObjectiveStrategy abstract class, which is now inherited by MultiObjectiveBandit and MultiObjectiveCostControlBandit.
 * In model.py. Removed the redundant BaseBetaMO and BaseBayesianLogisticRegression. Added cold_start_instantiate method to BetaMO and BayesianLogisticRegression models.
 * Added extract_argument_names_from_function under utils.py to allow extract function parameter names by handle.
 * Changed test_base.py into test_mab.py.
 * Updated deprecated linter settings in pyproject.toml.
 * Added test_smab_mo_cc_update test on test_smab.py.
 * Changed version to 1.0.0 on pyproject.toml.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants