Beispiel #1
0
    def test_uniform_unit_scaling_can_initialize(self):
        tensor = torch.zeros([10, 6])
        uniform_unit_scaling(tensor, "linear")

        assert tensor.data.max() < math.sqrt(3 / 10)
        assert tensor.data.min() > -math.sqrt(3 / 10)

        # Check that it gets the scaling correct for relu (1.43).
        uniform_unit_scaling(tensor, "relu")
        assert tensor.data.max() < math.sqrt(3 / 10) * 1.43
        assert tensor.data.min() > -math.sqrt(3 / 10) * 1.43
    def test_uniform_unit_scaling_can_initialize(self):
        tensor = Variable(torch.zeros([10, 6]))
        uniform_unit_scaling(tensor, "linear")

        assert tensor.data.max() < math.sqrt(3/10)
        assert tensor.data.min() > -math.sqrt(3/10)

        # Check that it gets the scaling correct for relu (1.43).
        uniform_unit_scaling(tensor, "relu")
        assert tensor.data.max() < math.sqrt(3/10) * 1.43
        assert tensor.data.min() > -math.sqrt(3/10) * 1.43