P. Waksman
P. Waksman

Reputation: 1009

Boolean Perceptron for the NOT Function

I'm trying to implement a simple perceptron for the basic boolean expression. But I was not able correctly traine the NOT perceptron.

I was successfully able to traine the AND and OR perceptron to return the correct values for the given input set. But when I try to traine the NOT.

That is how I'm doing it:

The AND and OR perceptron have two inputs, two weights and One Bias(with fixed 1 to the bias input).

All perceptron starts with 0 on all weights. Then I generate random values (between 0 and 1) to traine the perceptrons, and keep it on a loop until I get 10 correctly guesses.

They have a learning rate of 0.1

This is the training process:

To guess the value:
For each input I multiply the input for the weight, and sum all values, including the bias.

sum = (weight1 * input1) + (weight2 * input2) + (biasWeight * biasInput)--Bias input is fixed to 1
return = if (sum > 0) then 1 else 0

To traine the perceptron:
I get the guess from the perceptron

val = and.guess(1,0) --This will return 0 or 1
error = answer - val

For each input I execute this calculation

weight = weight + (input * error * rate)

Then I do the same for the bias

biasWeight = biasWeight + (input * error * rate)--Bias input is fixed to 1

With this process, I can successfully traine the AND and OR perceptron.

The only difference between the AND/OR and the NOT perceptron is the number of Inputs (only 1 for the NOT)

But the NOT perceptron just keep growing the weight by the number in the learning rate.

Some times, depending on the training order of the NOT Perceptron it get the correctly values when it hit 0.5.

There is the code (html, javascript) when I got home to post the code. I actually found the bug. the CALC function that should return weight * input was returning weight + input, and it actually worked for the AND and OR training.

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="jquery-3.2.1.js"></script>

    <script type="text/javascript">
        function Show(text) {
            if (!text) {
                text = '';
            }

            document.writeln(text + '<br />');
        }

        //return random value from 0 ~ 1
        function getRandom() {
            return Math.floor(Math.random() * 2);
        };

        function PerceptronData(input, weight) {
            this.input = input;
            this.weight = weight;
        }
        PerceptronData.prototype.calc = function () {
            var result = this.input + this.weight;
            return result;
        };
        PerceptronData.prototype.adjust = function (error, rate) {
            this.weight += (this.input * error * rate);
        };
        PerceptronData.prototype.print = function () {
            return '(' + this.input + ', ' + this.weight + ')';
        }

        function Perceptron(n) {
            this.data = [];//Data array [input, weight]
            this.bias = new PerceptronData(1, 0);
            this.rate = 0.1;//learning rate

            //initial data
            for (var index = 0; index < n; index++) {
                this.data.push(new PerceptronData(0, 0));
            }
        }
        //called from "guess" function in the final perceptron
        Perceptron.prototype.process = function (inputs) {
            var data = this.data;

            if (inputs.length != data.length) {
                throw "The number os inputs [" + inputs.length + "] doesn't match with the start value [" + data.length + "] of the Perceptron.";
            }

            var dataSum = 0;
            for (var index = 0; index < data.length; index++) {
                data[index].input = parseInt(inputs[index]);
                dataSum += data[index].calc();
            }

            dataSum += this.bias.calc();

            return dataSum;
        };
        //twick the weight for every data
        Perceptron.prototype.adjust = function (value, answer) {
            var data = this.data;
            var error = answer - value;

            for (var index = 0; index < data.length; index++) {
                data[index].adjust(error, this.rate);
            }

            this.bias.adjust(error, this.rate);
        };
        Perceptron.prototype.print = function () {
            var data = this.data;
            var result = '';
            for (var index = 0; index < data.length; index++) {
                result += 'data[' + index + ']' + data[index].print() + ' > ';
            }

            return result + 'bias' + this.bias.print();
        };

        function NotPerceptron() {
            Perceptron.call(this, 1);
        }
        NotPerceptron.prototype = Object.create(Perceptron.prototype);
        NotPerceptron.prototype.guess = function (value) {
            var data = this.process([value]);

            //activation function
            return ((data > 0) ? 1 : 0);
        };
        NotPerceptron.prototype.train = function (value, answer) {
            var result = this.guess([value]);
            this.adjust(result, answer);
        };

        function AndPerceptron() {
            Perceptron.call(this, 2);
        }
        AndPerceptron.prototype = Object.create(Perceptron.prototype);
        AndPerceptron.prototype.guess = function (valueA, valueB) {
            var data = this.process([valueA, valueB]);

            //activation function
            return ((data > 0) ? 1 : 0);
        };
        AndPerceptron.prototype.train = function (valueA, valueB, answer) {
            var result = this.guess(valueA, valueB);

            this.adjust(result, answer);
        };

        function OrPerceptron() {
            Perceptron.call(this, 2);
        }
        OrPerceptron.prototype = Object.create(Perceptron.prototype);
        OrPerceptron.prototype.guess = function (valueA, valueB) {
            var data = this.process([valueA, valueB]);

            //activation function
            return ((data > 0) ? 1 : 0);
        };
        OrPerceptron.prototype.train = function (valueA, valueB, answer) {
            var result = this.guess(valueA, valueB);

            this.adjust(result, answer);
        };
    </script>
