MCPcopy Create free account
hub / github.com/dblalock/bolt / generate_params_combinations

Function generate_params_combinations

experiments/python/pyience.py:184–237  ·  view source on GitHub ↗

Uses update_func to update each dict based on its values (e.g., to add SVM kernel params if it contains "classifier": "SVM")

(params_list, update_func)

Source from the content-addressed store, hash-verified

182
183
184def generate_params_combinations(params_list, update_func):
185 """Uses update_func to update each dict based on its values (e.g., to
186 add SVM kernel params if it contains "classifier": "SVM")"""
187 if not isinstance(params_list, (list, set, frozenset, tuple)):
188 params_list = [params_list]
189
190 for params in params_list:
191 params[KEY_NEW_KEYS] = set(params.keys())
192
193 if isinstance(update_func, dict):
194 update_func = update_func_from_dict(update_func)
195
196 while True:
197 new_list = []
198 for params in params_list:
199 expanded = expand_params(params)
200 new_list += expanded
201
202 if not update_func:
203 params_list = new_list
204 break
205
206 allFinished = True
207 for params in new_list:
208 # if these params aren't fully updated, update them; keep
209 # track of which keys are added along the way so we can
210 # pass this set to the update function next time
211 if not params.get(KEY_FINISHED_UPDATING, False):
212 # read which keys were added last time and which keys
213 # are currently present
214 new_keys = params[KEY_NEW_KEYS]
215 existing_keys = frozenset(params.keys())
216 params.pop(KEY_NEW_KEYS)
217
218 unfinished = update_func(params, new_keys)
219
220 # compute and store which keys were added this time
221 new_keys = frozenset(params.keys()) - existing_keys
222 params[KEY_NEW_KEYS] = new_keys
223
224 if unfinished:
225 allFinished = False
226 params[KEY_FINISHED_UPDATING] = not unfinished
227
228 params_list = new_list
229
230 if allFinished:
231 break
232
233 for p in params_list:
234 p.pop(KEY_FINISHED_UPDATING)
235 p.pop(KEY_NEW_KEYS)
236
237 return params_list
238
239# ------------------------------------------------ cross validation
240

Callers 1

mainFunction · 0.85

Calls 4

setClass · 0.85
update_func_from_dictFunction · 0.85
expand_paramsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected