コード例 #1
0
    def test_Spectrum(self):
        spectrum = rs.Spectrum(width=2)
        assert spectrum.values == [0, 0]

        with pytest.raises(TypeError) as e:
            spectrum = rs.Spectrum()
        assert "The width of the spectrum must be specified." in str(e)

        connection1 = rs.Connection(0)
        connection2 = rs.Connection(1)
        connection3 = rs.Connection(0)

        spectrum = rs.Spectrum(
            connections=[connection1, connection2, connection3])

        assert spectrum.connections == [connection1, connection2, connection3]
        assert spectrum.values == [0, 1, 0]

        spectrum.values = [0.5, 1, 1.5]
        assert spectrum.values == [0.5, 1, 1.5]

        assert spectrum[0] == connection1
        assert spectrum[1:] == [connection2, connection3]
        with pytest.raises(IndexError) as e:
            connection = spectrum[3]
        assert "Spectrum width exceeded." in str(e)

        test_list = []
        for connection in spectrum:
            test_list.append(connection)
        assert test_list == [connection1, connection2, connection3]

        assert len(spectrum) == 3
コード例 #2
0
ファイル: test_Image.py プロジェクト: jamesjiang52/Reshade
    def test_Image(self):
        image = rs.Image(height=3, width=2)
        assert image.values == [
            [0, 0],
            [0, 0],
            [0, 0]
        ]

        with pytest.raises(TypeError) as e:
            image = rs.Image()
        assert "The height and width of the image must be specified." in str(e)

        connection1 = rs.Connection(0)
        connection2 = rs.Connection(1)
        connection3 = rs.Connection(0)
        connection4 = rs.Connection(1)
        
        spectrum1 = rs.Spectrum([connection1, connection2])
        spectrum2 = rs.Spectrum([connection3, connection4])

        image = rs.Image(spectra=[spectrum1, spectrum2])

        assert image.spectra == [spectrum1, spectrum2]
        assert image.values == [
            [0, 1],
            [0, 1]
        ]

        image.values = [
            [0.5, 1],
            [1.5, 2]
        ]
        assert image.values == [
            [0.5, 1],
            [1.5, 2]
        ]

        assert image[0][0] == connection1
        assert image[1:][0][1] == connection4
        with pytest.raises(IndexError) as e:
            connection = image[2][0]
        assert "Image height exceeded." in str(e)

        test_list = []
        for spectrum in image:
            for connection in spectrum:
                test_list.append(connection)
        assert test_list == [
            connection1, connection2, connection3, connection4]

        assert len(image) == 2
コード例 #3
0
    def test_Connection(self):
        self._test_value = 0

        connection = rs.Connection()
        assert connection.value == 0

        connection = rs.Connection(1)
        assert connection.value == 1

        connection.value = 0
        assert connection.value == 0

        connection.bind_to(self.__tester)
        assert self._test_value == 0

        connection.value = 1
        assert connection.value == 1
        assert self._test_value == 5
コード例 #4
0
    def test_TanhActivationNeuron(self):
        input = rs.Connection()
        output = rs.Connection()

        rs.activation.TanhActivationNeuron(input, output)

        assert input.value == 0
        assert round(output.value, 2) == 0.00

        input.value = -1
        assert round(output.value, 2) == -0.76

        input.value = -2
        assert round(output.value, 2) == -0.96

        input.value = 1
        assert round(output.value, 2) == 0.76

        input.value = 2
        assert round(output.value, 2) == 0.96
コード例 #5
0
    def test_BinaryStepActivationNeuron(self):
        input = rs.Connection()
        output = rs.Connection()

        rs.activation.BinaryStepActivationNeuron(input, output)

        assert input.value == 0
        assert output.value == 1

        input.value = -1
        assert output.value == 0

        input.value = -2
        assert output.value == 0

        input.value = 1
        assert output.value == 1

        input.value = 2
        assert output.value == 1
コード例 #6
0
    def test_LeakyReLUActivationNeuron(self):
        input = rs.Connection()
        output = rs.Connection()

        rs.activation.LeakyReLUActivationNeuron(input, output)

        assert input.value == 0
        assert output.value == 0

        input.value = -1
        assert output.value == -0.01

        input.value = -2
        assert output.value == -0.02

        input.value = 1
        assert output.value == 1

        input.value = 2
        assert output.value == 2