</head>
<body>
    <script type="text/javascript">
        Show('Training AND...');
        Show();
        var and = new AndPerceptron();

        var count = 0;
        var total = 0;
        var max = 100;

        while (count < 10 && total < max) {
            total++;
            var a = getRandom();
            var b = getRandom();
            var answer = ((a === 1 && b === 1) ? 1 : 0);

            and.train(a, b, answer);

            a = getRandom();
            b = getRandom();
            answer = ((a === 1 && b === 1) ? 1 : 0);

            var guess = and.guess(a, b);

            if (guess === answer) {
                count++;
            } else {
                count = 0;
            }

            Show(' > AND(' + a + ', ' + b + ') = ' + guess + ' > [' + and.print() + ']');

            if (count == 10) {
                //final test
                if (and.guess(0, 0) == 1) {
                    count = 0;
                }

                if (and.guess(0, 1) == 1) {
                    count = 0;
                }

                if (and.guess(1, 0) == 1) {
                    count = 0;
                }

                if (and.guess(1, 1) == 0) {
                    count = 0;
                }
            }
        }
        Show();

        if (total >= max) {
            Show('AND training failed...');
        } else {
            Show('AND trained with [' + total + '] interactions. [' + and.print() + ']');
        }

        Show();
        Show('AND(0, 0) = ' + and.guess(0, 0));
        Show('AND(0, 1) = ' + and.guess(0, 1));
        Show('AND(1, 0) = ' + and.guess(1, 0));
        Show('AND(1, 1) = ' + and.guess(1, 1));

        Show();
        Show('Training OR...');
        Show();
        var or = new OrPerceptron();

        count = 0;
        total = 0;
        max = 100;

        while (count < 10 && total < max) {
            total++;
            var a = getRandom();
            var b = getRandom();
            var answer = ((a === 1 || b === 1) ? 1 : 0);

            or.train(a, b, answer);

            a = getRandom();
            b = getRandom();
            answer = ((a === 1 || b === 1) ? 1 : 0);

            var guess = or.guess(a, b);

            if (guess === answer) {
                count++;
            } else {
                count = 0;
            }

            Show(' > OR(' + a + ', ' + b + ') = ' + guess + ' > [' + or.print() + ']');

            if (count == 10) {
                //final test
                if (or.guess(0, 0) == 1) {
                    count = 0;
                }

                if (or.guess(0, 1) == 0) {
                    count = 0;
                }

                if (or.guess(1, 0) == 0) {
                    count = 0;
                }

                if (or.guess(1, 1) == 0) {
                    count = 0;
                }
            }
        }
        Show();

        if (total >= max) {
            Show('OR training failed...');
        } else {
            Show('OR trained with [' + total + '] interactions. [' + or.print() + ']');
        }

        Show();
        Show('OR(0, 0) = ' + or.guess(0, 0));
        Show('OR(0, 1) = ' + or.guess(0, 1));
        Show('OR(1, 0) = ' + or.guess(1, 0));
        Show('OR(1, 1) = ' + or.guess(1, 1));

        Show();
        Show('Training NOT...');
        Show();
        var not = new NotPerceptron();
        not.rate = 0.1;

        count = 0;
        total = 0;
        max = 100;

        while (count < 10 && total < max) {
            total++;
            var test = getRandom();
            var answer = ((test === 1) ? 0 : 1);

            not.train(test, answer);

            test = getRandom();
            answer = ((test === 1) ? 0 : 1);

            var guess = not.guess(test);

            if (guess === answer) {
                count++;
            } else {
                count = 0;
            }

            Show(' > NOT(' + test + ') = ' + guess + ' > [' + not.print() + ']');

            if (count == 10) {
                //final test
                if (not.guess(0) == 0) {
                    count = 0;
                }

                if (not.guess(1) == 1) {
                    count = 0;
                }
            }
        }
        Show();

        if (total >= max) {
            Show('NOT training failed...');
        } else {
            Show('NOT trained with [' + total + '] interactions. [' + not.print() + ']');
        }

        Show();
        Show('NOT(1) = ' + not.guess(1));
        Show('NOT(0) = ' + not.guess(0));
    </script>
