Ejemplo n.º 1
0
    def test_normalize_belief(self):
        """Test that the beliefs can be normalized"""
        classifier = DummyClassifier()
        attack = DummyPoisonAttack()
        attack_pairs = AttackPairs()

        attack_pairs.add(classifier, attack, 1)
        attack_pairs.add(classifier, attack, 1)
        attack_pairs.add(classifier, attack, 1)

        attack_pairs.normalize_beliefs()
        assert np.array_equal(attack_pairs.get_beliefs(),
                              np.array([1.0, 1.0, 1.0]) / 3)

        rand_beliefs_3 = np.random.rand(3)
        attack_pairs.set_beliefs(rand_beliefs_3)
        attack_pairs.normalize_beliefs()
        assert np.array_equal(attack_pairs.get_beliefs(),
                              rand_beliefs_3 / np.sum(rand_beliefs_3))
Ejemplo n.º 2
0
    def test_set_beliefs(self):
        """Test that you can set the current beliefs as a numpy array"""
        classifier = DummyClassifier()
        attack = DummyPoisonAttack()
        attack_pairs = AttackPairs()

        attack_pairs.add(classifier, attack, 1)
        rand_beliefs_1 = np.random.rand(1)
        attack_pairs.set_beliefs(rand_beliefs_1)
        assert np.array_equal(attack_pairs.get_beliefs(), rand_beliefs_1)

        attack_pairs.add(classifier, attack, 1)
        rand_beliefs_2 = np.random.rand(2)
        attack_pairs.set_beliefs(rand_beliefs_2)
        assert np.array_equal(attack_pairs.get_beliefs(), rand_beliefs_2)

        attack_pairs.add(classifier, attack, 1)
        rand_beliefs_3 = np.random.rand(3)
        attack_pairs.set_beliefs(rand_beliefs_3)
        assert np.array_equal(attack_pairs.get_beliefs(), rand_beliefs_3)