Hacky way to recognize some kinds of false dependencies Better would be logic programming.
(hps, conditions)
| 209 | |
| 210 | |
| 211 | def _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 |