Learn Neural Networks

With Brain.js
    // input 0 0, output 0
    // input 0 1, output 1
    // input 1 0, output 1
    // input 1 1, output 0
    
    const net = new brain.NeuralNetwork({ hiddenLayers: [3] });
    
    const trainingData = [
      { input: [0, 0], output: [0] },
      { input: [0, 1], output: [1] },
      { input: [1, 0], output: [1] },
      { input: [1, 1], output: [0] }
    ];
    
    // input 0 0, output 0
    // input 0 1, output 1
    // input 1 0, output 1
    // input 1 1, output 0
    
    const net = new brain.NeuralNetwork({ hiddenLayers: [3] });
    
    const trainingData = [
      { input: [0, 0], output: [0] },
      { input: [0, 1], output: [1] },
      { input: [1, 0], output: [1] },
      { input: [1, 1], output: [0] }
    ];
    
    // inputs & outputs
    (inputs) => outputs;
    
    // random values
    Math.random();
    
    // activation "relu"
    function relu(value) {
        return value < 0 ? 0 : value;
    }
    
    // bonus material
    // https://en.wikipedia.org/wiki/Activation_function
    /*
    const net = new brain.NeuralNetwork({ hiddenLayers: [2, 2] });
    
    const trainingData = [
      { input: [0, 0], output: [0] },
      { input: [0, 1], output: [1] },
      { input: [1, 0], output: [1] },
      { input: [1, 1], output: [0] }
    ];
    
    net.train(trainingData, {
        log: (error) => console.log(error)
    });
    
    
    // input: { red, green, blue }
    // ouput: { light, neutral, dark }
    
    const colors = [
        { green: 0.2, blue: 0.4 },
        { green: 0.4, blue: 0.6 },
        { red: 0.2, green: 0.8, blue: 0.8 },
        { green: 1, blue: 1 },
        { red: 0.8, green: 1, blue: 1 },
        { red: 1, green: 1, blue: 1 },
        { red: 1, green: 0.8, blue: 0.8 },
        { red: 1, green: 0.6, blue: 0.6 },
        { red: 1, green: 0.4, blue: 0.4 },
        { red: 1, green: 0.31, blue: 0.31 },
    const restaurants = {
        "Brilliant Yellow Corral": "Monday",
        "Penny’s": "Tuesday",
        "Right Coast Wings": "Wednesday",
        "The Delusion Last Railway Car": "Thursday",
        "Fun Day Inn": "Friday",
        "JHOP": "Saturday",
        "Owls": "Sunday"
    };
    
    // input: { Monday, Tuesday, Wednesday, etc. }
    // output: { Restaurant1, Restaurant2 }
    
    const trainingData = [];
    // Count to 5
    // 1-5, 5-1
    
    const trainingData = [
        [1,2,3,4,5],
        [5,4,3,2,1]
    ];
    
    const net = new brain.recurrent.LSTMTimeStep();
    
    net.train(trainingData);
    
    console.log(net.run([1,2,3,4]));
    console.log(net.run([5,4,3,2]));