</body>
</html>

The output:

Training AND...

> AND(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0.1)]
> AND(1, 1) = 1 > [data[0](1, 0.1) > data[1](1, 0) > bias(1, 0)]
> AND(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0) > bias(1, 0)]
> AND(1, 1) = 1 > [data[0](1, 0.1) > data[1](1, 0) > bias(1, 0)]
> AND(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0) > bias(1, 0)]
> AND(0, 1) = 0 > [data[0](0, 0.1) > data[1](1, 0) > bias(1, 0)]
> AND(0, 1) = 0 > [data[0](0, 0) > data[1](1, 0) > bias(1, -0.1)]
> AND(0, 1) = 1 > [data[0](0, 0.1) > data[1](1, 0.1) > bias(1, 0)]
> AND(0, 1) = 0 > [data[0](0, 0.1) > data[1](1, 0) > bias(1, -0.1)]
> AND(1, 1) = 0 > [data[0](1, 0.1) > data[1](1, 0) > bias(1, -0.1)]
> AND(1, 1) = 0 > [data[0](1, 0.1) > data[1](1, 0) > bias(1, -0.1)]
> AND(1, 0) = 0 > [data[0](1, 0.1) > data[1](0, 0) > bias(1, -0.1)]
> AND(1, 1) = 1 > [data[0](1, 0.2) > data[1](1, 0.1) > bias(1, 0)]
> AND(0, 0) = 0 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(1, 0) = 0 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(1, 0) = 0 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(1, 0) = 0 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(1, 0) = 0 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(0, 0) = 0 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(1, 0) = 0 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]
> AND(0, 0) = 0 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, -0.1)]

AND trained with [21] interactions. [data[0](1, 0.1) > data[1](1, 0.1) > bias(1, -0.1)]

AND(0, 0) = 0
AND(0, 1) = 0
AND(1, 0) = 0
AND(1, 1) = 1

Training OR...

> OR(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0.1)]
> OR(0, 1) = 1 > [data[0](0, 0.1) > data[1](1, 0.1) > bias(1, 0.1)]
> OR(0, 1) = 1 > [data[0](0, 0.1) > data[1](1, 0.1) > bias(1, 0.1)]
> OR(0, 0) = 1 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, 0.1)]
> OR(0, 0) = 1 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, 0.1)]
> OR(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0.1)]
> OR(0, 1) = 1 > [data[0](0, 0.1) > data[1](1, 0.1) > bias(1, 0.1)]
> OR(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0)]
> OR(0, 0) = 0 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, 0)]
> OR(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0)]
> OR(0, 0) = 0 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, 0)]
> OR(0, 0) = 0 > [data[0](0, 0.1) > data[1](0, 0.1) > bias(1, 0)]
> OR(1, 1) = 1 > [data[0](1, 0.1) > data[1](1, 0.1) > bias(1, 0)]
> OR(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0)]
> OR(1, 0) = 1 > [data[0](1, 0.1) > data[1](0, 0.1) > bias(1, 0)]

OR trained with [15] interactions. [data[0](1, 0.1) > data[1](1, 0.1) > bias(1, 0)]

OR(0, 0) = 0
OR(0, 1) = 1
OR(1, 0) = 1
OR(1, 1) = 1

Training NOT...

