Skip to content

Commit 9929fb0

Browse files
committed
Address comments from shuhei, change run_greedy to portfolio_selection
1 parent af8fda6 commit 9929fb0

10 files changed

+87
-27
lines changed

autoPyTorch/api/base_task.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class BaseTask:
121121
exclude_components (Optional[Dict]): If None, all possible components are used.
122122
Otherwise specifies set of components not to use. Incompatible with include
123123
components
124+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
125+
search space updates that can be used to modify the search
126+
space of particular components or choice modules of the pipeline
124127
"""
125128

126129
def __init__(
@@ -702,7 +705,7 @@ def _search(
702705
precision: int = 32,
703706
disable_file_output: List = [],
704707
load_models: bool = True,
705-
run_greedy_portfolio: bool = False
708+
portfolio_selection: str = "none"
706709
) -> 'BaseTask':
707710
"""
708711
Search for the best pipeline configuration for the given dataset.
@@ -773,12 +776,12 @@ def _search(
773776
disable_file_output (Union[bool, List]):
774777
load_models (bool), (default=True): Whether to load the
775778
models after fitting AutoPyTorch.
776-
run_greedy_portfolio (bool), (default=False): If True,
779+
portfolio_selection (str), (default="none"): If "greedy",
777780
runs initial configurations present in
778781
'autoPyTorch/optimizer/greedy_portfolio.json'.
779782
These configurations are the best performing configurations
780783
when search was performed on meta training datasets.
781-
For more info refer to `AutoPyTorch Tabular <https://arxiv.org/abs/2006.13799>
784+
For more info refer to `AutoPyTorch Tabular <https://arxiv.org/abs/2006.13799>`
782785
Returns:
783786
self
784787
@@ -964,7 +967,7 @@ def _search(
964967
# smac does internally
965968
start_num_run=self._backend.get_next_num_run(peek=True),
966969
search_space_updates=self.search_space_updates,
967-
run_greedy_portfolio=run_greedy_portfolio
970+
portfolio_selection=portfolio_selection
968971
)
969972
try:
970973
run_history, self.trajectory, budget_type = \

autoPyTorch/api/tabular_classification.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class TabularClassificationTask(BaseTask):
5757
If None, all possible components are used. Otherwise
5858
specifies set of components not to use. Incompatible
5959
with include components
60+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
61+
search space updates that can be used to modify the search
62+
space of particular components or choice modules of the pipeline
6063
"""
6164
def __init__(
6265
self,
@@ -131,7 +134,7 @@ def search(
131134
precision: int = 32,
132135
disable_file_output: List = [],
133136
load_models: bool = True,
134-
run_greedy_portfolio: bool = False
137+
portfolio_selection: str = "none"
135138
) -> 'BaseTask':
136139
"""
137140
Search for the best pipeline configuration for the given dataset.
@@ -200,12 +203,12 @@ def search(
200203
disable_file_output (Union[bool, List]):
201204
load_models (bool), (default=True): Whether to load the
202205
models after fitting AutoPyTorch.
203-
run_greedy_portfolio (bool), (default=False): If True,
206+
portfolio_selection (str), (default="none"): If "greedy",
204207
runs initial configurations present in
205208
'autoPyTorch/optimizer/greedy_portfolio.json'.
206209
These configurations are the best performing configurations
207210
when search was performed on meta training datasets.
208-
For more info refer to `AutoPyTorch Tabular <https://arxiv.org/abs/2006.13799>
211+
For more info refer to `AutoPyTorch Tabular <https://arxiv.org/abs/2006.13799>`
209212
210213
Returns:
211214
self
@@ -252,7 +255,7 @@ def search(
252255
precision=precision,
253256
disable_file_output=disable_file_output,
254257
load_models=load_models,
255-
run_greedy_portfolio=run_greedy_portfolio
258+
portfolio_selection=portfolio_selection
256259
)
257260

258261
def predict(

autoPyTorch/api/tabular_regression.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class TabularRegressionTask(BaseTask):
4848
exclude_components (Optional[Dict]): If None, all possible components are used.
4949
Otherwise specifies set of components not to use. Incompatible with include
5050
components
51+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
52+
search space updates that can be used to modify the search
53+
space of particular components or choice modules of the pipeline
5154
"""
5255

5356
def __init__(
@@ -123,7 +126,7 @@ def search(
123126
precision: int = 32,
124127
disable_file_output: List = [],
125128
load_models: bool = True,
126-
run_greedy_portfolio: bool = False
129+
portfolio_selection: str = "none"
127130
) -> 'BaseTask':
128131
"""
129132
Search for the best pipeline configuration for the given dataset.
@@ -188,12 +191,12 @@ def search(
188191
disable_file_output (Union[bool, List]):
189192
load_models (bool), (default=True): Whether to load the
190193
models after fitting AutoPyTorch.
191-
run_greedy_portfolio (bool), (default=False): If True,
192-
runs initial configurations present in
193-
'autoPyTorch/optimizer/greedy_portfolio.json'.
194-
These configurations are the best performing configurations
195-
when search was performed on meta training datasets.
196-
For more info refer to `AutoPyTorch Tabular <https://arxiv.org/abs/2006.13799>
194+
portfolio_selection (str), (default="none"): If "greedy",
195+
runs initial configurations present in
196+
'autoPyTorch/optimizer/greedy_portfolio.json'.
197+
These configurations are the best performing configurations
198+
when search was performed on meta training datasets.
199+
For more info refer to `AutoPyTorch Tabular <https://arxiv.org/abs/2006.13799>`
197200
Returns:
198201
self
199202
@@ -239,7 +242,7 @@ def search(
239242
precision=precision,
240243
disable_file_output=disable_file_output,
241244
load_models=load_models,
242-
run_greedy_portfolio=run_greedy_portfolio
245+
portfolio_selection=portfolio_selection
243246
)
244247

245248
def predict(

autoPyTorch/optimizer/smbo.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(self,
109109
ensemble_callback: typing.Optional[EnsembleBuilderManager] = None,
110110
logger_port: typing.Optional[int] = None,
111111
search_space_updates: typing.Optional[HyperparameterSearchSpaceUpdates] = None,
112-
run_greedy_portfolio: bool = False
112+
portfolio_selection: str = "none"
113113
):
114114
"""
115115
Interface to SMAC. This method calls the SMAC optimize method, and allows
@@ -158,7 +158,7 @@ def __init__(self,
158158
Allows to create a user specified SMAC object
159159
ensemble_callback (typing.Optional[EnsembleBuilderManager]):
160160
A callback used in this scenario to start ensemble building subtasks
161-
run_greedy_portfolio (bool), (default=False): If True,
161+
portfolio_selection (str), (default="none"): If "greedy",
162162
runs initial configurations present in
163163
'autoPyTorch/optimizer/greedy_portfolio.json'.
164164
"""
@@ -217,7 +217,8 @@ def __init__(self,
217217
initial_configurations = json.load(open(os.path.join(os.path.dirname(__file__), 'greedy_portfolio.json')))
218218

219219
self.initial_configurations: typing.Optional[typing.List[Configuration]] = None
220-
if run_greedy_portfolio:
220+
assert portfolio_selection in ['none', 'greedy']
221+
if portfolio_selection == "greedy":
221222
self.initial_configurations = list()
222223
for configuration_dict in initial_configurations:
223224
try:

autoPyTorch/pipeline/base_pipeline.py

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class BasePipeline(Pipeline):
4141
random_state (np.random.RandomState): allows to produce reproducible results by
4242
setting a seed for randomized settings
4343
init_params (Optional[Dict[str, Any]])
44+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
45+
search space updates that can be used to modify the search
46+
space of particular components or choice modules of the pipeline
4447
4548
4649
Attributes:

autoPyTorch/pipeline/image_classification.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ class ImageClassificationPipeline(ClassifierMixin, BasePipeline):
4040
Args:
4141
config (Configuration)
4242
The configuration to evaluate.
43-
random_state (Optional[RandomState): random_state is the random number generator
43+
steps (Optional[List[Tuple[str, autoPyTorchChoice]]]): the list of steps that
44+
build the pipeline. If provided, they won't be dynamically produced.
45+
include (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
46+
to honor during the creation of the configuration space.
47+
exclude (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
48+
to avoid during the creation of the configuration space.
49+
random_state (np.random.RandomState): allows to produce reproducible results by
50+
setting a seed for randomized settings
51+
init_params (Optional[Dict[str, Any]])
52+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
53+
search space updates that can be used to modify the search
54+
space of particular components or choice modules of the pipeline
4455
4556
Attributes:
4657
Examples

autoPyTorch/pipeline/tabular_classification.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,18 @@ class TabularClassificationPipeline(ClassifierMixin, BasePipeline):
6060
Args:
6161
config (Configuration)
6262
The configuration to evaluate.
63-
random_state (Optional[RandomState): random_state is the random number generator
63+
steps (Optional[List[Tuple[str, autoPyTorchChoice]]]): the list of steps that
64+
build the pipeline. If provided, they won't be dynamically produced.
65+
include (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
66+
to honor during the creation of the configuration space.
67+
exclude (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
68+
to avoid during the creation of the configuration space.
69+
random_state (np.random.RandomState): allows to produce reproducible results by
70+
setting a seed for randomized settings
71+
init_params (Optional[Dict[str, Any]])
72+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
73+
search space updates that can be used to modify the search
74+
space of particular components or choice modules of the pipeline
6475
6576
Attributes:
6677
Examples

autoPyTorch/pipeline/tabular_regression.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,18 @@ class TabularRegressionPipeline(RegressorMixin, BasePipeline):
5858
Args:
5959
config (Configuration)
6060
The configuration to evaluate.
61-
random_state (Optional[RandomState): random_state is the random number generator
61+
steps (Optional[List[Tuple[str, autoPyTorchChoice]]]): the list of steps that
62+
build the pipeline. If provided, they won't be dynamically produced.
63+
include (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
64+
to honor during the creation of the configuration space.
65+
exclude (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
66+
to avoid during the creation of the configuration space.
67+
random_state (np.random.RandomState): allows to produce reproducible results by
68+
setting a seed for randomized settings
69+
init_params (Optional[Dict[str, Any]])
70+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
71+
search space updates that can be used to modify the search
72+
space of particular components or choice modules of the pipeline
6273
6374
Attributes:
6475
Examples

autoPyTorch/pipeline/traditional_tabular_classification.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from autoPyTorch.pipeline.base_pipeline import BasePipeline
1111
from autoPyTorch.pipeline.components.base_choice import autoPyTorchChoice
1212
from autoPyTorch.pipeline.components.setup.traditional_ml.base_model_choice import ModelChoice
13+
from autoPyTorch.utils.hyperparameter_search_space_update import HyperparameterSearchSpaceUpdates
1314

1415

1516
class TraditionalTabularClassificationPipeline(ClassifierMixin, BasePipeline):
@@ -19,7 +20,19 @@ class TraditionalTabularClassificationPipeline(ClassifierMixin, BasePipeline):
1920
Args:
2021
config (Configuration)
2122
The configuration to evaluate.
22-
random_state (Optional[RandomState): random_state is the random number generator
23+
steps (Optional[List[Tuple[str, autoPyTorchChoice]]]): the list of steps that
24+
build the pipeline. If provided, they won't be dynamically produced.
25+
include (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
26+
to honor during the creation of the configuration space.
27+
exclude (Optional[Dict[str, Any]]): Allows the caller to specify which configurations
28+
to avoid during the creation of the configuration space.
29+
random_state (np.random.RandomState): allows to produce reproducible results by
30+
setting a seed for randomized settings
31+
init_params (Optional[Dict[str, Any]])
32+
search_space_updates (Optional[HyperparameterSearchSpaceUpdates]):
33+
search space updates that can be used to modify the search
34+
space of particular components or choice modules of the pipeline
35+
2336
2437
Attributes:
2538
"""
@@ -32,11 +45,12 @@ def __init__(
3245
include: Optional[Dict[str, Any]] = None,
3346
exclude: Optional[Dict[str, Any]] = None,
3447
random_state: Optional[np.random.RandomState] = None,
35-
init_params: Optional[Dict[str, Any]] = None
48+
init_params: Optional[Dict[str, Any]] = None,
49+
search_space_updates: Optional[HyperparameterSearchSpaceUpdates] = None
3650
):
3751
super().__init__(
3852
config, steps, dataset_properties, include, exclude,
39-
random_state, init_params)
53+
random_state, init_params, search_space_updates)
4054

4155
def predict(self, X: np.ndarray, batch_size: Optional[int] = None
4256
) -> np.ndarray:

examples/tabular/40_advanced/example_run_with_portfolio.py renamed to examples/40_advanced/example_run_with_portfolio.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
optimize_metric='accuracy',
5555
total_walltime_limit=300,
5656
func_eval_time_limit_secs=50,
57-
# Setting this option to True
57+
# Setting this option to "greedy"
5858
# will make smac run the configurations
5959
# present in 'autoPyTorch/optimizer/greedy_portfolio.json'
60-
run_greedy_portfolio=True
60+
portfolio_selection="greedy"
6161
)
6262

6363
############################################################################

0 commit comments

Comments
 (0)