コード例 #1
0
ファイル: test_smac_hdl.py プロジェクト: chengdake/autoflow
 def test_encode(self):
     before = {"name": ["tqc", "dsy"], "type": {(1, 2): {1, 2, 3}}}
     encoded = smac_hdl._encode(before)
     logging.info(encoded)
     after = smac_hdl._decode(encoded)
     logging.info(after)
     self.assertEqual(before, after)
コード例 #2
0
 def __parse_dict_to_config(self, key, value):
     if isinstance(value, dict):
         _type = value.get("_type")
         _value = value.get("_value")
         _default = value.get("_default")
         assert _value is not None
         if _type == "choice":
             return smac_hdl.choice(key, _value, _default)
         else:
             return eval(
                 f'''smac_hdl.{_type}("{key}",*_value,default=_default)''')
     else:
         return Constant(key, smac_hdl._encode(value))
コード例 #3
0
 def __condition(self, item: Dict, store: Dict):
     child = item["_child"]
     child = store[child]
     parent = item["_parent"]
     parent = store[parent]
     value = (item["_values"])
     if (isinstance(value, list) and len(value) == 1):
         value = value[0]
     if isinstance(value, list):
         cond = InCondition(child, parent, list(map(smac_hdl._encode,
                                                    value)))
     else:
         cond = EqualsCondition(child, parent, smac_hdl._encode(value))
     return cond
コード例 #4
0
 def __condition(self, item: Dict, store: Dict, leader_model):
     child = add_leader_model(item["_child"], leader_model,
                              SERIES_CONNECT_LEADER_TOKEN)
     child = store[child]
     parent = add_leader_model(item["_parent"], leader_model,
                               SERIES_CONNECT_LEADER_TOKEN)
     parent = store[parent]
     value = (item["_values"])
     if (isinstance(value, list) and len(value) == 1):
         value = value[0]
     if isinstance(value, list):
         cond = InCondition(child, parent, list(map(smac_hdl._encode,
                                                    value)))
     else:
         cond = EqualsCondition(child, parent, smac_hdl._encode(value))
     return cond
コード例 #5
0
 def __forbidden(self, value: List, store: Dict, cs: ConfigurationSpace):
     assert isinstance(value, list)
     for item in value:
         assert isinstance(item, dict)
         clauses = []
         for k, v in item.items():
             if isinstance(v, list) and len(v) == 1:
                 v = v[0]
             if isinstance(v, list):
                 clauses.append(
                     ForbiddenInClause(store[k],
                                       list(map(smac_hdl._encode, v))))
             else:
                 clauses.append(
                     ForbiddenEqualsClause(store[k], smac_hdl._encode(v)))
         cs.add_forbidden_clause(ForbiddenAndConjunction(*clauses))
コード例 #6
0
 def __forbidden(self, value: List, store: Dict, cs: ConfigurationSpace,
                 leader_model):
     assert isinstance(value, list)
     for item in value:
         assert isinstance(item, dict)
         clauses = []
         for name, forbidden_values in item.items():
             true_name = add_leader_model(name, leader_model,
                                          SERIES_CONNECT_LEADER_TOKEN)
             if isinstance(forbidden_values,
                           list) and len(forbidden_values) == 1:
                 forbidden_values = forbidden_values[0]
             if isinstance(forbidden_values, list):
                 clauses.append(
                     ForbiddenInClause(
                         store[true_name],
                         list(map(smac_hdl._encode, forbidden_values))))
             else:
                 clauses.append(
                     ForbiddenEqualsClause(
                         store[true_name],
                         smac_hdl._encode(forbidden_values)))
         cs.add_forbidden_clause(ForbiddenAndConjunction(*clauses))
コード例 #7
0
ファイル: config_space.py プロジェクト: chengdake/autoflow
def replace_phps(shps: ConfigurationSpace, key, value):
    for hp in shps.get_hyperparameters():
        if hp.__class__.__name__ == "Constant" and hp.name.endswith(key):
            hp.value = _encode(value)