JSFiddle - React, Tailwind, and code Playground

by a_bertrand

HTML

<pre id='result'></pre>

JavaScript

// The base "node" called "neuron"
var Neuron = (function () {
    function Neuron(net) {
        this.Connections = [];
        this.ReverseConnections = [];
        this.value = 0;
        this.Net = net;
    }
    Object.defineProperty(Neuron.prototype, "Value", {
        get: function () {
            return this.value;
        },
        set: function (newValue) {
            this.value = newValue;
            for (var i = 0; i < this.Connections.length; i++)
                this.Connections[i].To.RecalcValue();
        },
        enumerable: true,
        configurable: true
    });
    Neuron.prototype.RecalcValue = function () {
        var v = 0;
        for (var i = 0; i < this.ReverseConnections.length; i++) {
            v += this.ReverseConnections[i].From.value * this.ReverseConnections[i].Weight;
        }
        this.value = v;
        for (var i = 0; i < this.Connections.length; i++)
            this.Connections[i].To.RecalcValue();
    };
    return Neuron;
}());

// Connection between the neurons
var NeuronConnection = (function () {
    function NeuronConnection(from, to) {
        this.From = from;
        this.To = to;
        this.Weight = Math.random() * 2 - 1;
    }
    return NeuronConnection;
}());

// The full system
var NeuronNet = (function () {
    function NeuronNet() {
        this.Inputs = [];
        this.Outputs = [];
        this.Neurons = [];
    }
    NeuronNet.prototype.CheckError = function (data) {
        var err = 0;
        for (var i = 0; i < data.length; i++) {
            // Feed all the data
            for (var j = 0; j < this.Inputs.length; j++) {
                this.Inputs[j].Value = data[i][j];
            }
            for (var j = 0; j < this.Outputs.length; j++) {
                err += Math.abs(data[i][j + this.Inputs.length] - NeuronNet.Sigmoid(this.Outputs[j].Value));
            }
        }
        return err;
    };
    NeuronNet.prototype.GetWeights = function () {
        var result = [];
        for...