예제 #1
0
    def test_remove_symbol(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'0': 0.4, '1': 0.4, '9': 0.2})
        attr2 = ProbabilityEnhancedAttribute({'0': 0.5, '1': 0.5})

        # when
        assert attr1.remove_symbol('9')

        # then
        assert attr1 == attr2
예제 #2
0
    def test_insert_symbol(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'0': 0.5, '1': 0.5})
        attr2 = ProbabilityEnhancedAttribute({'0': 0.4, '1': 0.4, '9': 0.2})

        # when
        attr1.insert_symbol('9', 0.8, 0.2)

        # then
        assert attr1 == attr2
예제 #3
0
    def test_remove_last_symbol(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'0': 1.0})
        attr2 = ProbabilityEnhancedAttribute({'0': 1.0})

        # when
        assert not attr1.remove_symbol('0')

        # then
        assert attr1 == attr2
예제 #4
0
    def test_get_best_symbol(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'0': 0.4, '1': 0.6})
        attr2 = ProbabilityEnhancedAttribute({'0': 0.5, '1': 0.3, '9': 0.2})
        attr3 = ProbabilityEnhancedAttribute({'0': 0.3, '1': 0.3, '9': 0.4})

        # then
        assert attr1.get_best_symbol() == '1'
        assert attr2.get_best_symbol() == '0'
        assert attr3.get_best_symbol() == '9'
예제 #5
0
    def __init__(self, observation):
        # Convert dict to ProbabilityEnhancedAttribute
        if not all(
                isinstance(attr, ProbabilityEnhancedAttribute)
                for attr in observation):

            observation = (ProbabilityEnhancedAttribute(attr) if isinstance(
                attr, dict) else attr for attr in observation)

        super().__init__(observation)
예제 #6
0
    def test_is_compact(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'0': 0.6, '1': 0.4, '9': 0.0})
        attr2 = ProbabilityEnhancedAttribute({'0': 0.6, '1': 0.4})

        # then
        assert not attr1.is_compact()
        assert attr2.is_compact()
예제 #7
0
    def test_is_similar_3(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'0': 0.5, '1': 0.4, '9': 0.1})
        attr2 = ProbabilityEnhancedAttribute({'0': 0.9, '9': 0.1})

        # then
        assert not attr1.is_similar(attr2)
        assert not attr2.is_similar(attr1)
예제 #8
0
    def test_is_similar_1(self):
        # given
        attr1 = ProbabilityEnhancedAttribute({'1': 0.8, '0': 0.2})
        attr2 = ProbabilityEnhancedAttribute({'1': 0.4, '0': 0.6})

        # then
        assert attr1.is_similar(attr2)
        assert attr2.is_similar(attr1)
예제 #9
0
    def enhanced_effect(cls,
                        effect1,
                        effect2,
                        q1: float = 0.5,
                        q2: float = 0.5,
                        perception: ImmutableSequence = None):
        """
        Create a new enhanced effect part.
        """
        assert perception is not None
        result = cls(observation=effect1)
        for i, attr2 in enumerate(effect2):
            attr1 = effect1[i]
            if attr1 == Effect.WILDCARD and attr2 == Effect.WILDCARD:
                continue
            if attr1 == Effect.WILDCARD:
                attr1 = perception[i]
            if attr2 == Effect.WILDCARD:
                attr2 = perception[i]

            result[i] = ProbabilityEnhancedAttribute.merged_attributes(
                attr1, attr2, q1, q2)

        return result
예제 #10
0
 def test_should_initialize_correctly_dict(self):
     attr = ProbabilityEnhancedAttribute({'1': 1.0, '0': 0.0})
     assert attr.sum_of_probabilities() == 1.0
     assert attr['1'] == 1.0
예제 #11
0
 def test_should_initialize_correctly_str(self):
     attr = ProbabilityEnhancedAttribute('1')
     assert attr.sum_of_probabilities() == 1.0
     assert attr['1'] == 1.0
예제 #12
0
    def test_is_similar_0(self):
        # given
        attr = ProbabilityEnhancedAttribute({'1': 0.8, '0': 0.2})

        # then
        assert attr.is_similar(attr)