コード例 #7
0
    def test_IdentityActivationNeuron(self):
        input = rs.Connection()
        output = rs.Connection()

        rs.activation.IdentityActivationNeuron(input, output)

        assert input.value == 0
        assert output.value == 0

        input.value = -1
        assert output.value == -1

        input.value = -2
        assert output.value == -2

        input.value = 1
        assert output.value == 1

        input.value = 2
        assert output.value == 2
コード例 #8
0
    def test_AveragePoolingNeuron(self):
        inputs = rs.Image(height=4, width=4)
        output = rs.Connection()

        rs.pooling.AveragePoolingNeuron(inputs, output)

        assert inputs.values == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
                                 [0, 0, 0, 0]]
        assert round(output.value, 2) == 0.00

        inputs.values = [[0, 0, 0, 10], [0, 0, -2, 0], [2, 0, 0, 0],
                         [0, 6, 0, 0]]
        assert round(output.value, 2) == 1.00

        inputs.values = [[1, 2, 3, 4], [-1, -4, -9, -16], [2.79, 3.14, 1, 0],
                         [0, 0, 0, 0]]
        assert round(output.value, 2) == -0.82
コード例 #9
0
    def test_DenseNeuron(self):
        inputs = rs.Spectrum(width=4)
        output = rs.Connection()
        neuron = rs.dense.DenseNeuron(inputs, output)

        assert inputs.values == [0, 0, 0, 0]
        assert neuron.weights == [1, 1, 1, 1]
        assert output.value == 0

        inputs.values = [0.1, 0.2, 0.3, 0.4]
        assert round(output.value, 2) == 1.0

        neuron.weights = [4, 3, 2, 1]
        assert round(output.value, 2) == 2.0

        neuron.weights = [0.5, 1, 1.5, 2]
        assert round(output.value, 2) == 1.5

        inputs.values = [2, 2, 1, 1]
        assert round(output.value, 2) == 6.5
コード例 #10
0
    def test_ConnectionLayer(self):
        layer = rs.ConnectionLayer(height=3, width=4, depth=2)
        assert layer.values == [
            [[0, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 0, 0, 0]],

            [[0, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 0, 0, 0]],
        ]

        with pytest.raises(TypeError) as e:
            layer = rs.ConnectionLayer()
        assert "The depth, height, and width of the layer must be specified."\
            in str(e)

        connection1 = rs.Connection(0)
        connection2 = rs.Connection(1)
        connection3 = rs.Connection(0)
        connection4 = rs.Connection(1)
        connection5 = rs.Connection(0)
        connection6 = rs.Connection(1)

        spectrum1 = rs.Spectrum([connection1])
        spectrum2 = rs.Spectrum([connection2])
        spectrum3 = rs.Spectrum([connection3])
        spectrum4 = rs.Spectrum([connection4])
        spectrum5 = rs.Spectrum([connection5])
        spectrum6 = rs.Spectrum([connection6])

        image1 = rs.Image([spectrum1, spectrum2, spectrum3])
        image2 = rs.Image([spectrum4, spectrum5, spectrum6])

        layer = rs.ConnectionLayer(images=[image1, image2])

        assert layer.images == [image1, image2]
        assert layer.values == [
            [[0],
             [1],
             [0]],

            [[1],
             [0],
             [1]]
        ]

        layer.values = [
            [[0.5],
             [1],
             [1.5]],

            [[2],
             [2.5],
             [3]]
        ]
        assert layer.values == [
            [[0.5],
             [1],
             [1.5]],

            [[2],
             [2.5],
             [3]]
        ]

        assert layer[0][1][0] == connection2
        assert layer[1:][0][1][0] == connection5
        with pytest.raises(IndexError) as e:
            connection = layer[2][0][0]
        assert "Layer depth exceeded." in str(e)

        test_list = []
        for image in layer:
            for spectrum in image:
                for connection in spectrum:
                    test_list.append(connection)
        assert test_list == [
            connection1,
            connection2,
            connection3,
            connection4,
            connection5,
            connection6
        ]

        assert len(layer) == 2