Example #1
0
    def testInvert(self):
        """
        Testen invert
        De Invert zou de input om moeten draaien (1 word 0 en omgekeerd).
        """
        testInvertPort = Neuron.Neuron(weights=[-1], bias=0)
        output = []

        output.append(round(testInvertPort.activatieNeuron([0])))
        output.append(round(testInvertPort.activatieNeuron([1])))

        self.assertNotEqual([1, 0], output)
Example #2
0
    def testORNeuron(self):
        ORNeuron = Neuron(weights=[1, 1], bias=-1)
        ORinput = [[[1, 1], 1], [[1, 0], 1], [[0, 1], 1], [[0, 0], 0]]
        #
        # for testInput in ORinput:
        #     ORNeuron.setInput(neuronInput=testInput[0])
        #     ORNeuron.activate()
        #     self.assertEqual(ORNeuron.output, testInput[1])

        ORNeuron = Neuron(weights=[100, 100], bias=-50)
        for testInput in ORinput:
            ORNeuron.setInput(neuronInput=testInput[0])
            ORNeuron.activate()
            self.assertEqual(int(ORNeuron.output), testInput[1])
Example #3
0
    def testINVERTNeuron(self):
        INVERTNeuron = Neuron(weights=[-1], bias=0)
        INVERTinput = [[[1], 0], [[0], 1]]
        #
        # for testInput in INVERTinput:
        #     INVERTNeuron.setInput(neuronInput=testInput[0])
        #     INVERTNeuron.activate()
        #     self.assertEqual(INVERTNeuron.output, testInput[1])

        INVERTNeuron = Neuron(weights=[-110], bias=100)
        for testInput in INVERTinput:
            INVERTNeuron.setInput(neuronInput=testInput[0])
            INVERTNeuron.activate()
            self.assertEqual(int(INVERTNeuron.output), testInput[1])
Example #4
0
    def testOr(self):
        """
        Testen or port
        De or gate zou alleen UIT moeten staan als geen een input 1 is.
        """
        testOrPort = Neuron.Neuron(weights=[0.5, 0.5], bias=-0.5)
        output = []
        output.append(round(testOrPort.activatieNeuron([0, 0])))
        output.append(round(testOrPort.activatieNeuron([0, 1])))
        output.append(round(testOrPort.activatieNeuron([1, 0])))
        output.append(round(testOrPort.activatieNeuron([1, 1])))

        self.assertEqual([0, 1, 1, 1], output)
Example #5
0
    def testAnd(self):
        """
        Testen and port
        De and gate zou alleen AAN moeten staan als beide inputs 1 zijn.
        """
        testAndPort = Neuron.Neuron(weights=[0.5, 0.5], bias=-1.0)
        output = []
        output.append(round(testAndPort.activatieNeuron([0, 0])))
        output.append(round(testAndPort.activatieNeuron([0, 1])))
        output.append(round(testAndPort.activatieNeuron([1, 0])))
        output.append(round(testAndPort.activatieNeuron([1, 1])))

        self.assertEqual([0, 0, 0, 1], output)
Example #6
0
    def testNOR(self):
        NORNeuron = Neuron(weights=[-1, -1, -1], bias=0)
        NORinput = [[[0, 0, 0], 1], [[1, 0, 0], 0], [[1, 1, 0], 0],
                    [[1, 1, 1], 0], [[0, 0, 1], 0], [[0, 1, 0], 0],
                    [[0, 1, 1], 0]]

        # for testInput in NORinput:
        #     NORNeuron.setInput(neuronInput=testInput[0])
        #     NORNeuron.activate()
        #     self.assertEqual(NORNeuron.output, testInput[1])

        NORNeuron = Neuron(weights=[-100, -100, -100], bias=100)
        for testInput in NORinput:
            NORNeuron.setInput(neuronInput=testInput[0])
            NORNeuron.activate()
            self.assertEqual(int(NORNeuron.output), testInput[1])
Example #7
0
    def testNor(self):
        """
        Testen Nor port
        De Nor gate zou alleen aan moeten staan als alle inputs 0 zijn.
        """
        testNorPort = Neuron.Neuron(weights=[-1, -1, -1], bias=0.1)
        output = []

        for num1 in range(2):
            for num2 in range(2):
                for num3 in range(2):
                    output.append(round(testNorPort.activatieNeuron([num1, num2, num3])))

        self.assertEqual(output, [1, 0, 0, 0, 0, 0, 0, 0])
Example #8
0
    def testANDNeuron(self):
        ANDNeuron = Neuron(weights=[0.5, 0.5], bias=-1)
        ANDinput = [[[1, 1], 1], [[1, 0], 0], [[0, 1], 0], [[0, 0], 0]]

        # for testInput in ANDinput:
        #     ANDNeuron.setInput(neuronInput=testInput[0])
        #     ANDNeuron.activate()
        #     self.assertEqual(ANDNeuron.output, testInput[1])

        ## The gates won't work the same as the perceptrons because output is given in floats instead
        ## of integers.

        ANDNeuron = Neuron(weights=[100, 100], bias=-100)
        for testInput in ANDinput:
            ANDNeuron.setInput(neuronInput=testInput[0])
            ANDNeuron.activate()
            self.assertEqual(int(ANDNeuron.output), testInput[1])