def _to_param_meta(param_grid, control):
'''Acquire parameter metadata such as bounds that are useful for sampling'''
choice_params = {k: v for k, v in param_grid.items()
if not hasattr(v, 'rvs')}
distributions = {k: v for k, v in param_grid.items()
if k not in choice_params}
pg_list = list(ParameterGrid(choice_params))
choices, low, high, param_order, is_int = [], [], [], [], []
is_continuous = lambda v: isinstance(v, numbers.Real)
while len(pg_list):
pg2 = pg_list.pop(0)
for k, v in pg2.items():
if k in param_order:
idx = param_order.index(k)
else:
idx = len(param_order)
param_order.append(k)
low.append(v)
high.append(v)
choices.append([v])
is_int.append(not is_continuous(v))
continue
if v not in choices[idx]:
choices[idx].append(v)
if is_continuous(v):
is_int[idx] = False
if v < low[idx]:
low[idx] = v
if v > high[idx]:
high[idx] = v
else:
is_int[idx] = True
low[idx] = high[idx] = v
for k, v in distributions.items():
choices.append(v)
low.append(None)
high.append(None)
is_int.append(False)
param_order.append(k)
param_meta = dict(control=control, high=high, low=low,
choices=choices, is_int=is_int,
param_order=param_order)
return param_meta
评论列表
文章目录