MCPcopy
hub / github.com/hyperopt/hyperopt / _remove_allpaths

Function _remove_allpaths

hyperopt/pyll_utils.py:211–247  ·  view source on GitHub ↗

Hacky way to recognize some kinds of false dependencies Better would be logic programming.

(hps, conditions)

Source from the content-addressed store, hash-verified

209
210
211def _remove_allpaths(hps, conditions):
212 """Hacky way to recognize some kinds of false dependencies
213 Better would be logic programming.
214 """
215 potential_conds = {}
216 for k, v in list(hps.items()):
217 if v["node"].name == "randint":
218 low = v["node"].arg["low"].obj
219 # if high is None, the domain is [0, low), else it is [low, high)
220 domain_size = (
221 v["node"].arg["high"].obj - low
222 if v["node"].arg["high"] != MissingArgument
223 else low
224 )
225 potential_conds[k] = frozenset([EQ(k, ii) for ii in range(domain_size)])
226 elif v["node"].name == "categorical":
227 p = v["node"].arg["p"].obj
228 potential_conds[k] = frozenset([EQ(k, ii) for ii in range(p.size)])
229
230 for k, v in list(hps.items()):
231 if len(v["conditions"]) > 1:
232 all_conds = [[c for c in cond if c is not True] for cond in v["conditions"]]
233 all_conds = [cond for cond in all_conds if len(cond) >= 1]
234 if len(all_conds) == 0:
235 v["conditions"] = {conditions}
236 continue
237
238 depvar = all_conds[0][0].name
239
240 all_one_var = all(
241 len(cond) == 1 and cond[0].name == depvar for cond in all_conds
242 )
243 if all_one_var:
244 conds = [cond[0] for cond in all_conds]
245 if frozenset(conds) == potential_conds[depvar]:
246 v["conditions"] = {conditions}
247 continue
248
249
250# -- eof

Callers 1

expr_to_configFunction · 0.85

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected