예제 #1
0
 def test_mutate_condition_force_stay_wildcard(self, discrete_rule_repr):
     condition = [DiscreteWildcardElem()]
     situation = [1]
     register_hyperparams({"mu": 0.0})
     discrete_rule_repr.mutate_condition(condition, situation)
     assert len(condition) == 1
     assert condition[0] == DiscreteWildcardElem()
예제 #2
0
 def test_gen_covering_condition_force_copy_situation(
         self, discrete_rule_repr):
     situation = [0]
     register_hyperparams({"p_wildcard": 0.0})
     condition = discrete_rule_repr.gen_covering_condition(situation)
     assert len(condition) == 1
     assert condition[0] == 0
예제 #3
0
 def test_mutate_force_disable(self, centre_allele, spread_allele,
                               mutation_magnitude):
     elem = CentreSpreadElem(centre_allele, spread_allele)
     register_hyperparams({"mu": 0.0, "m": mutation_magnitude})
     elem.mutate()
     centre_value_same = elem._centre_allele == centre_allele
     spread_value_same = elem._spread_allele == spread_allele
     assert centre_value_same and spread_value_same
예제 #4
0
 def test_mutate_condition_force_mutate_to_wildcard(self,
                                                    discrete_rule_repr):
     condition = [0]
     # situation does not matter in this context
     situation = [1]
     register_hyperparams({"mu": 1.0})
     discrete_rule_repr.mutate_condition(condition, situation)
     assert len(condition) == 1
     assert condition[0] == DiscreteWildcardElem()
 def test_gen_covering_condition(self, mock_situation_space,
                                 make_centre_spread_rule_repr):
     rule_repr = make_centre_spread_rule_repr(mock_situation_space)
     register_hyperparams({"s_nought": 1.0})
     situation_elem = 0.0
     situation = [situation_elem]
     condition = rule_repr.gen_covering_condition(situation)
     assert len(condition) == 1
     elem = condition[0]
     assert type(elem) == CentreSpreadElem
     assert elem._centre_allele == situation_elem
예제 #6
0
 def test_mutate_force_enable(self, centre_allele, spread_allele,
                              mutation_magnitude):
     orig_centre_value = centre_allele.value
     orig_spread_value = spread_allele.value
     elem = CentreSpreadElem(centre_allele, spread_allele)
     register_hyperparams({"mu": 1.0, "m": mutation_magnitude})
     elem.mutate()
     centre_value_valid = \
         (orig_centre_value - mutation_magnitude) <= elem._centre_allele \
         <= (orig_centre_value + mutation_magnitude)
     spread_value_valid = \
         (orig_spread_value - mutation_magnitude) <= elem._spread_allele \
         <= (orig_spread_value + mutation_magnitude)
     assert centre_value_valid and spread_value_valid