Skip to content

Commit

Permalink
Merge pull request #572 from autonomio/allow_paramspace_as_params
Browse files Browse the repository at this point in the history
Scan allows ParamSpace as input
  • Loading branch information
mikkokotila committed Apr 3, 2022
2 parents a747a45 + c4251c1 commit b11c5db
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/Scan.md
Expand Up @@ -17,7 +17,7 @@ Argument | Input | Description
--------- | ------- | -----------
`x` | array or list of arrays | prediction features
`y` | array or list of arrays | prediction outcome variable
`params` | dict | the parameter dictionary
`params` | dict or ParamSpace object | the parameter dictionary or the ParamSpace object after splitting
`model` | function | the Keras model as a function
`experiment_name` | str | Used for creating the experiment logging folder
`x_val` | array or list of arrays | validation data for x
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -18,7 +18,7 @@
URL = 'http://autonom.io'
LICENSE = 'MIT'
DOWNLOAD_URL = 'https://github.com/autonomio/talos/'
VERSION = '1.1.0'
VERSION = '1.1.1'


try:
Expand Down
4 changes: 4 additions & 0 deletions talos/parameters/DistributeParamSpace.py
Expand Up @@ -16,6 +16,10 @@ def __init__(self,
params | object | ParamSpace class object
machines | int | number of machines to split for
NOTE: `Scan()` limits will not be applied if ParamSpace object
is passed directly into `Scan()` as `params` argument so they
should be passed directly into `DistributeParamSpace` instead.
'''

from talos.parameters.ParamSpace import ParamSpace
Expand Down
37 changes: 24 additions & 13 deletions talos/scan/scan_prepare.py
Expand Up @@ -16,19 +16,30 @@ def scan_prepare(self):
elif self.x_val is not None and self.y_val is not None:
self.custom_val_split = True

# create reference for parameter keys
self._param_dict_keys = sorted(list(self.params.keys()))

# create the parameter object and move to self
from ..parameters.ParamSpace import ParamSpace
self.param_object = ParamSpace(params=self.params,
param_keys=self._param_dict_keys,
random_method=self.random_method,
fraction_limit=self.fraction_limit,
round_limit=self.round_limit,
time_limit=self.time_limit,
boolean_limit=self.boolean_limit
)
# handle the case where self.params is dictionary
if isinstance(self.params, dict):

# create reference for parameter keys
self._param_dict_keys = sorted(list(self.params.keys()))

# create the parameter object and move to self
from ..parameters.ParamSpace import ParamSpace
self.param_object = ParamSpace(params=self.params,
param_keys=self._param_dict_keys,
random_method=self.random_method,
fraction_limit=self.fraction_limit,
round_limit=self.round_limit,
time_limit=self.time_limit,
boolean_limit=self.boolean_limit)

# handle the case when self.params already is ParamSpace object
elif 'talos.parameters.ParamSpace.ParamSpace' in str(type(self.params)):

self._param_dict_keys = sorted(list(self.params.param_keys))
self.param_object = self.params

else:
raise TypeError('params has to be either dict or ParamSpace object.')

# mark that it's a first round
self.first_round = True
Expand Down
15 changes: 14 additions & 1 deletion tests/commands/test_latest.py
Expand Up @@ -24,7 +24,9 @@ def test_latest():

from talos.parameters.DistributeParamSpace import DistributeParamSpace

_ = DistributeParamSpace(params=p, param_keys=p.keys(), machines=5)
param_spaces = DistributeParamSpace(params=p,
param_keys=p.keys(),
machines=100)

def iris_model(x_train, y_train, x_val, y_val, params):

Expand All @@ -49,6 +51,17 @@ def iris_model(x_train, y_train, x_val, y_val, params):

return out, model

print(type(param_spaces.param_spaces[0]))

scan_object = talos.Scan(x,
y,
model=iris_model,
params=param_spaces.param_spaces[0],
experiment_name='test_latest',
round_limit=5,
reduction_method='gamify',
save_weights=False)

scan_object = talos.Scan(x, y,
model=iris_model,
params=p,
Expand Down

0 comments on commit b11c5db

Please sign in to comment.