> NOT(0) = 0 > [data[0](0, 0) > bias(1, 0)]
> NOT(1) = 1 > [data[0](1, 0) > bias(1, 0.1)]
> NOT(0) = 1 > [data[0](0, 0) > bias(1, 0.1)]
> NOT(1) = 1 > [data[0](1, 0) > bias(1, 0.1)]
> NOT(0) = 0 > [data[0](0, -0.1) > bias(1, 0)]
> NOT(1) = 1 > [data[0](1, -0.2) > bias(1, -0.1)]
> NOT(1) = 1 > [data[0](1, -0.2) > bias(1, -0.1)]
> NOT(0) = 1 > [data[0](0, -0.2) > bias(1, -0.1)]
> NOT(0) = 1 > [data[0](0, -0.30000000000000004) > bias(1, -0.2)]
> NOT(1) = 1 > [data[0](1, -0.30000000000000004) > bias(1, -0.2)]
> NOT(0) = 1 > [data[0](0, -0.30000000000000004) > bias(1, -0.2)]
> NOT(1) = 1 > [data[0](1, -0.4) > bias(1, -0.30000000000000004)]
> NOT(1) = 1 > [data[0](1, -0.5) > bias(1, -0.4)]
> NOT(1) = 1 > [data[0](1, -0.5) > bias(1, -0.4)]
> NOT(1) = 1 > [data[0](1, -0.6) > bias(1, -0.5)]
> NOT(1) = 1 > [data[0](1, -0.6) > bias(1, -0.5)]
> NOT(1) = 1 > [data[0](1, -0.7) > bias(1, -0.6)]
> NOT(1) = 1 > [data[0](1, -0.7999999999999999) > bias(1, -0.7)]
> NOT(0) = 1 > [data[0](0, -0.8999999999999999) > bias(1, -0.7999999999999999)]
> NOT(0) = 1 > [data[0](0, -0.8999999999999999) > bias(1, -0.7999999999999999)]
> NOT(0) = 1 > [data[0](0, -0.9999999999999999) > bias(1, -0.8999999999999999)]
> NOT(0) = 1 > [data[0](0, -0.9999999999999999) > bias(1, -0.8999999999999999)]
> NOT(1) = 1 > [data[0](1, -0.9999999999999999) > bias(1, -0.8999999999999999)]
> NOT(0) = 1 > [data[0](0, -0.9999999999999999) > bias(1, -0.8999999999999999)]
> NOT(0) = 1 > [data[0](0, -1.0999999999999999) > bias(1, -0.9999999999999999)]
> NOT(1) = 1 > [data[0](1, -1.2) > bias(1, -1.0999999999999999)]
> NOT(0) = 1 > [data[0](0, -1.2) > bias(1, -1.0999999999999999)]
> NOT(1) = 1 > [data[0](1, -1.2) > bias(1, -1.0999999999999999)]
> NOT(0) = 1 > [data[0](0, -1.2) > bias(1, -1.0999999999999999)]
> NOT(0) = 1 > [data[0](0, -1.2) > bias(1, -1.0999999999999999)]
> NOT(1) = 1 > [data[0](1, -1.2) > bias(1, -1.0999999999999999)]
> NOT(1) = 1 > [data[0](1, -1.3) > bias(1, -1.2)]
> NOT(0) = 1 > [data[0](0, -1.4000000000000001) > bias(1, -1.3)]
> NOT(0) = 1 > [data[0](0, -1.5000000000000002) > bias(1, -1.4000000000000001)]
> NOT(1) = 1 > [data[0](1, -1.6000000000000003) > bias(1, -1.5000000000000002)]
> NOT(1) = 1 > [data[0](1, -1.6000000000000003) > bias(1, -1.5000000000000002)]
> NOT(0) = 1 > [data[0](0, -1.6000000000000003) > bias(1, -1.5000000000000002)]
> NOT(0) = 1 > [data[0](0, -1.7000000000000004) > bias(1, -1.6000000000000003)]
> NOT(0) = 1 > [data[0](0, -1.8000000000000005) > bias(1, -1.7000000000000004)]
> NOT(1) = 1 > [data[0](1, -1.9000000000000006) > bias(1, -1.8000000000000005)]
> NOT(1) = 1 > [data[0](1, -1.9000000000000006) > bias(1, -1.8000000000000005)]
> NOT(1) = 1 > [data[0](1, -1.9000000000000006) > bias(1, -1.8000000000000005)]
> NOT(1) = 1 > [data[0](1, -1.9000000000000006) > bias(1, -1.8000000000000005)]
> NOT(0) = 1 > [data[0](0, -2.0000000000000004) > bias(1, -1.9000000000000006)]
> NOT(1) = 1 > [data[0](1, -2.1000000000000005) > bias(1, -2.0000000000000004)]
> NOT(1) = 1 > [data[0](1, -2.2000000000000006) > bias(1, -2.1000000000000005)]
> NOT(1) = 1 > [data[0](1, -2.3000000000000007) > bias(1, -2.2000000000000006)]
> NOT(0) = 1 > [data[0](0, -2.3000000000000007) > bias(1, -2.2000000000000006)]
> NOT(0) = 1 > [data[0](0, -2.400000000000001) > bias(1, -2.3000000000000007)]
> NOT(0) = 1 > [data[0](0, -2.500000000000001) > bias(1, -2.400000000000001)]
> NOT(1) = 1 > [data[0](1, -2.600000000000001) > bias(1, -2.500000000000001)]
> NOT(0) = 1 > [data[0](0, -2.700000000000001) > bias(1, -2.600000000000001)]
> NOT(1) = 1 > [data[0](1, -2.800000000000001) > bias(1, -2.700000000000001)]
> NOT(0) = 1 > [data[0](0, -2.9000000000000012) > bias(1, -2.800000000000001)]
> NOT(1) = 1 > [data[0](1, -3.0000000000000013) > bias(1, -2.9000000000000012)]
> NOT(1) = 1 > [data[0](1, -3.0000000000000013) > bias(1, -2.9000000000000012)]
> NOT(1) = 1 > [data[0](1, -3.0000000000000013) > bias(1, -2.9000000000000012)]
> NOT(0) = 1 > [data[0](0, -3.1000000000000014) > bias(1, -3.0000000000000013)]
> NOT(0) = 1 > [data[0](0, -3.1000000000000014) > bias(1, -3.0000000000000013)]
> NOT(1) = 1 > [data[0](1, -3.2000000000000015) > bias(1, -3.1000000000000014)]
> NOT(0) = 1 > [data[0](0, -3.3000000000000016) > bias(1, -3.2000000000000015)]
> NOT(1) = 1 > [data[0](1, -3.4000000000000017) > bias(1, -3.3000000000000016)]
> NOT(0) = 1 > [data[0](0, -3.5000000000000018) > bias(1, -3.4000000000000017)]
> NOT(0) = 1 > [data[0](0, -3.600000000000002) > bias(1, -3.5000000000000018)]
> NOT(1) = 1 > [data[0](1, -3.700000000000002) > bias(1, -3.600000000000002)]
> NOT(1) = 1 > [data[0](1, -3.700000000000002) > bias(1, -3.600000000000002)]
> NOT(1) = 1 > [data[0](1, -3.800000000000002) > bias(1, -3.700000000000002)]
> NOT(0) = 1 > [data[0](0, -3.800000000000002) > bias(1, -3.700000000000002)]
> NOT(1) = 1 > [data[0](1, -3.900000000000002) > bias(1, -3.800000000000002)]
> NOT(1) = 1 > [data[0](1, -4.000000000000002) > bias(1, -3.900000000000002)]
> NOT(1) = 1 > [data[0](1, -4.000000000000002) > bias(1, -3.900000000000002)]
> NOT(0) = 1 > [data[0](0, -4.000000000000002) > bias(1, -3.900000000000002)]
> NOT(0) = 1 > [data[0](0, -4.000000000000002) > bias(1, -3.900000000000002)]
> NOT(1) = 1 > [data[0](1, -4.100000000000001) > bias(1, -4.000000000000002)]
> NOT(1) = 1 > [data[0](1, -4.100000000000001) > bias(1, -4.000000000000002)]
> NOT(1) = 1 > [data[0](1, -4.200000000000001) > bias(1, -4.100000000000001)]
> NOT(0) = 1 > [data[0](0, -4.300000000000001) > bias(1, -4.200000000000001)]
> NOT(1) = 1 > [data[0](1, -4.300000000000001) > bias(1, -4.200000000000001)]
> NOT(1) = 1 > [data[0](1, -4.4) > bias(1, -4.300000000000001)]
> NOT(0) = 1 > [data[0](0, -4.5) > bias(1, -4.4)]
> NOT(0) = 1 > [data[0](0, -4.5) > bias(1, -4.4)]
> NOT(0) = 1 > [data[0](0, -4.5) > bias(1, -4.4)]
> NOT(0) = 1 > [data[0](0, -4.6) > bias(1, -4.5)]
> NOT(1) = 1 > [data[0](1, -4.699999999999999) > bias(1, -4.6)]
> NOT(0) = 1 > [data[0](0, -4.799999999999999) > bias(1, -4.699999999999999)]
> NOT(1) = 1 > [data[0](1, -4.799999999999999) > bias(1, -4.699999999999999)]
> NOT(0) = 1 > [data[0](0, -4.899999999999999) > bias(1, -4.799999999999999)]
> NOT(0) = 1 > [data[0](0, -4.999999999999998) > bias(1, -4.899999999999999)]
> NOT(0) = 1 > [data[0](0, -5.099999999999998) > bias(1, -4.999999999999998)]
> NOT(0) = 1 > [data[0](0, -5.1999999999999975) > bias(1, -5.099999999999998)]
> NOT(0) = 1 > [data[0](0, -5.299999999999997) > bias(1, -5.1999999999999975)]
> NOT(0) = 1 > [data[0](0, -5.299999999999997) > bias(1, -5.1999999999999975)]
> NOT(0) = 1 > [data[0](0, -5.299999999999997) > bias(1, -5.1999999999999975)]
> NOT(1) = 1 > [data[0](1, -5.299999999999997) > bias(1, -5.1999999999999975)]
> NOT(0) = 1 > [data[0](0, -5.299999999999997) > bias(1, -5.1999999999999975)]
> NOT(0) = 1 > [data[0](0, -5.299999999999997) > bias(1, -5.1999999999999975)]
> NOT(0) = 1 > [data[0](0, -5.399999999999997) > bias(1, -5.299999999999997)]
> NOT(0) = 1 > [data[0](0, -5.4999999999999964) > bias(1, -5.399999999999997)]
> NOT(1) = 1 > [data[0](1, -5.599999999999996) > bias(1, -5.4999999999999964)]
> NOT(0) = 1 > [data[0](0, -5.699999999999996) > bias(1, -5.599999999999996)]
> NOT(1) = 1 > [data[0](1, -5.799999999999995) > bias(1, -5.699999999999996)]
> NOT(0) = 1 > [data[0](0, -5.899999999999995) > bias(1, -5.799999999999995)]
> NOT(0) = 1 > [data[0](0, -5.999999999999995) > bias(1, -5.899999999999995)]
> NOT(0) = 1 > [data[0](0, -6.099999999999994) > bias(1, -5.999999999999995)]
> NOT(1) = 1 > [data[0](1, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(0) = 1 > [data[0](0, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(1) = 1 > [data[0](1, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(1) = 1 > [data[0](1, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(0) = 1 > [data[0](0, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(1) = 1 > [data[0](1, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(0) = 1 > [data[0](0, -6.199999999999994) > bias(1, -6.099999999999994)]
> NOT(1) = 1 > [data[0](1, -6.299999999999994) > bias(1, -6.199999999999994)]
> NOT(0) = 1 > [data[0](0, -6.399999999999993) > bias(1, -6.299999999999994)]

Upvotes: 2

Views: 957

Answers (1)

P. Waksman
P. Waksman

Reputation: 1009

Following @Stanislav Kralin sugestion, I have updated the question again so it shows up the problem. And here is the solution.

The problem was with the CALC function that should multiply the value of the input for the weight. But I was adding it.

Unfortunately i was so focuses looking about if I should use a sigmoid function or other function, looking about the learning rate and linear and non linear functions, that I didn't saw this mistake.

And the fact that works well with the AND and OR perceptron really toke me to the wrong direction.

PerceptronData.prototype.calc = function () {
    //var result = this.input + this.weight;//This was wrong... :(
    var result = this.input * this.weight;
    return result;
};

Upvotes: 2

Related Questions