wanna model to be selfsufficient and train by its own artificial intelligent reasonings. I wanna AI to hear what sounds it makes and try to adjust it by some unknown factor to some unknown result...: <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Bird Singing Generator with ML Autoencoder</title>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
  <script>
  async function run() {
    await tf.setBackend("cpu");

    // Create the autoencoder architecture with an encoder and decoder
    const encoder = tf.sequential();
    encoder.add(tf.layers.dense({ units: 10, inputShape: [4], activation: 'relu' }));
    encoder.add(tf.layers.dense({ units: 3, activation: 'relu' }));

    const decoder = tf.sequential();
    decoder.add(tf.layers.dense({ units: 10, inputShape: [3], activation: 'relu' }));
    decoder.add(tf.layers.dense({ units: 4 }));

    const autoencoder = tf.model({ inputs: encoder.inputs, outputs: decoder.apply(encoder.outputs) });

    autoencoder.compile({
      loss: "meanSquaredError",
      optimizer: "sgd",
      metrics: ["mse"],
    });

    // Generate random data as input and output for the autoencoder
    const data = new Array(100).fill().map(() => ([Math.random(), Math.random(), Math.random(), Math.random()]));
    const inputs = tf.tensor2d(data);
    const outputs = tf.tensor2d(data);

    // Train the autoencoder
    await autoencoder.fit(inputs, outputs, { batchSize: 10, epochs: 50 });

    function generateParameters() {
      const input = tf.tensor2d([Math.random(), Math.random(), Math.random(), Math.random()], [1, 4]);
      const encoded = encoder.predict(input);
      const generatedParameters = decoder.predict(encoded);

      const [pitchFactor, rhythmFactor, noteDurationFactor, harmonicFactor] = generatedParameters.arraySync()[0];
      
      return { pitchFactor, rhythmFactor, noteDurationFactor, harmonicFactor };
    }

    const audioContext = new (window.AudioContext || window.webkitAudioContext)();

    function playOscillator(freq, startTime, duration, gainNode) {
      const oscillator = audioContext.createOscillator();
      oscillator.type = 'sine';
      oscillator.frequency.setValueAtTime(freq, startTime);

      oscillator.connect(gainNode);
      oscillator.start(startTime);
      oscillator.stop(startTime + duration);
    }

    function playBirdSound() {
      const startTime = audioContext.currentTime;
      const { pitchFactor, rhythmFactor, noteDurationFactor, harmonicFactor } = generateParameters();

      const gainNode = audioContext.createGain();
      gainNode.gain.setValueAtTime(0.5, startTime);
      gainNode.gain.setValueAtTime(0, startTime + noteDurationFactor);
      gainNode.connect(audioContext.destination);

      const freq = 50 + (100 * pitchFactor);
      const numHarmonics = 255 + parseInt(50 * harmonicFactor);

      for (let i = 1; i <= numHarmonics; i++) {
        const harmonicFreq = freq * i;
        playOscillator(harmonicFreq, startTime, noteDurationFactor, gainNode);
      }
    }

    function loopBirdSounds() {
      playBirdSound();
      setTimeout(loopBirdSounds, Math.random() * 100 + 1000);
    }

    loopBirdSounds();
  }

  run();
  </script>
</head>
<body>
  <h1>Bird Singing Generator with ML Autoencoder</h1>
</body>
</html>