modrover.strategies#
- class modrover.strategies.base.Strategy(num_covs)[source]#
Bases:
ABC
An abstract base class representing a valid Rover strategy.
The strategy is responsible for selecting the next set of LearnerIDs, determining the next layer of individual learners that Rover will fit. Fitting learners and storing results is managed by Rover itself.
- Parameters:
num_covs (int) – Number of exploring covaraites.
- abstract property base_learner_id: tuple[int, ...]#
Starting learner id of the strategy
- abstract get_next_layer(curr_layer, learners, **kwargs)[source]#
Abstract method to generate the next set of learner ids.
- Parameters:
curr_layer (set[tuple[int, ...]]) – Current explored set of learner ids.
learners (dict[tuple[int, ...], modrover.learner.Learner]) – A dictionary contains all fitted learners.
**kwargs – Other key word arguments.
- Return type:
set[tuple[int, …]]
- class modrover.strategies.full.Full(num_covs)[source]#
Bases:
Strategy
Full strategy explore every possible covariate combinations.
- Parameters:
num_covs (int) – Number of exploring covaraites.
- property base_learner_id: tuple[int, ...]#
Starting learner id of the strategy
- property first_layer: set[tuple[int, ...]]#
Leanrer ids corresponding to the first layer.
- property second_layer: set[tuple[int, ...]]#
Leanrer ids corresponding to the second layer.
- get_next_layer(curr_layer, learners)[source]#
Find every single possible learner ID combination, return in a single layer. If the
curr_layer=first_layer
, it will return thesecond_layer
and if thecurr_layer=second_layer
, it will return an empty layer. The first layer and the second layer together cover all possible combinations.- Parameters:
curr_layer (set[tuple[int, ...]]) – Current explored set of learner ids.
learners (dict[tuple[int, ...], modrover.learner.Learner]) – A dictionary contains all fitted learners.
- Return type:
set[tuple[int, …]]
- class modrover.strategies.forward.Forward(num_covs)[source]#
Bases:
Strategy
Forward strategy starts from the model with only the
cov_fixed
and explores forwards with more and more covariates base on the learner performance.- Parameters:
num_covs (int) – Number of exploring covaraites.
- property base_learner_id: tuple[int, ...]#
Starting learner id of the strategy
- get_next_layer(curr_layer, learners, min_improvement=1.0, max_len=1)[source]#
The forward strategy will select a set of learner IDs numbering one more than the current. This function will return next set of learner ids corresponding the learers that need to be fitted.
E.g. if the full set of ids is 1-5, and our current is (0, 1)
The children will be (0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 1, 5)
- Parameters:
curr_layer (set[tuple[int, ...]]) – Current explored set of learner ids.
learners (dict[tuple[int, ...], modrover.learner.Learner]) – A dictionary contains all fitted learners.
min_improvement (float) – Minimum performance improvement requirement for the learner to be consider qualified to generate the next layer.
max_len (int) – Maximum number of learner in each layer.
- Return type:
set[tuple[int, …]]
- class modrover.strategies.backward.Backward(num_covs)[source]#
Bases:
Strategy
Backward strategy starts from the model with all the covariates that we want to explore and explores backward with less and less covaraites base on the learner performance.
- Parameters:
num_covs (int) – Number of exploring covaraites.
- property base_learner_id: tuple[int, ...]#
Starting learner id of the strategy
- get_next_layer(curr_layer, learners, min_improvement=1.0, max_len=1)[source]#
The backward strategy will select a set of learner IDs numbering one less. This function will return next set of learner ids corresponding the learers that need to be fitted.
E.g. if the full set of ids is 1-5, and our current is (0, 1, 2)
The downstreams will be (0, 1), (0, 2)
- Parameters:
curr_layer (set[tuple[int, ...]]) – Current explored set of learner ids.
learners (dict[tuple[int, ...], modrover.learner.Learner]) – A dictionary contains all fitted learners.
min_improvement (float) – Minimum performance improvement requirement for the learner to be consider qualified to generate the next layer.
max_len (int) – Maximum number of learner in each layer.
- Return type:
set[tuple[int, …]]