Example #1
0
    def test_wrong_percentage_perturbation(self):
        size = 3
        mp = DropoutMask((size, ))

        for i in [1.1, 1.5, 3.1]:
            mp.perturb(amount=i)
            assert pnp.sum(mp.mask) == round(i)
            mp.clear()
Example #2
0
    def test_percentage_perturbation(self):
        size = 3
        mp = DropoutMask((size, ))

        for i in [0.01, 0.1, 0.5, 0.9]:
            mp.perturb(amount=i)
            assert pnp.sum(mp.mask) == round(i * mp.mask.size)
            mp.clear()
Example #3
0
    def test_perturbation(self):
        size = 3
        mp = DropoutMask((size, ))

        for i in range(1, size + 1):
            mp.perturb(i)
            mp.perturb(i, mode=PerturbationMode.RESET)
            assert pnp.sum(mp.mask) == 0
Example #4
0
    def test_perturbation_mode(self, mode):
        size = 3
        mp = DropoutMask((size, ))

        for amount in [0, size, size + 1]:
            mp.perturb(amount=amount, mode=mode[0])
            mp.perturb(amount=amount, mode=mode[1])
            assert pnp.sum(mp.mask) == 0
Example #5
0
    def test_perturbation_add_remove(self):
        size = 3
        mp = DropoutMask((size, ))

        for amount in [random.randrange(size), 0, size, size + 1]:
            mp.perturb(amount=amount, mode=PerturbationMode.SET)
            assert pnp.sum(mp.mask) == min(amount, size)
            mp.perturb(amount=amount, mode=PerturbationMode.RESET)
            assert pnp.sum(mp.mask) == 0
Example #6
0
    def test_perturbation_invert_remove(self):
        size = 3
        mp = DropoutMask((size, ))

        for amount in [random.randrange(size), 0, size, size + 1]:
            mp.perturb(amount=amount, mode=PerturbationMode.INVERT)
            reversed_amount = pnp.sum(mp.mask).unwrap()  # unwrap tensor
            mp.perturb(amount=reversed_amount, mode=PerturbationMode.RESET)
            assert pnp.sum(mp.mask) == 0
Example #7
0
 def test_negative_perturbation(self):
     mp = DropoutMask((3, ))
     with pytest.raises(AssertionError):
         mp.perturb(amount=-1)
Example #8
0
 def test_wrong_mode(self):
     mp = DropoutMask((3, ))
     with pytest.raises(NotImplementedError):
         mp.perturb(mode=10, amount=1)