4646 BetaIntegerHyperparameter ,
4747 OrdinalHyperparameter )
4848from ConfigSpace .exceptions import ForbiddenValueError
49- from ConfigSpace .forbidden import ForbiddenEqualsRelation
49+ from ConfigSpace .forbidden import ForbiddenEqualsRelation , ForbiddenLessThanRelation
5050
5151
5252def byteify (input ):
@@ -919,6 +919,34 @@ def test_substitute_hyperparameters_in_conditions(self):
919919 self .assertEqual (new_conditions [0 ], test_conditions [0 ])
920920 self .assertEqual (new_conditions [1 ], test_conditions [1 ])
921921
922+ def test_substitute_hyperparameters_in_inconditions (self ):
923+ cs1 = ConfigurationSpace ()
924+ a = UniformIntegerHyperparameter ('a' , lower = 0 , upper = 10 )
925+ b = UniformFloatHyperparameter ('b' , lower = 1. , upper = 8. , log = False )
926+ cs1 .add_hyperparameters ([a , b ])
927+
928+ cond = InCondition (b , a , [1 , 2 , 3 , 4 ])
929+ cs1 .add_conditions ([cond ])
930+
931+ cs2 = ConfigurationSpace ()
932+ sub_a = UniformIntegerHyperparameter ('a' , lower = 0 , upper = 10 )
933+ sub_b = UniformFloatHyperparameter ('b' , lower = 1. , upper = 8. , log = False )
934+ cs2 .add_hyperparameters ([sub_a , sub_b ])
935+ new_conditions = cs1 .substitute_hyperparameters_in_conditions (cs1 .get_conditions (), cs2 )
936+
937+ test_cond = InCondition (b , a , [1 , 2 , 3 , 4 ])
938+ cs2 .add_conditions ([test_cond ])
939+ test_conditions = cs2 .get_conditions ()
940+
941+ self .assertEqual (new_conditions [0 ], test_conditions [0 ])
942+ self .assertIsNot (new_conditions [0 ], test_conditions [0 ])
943+
944+ self .assertEqual (new_conditions [0 ].get_parents (), test_conditions [0 ].get_parents ())
945+ self .assertIsNot (new_conditions [0 ].get_parents (), test_conditions [0 ].get_parents ())
946+
947+ self .assertEqual (new_conditions [0 ].get_children (), test_conditions [0 ].get_children ())
948+ self .assertIsNot (new_conditions [0 ].get_children (), test_conditions [0 ].get_children ())
949+
922950 def test_substitute_hyperparameters_in_forbiddens (self ):
923951 cs1 = ConfigurationSpace ()
924952 orig_hp1 = CategoricalHyperparameter ("input1" , [0 , 1 ])
@@ -930,7 +958,8 @@ def test_substitute_hyperparameters_in_forbiddens(self):
930958 forb_2 = ForbiddenEqualsClause (orig_hp2 , 1 )
931959 forb_3 = ForbiddenEqualsClause (orig_hp3 , 10 )
932960 forb_4 = ForbiddenAndConjunction (forb_1 , forb_2 )
933- cs1 .add_forbidden_clauses ([forb_3 , forb_4 ])
961+ forb_5 = ForbiddenLessThanRelation (orig_hp1 , orig_hp2 )
962+ cs1 .add_forbidden_clauses ([forb_3 , forb_4 , forb_5 ])
934963
935964 cs2 = ConfigurationSpace ()
936965 sub_hp1 = CategoricalHyperparameter ("input1" , [0 , 1 , 2 ])
@@ -944,9 +973,11 @@ def test_substitute_hyperparameters_in_forbiddens(self):
944973 test_forb_2 = ForbiddenEqualsClause (sub_hp2 , 1 )
945974 test_forb_3 = ForbiddenEqualsClause (sub_hp3 , 10 )
946975 test_forb_4 = ForbiddenAndConjunction (test_forb_1 , test_forb_2 )
947- cs2 .add_forbidden_clauses ([test_forb_3 , test_forb_4 ])
976+ test_forb_5 = ForbiddenLessThanRelation (sub_hp1 , sub_hp2 )
977+ cs2 .add_forbidden_clauses ([test_forb_3 , test_forb_4 , test_forb_5 ])
948978 test_forbiddens = cs2 .get_forbiddens ()
949979
980+ self .assertEqual (new_forbiddens [2 ], test_forbiddens [2 ])
950981 self .assertEqual (new_forbiddens [1 ], test_forbiddens [1 ])
951982 self .assertEqual (new_forbiddens [0 ], test_forbiddens [0 ])
952983
0 commit comments