Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

javascript - 未捕获的TypeError:无法读取未定义的突触错误的属性“输入”(Uncaught TypeError: Cannot read property 'input' of undefined Synaptic Error)

I'm noob at Neural Network implementation, so I'm trying to create a new one but i'm getting this error... Browser error

(我对神经网络实施不了解,所以我尝试创建一个新的,但出现此错误... 浏览器错误)

I was following this article https://www.freecodecamp.org/news/how-to-create-a-neural-network-in-javascript-in-only-30-lines-of-code-343dafc50d49/ step by step, but without success...

(我一直在逐步关注本文https://www.freecodecamp.org/news/how-to-create-a-neural-network-in-javascript-in-only-30-lines-of-code-343dafc50d49/ ,但没有成功...)

Let me show my code, Idk what i'm doing wrong.

(让我展示我的代码,Idk我在做什么错。)

rna_teste.js File(rna_teste.js文件)

var inputLayer = new window.synaptic.Layer(2);
var hiddenLayer = new window.synaptic.Layer(3);
var outputLayer = new window.synaptic.Layer(1);

inputLayer.project(hiddenLayer);
hiddenLayer.project(outputLayer);

var myNetwork = new window.synaptic.Network({
input: inputLayer,
hidden: [hiddenLayer],
output: outputLayer
});

var learningRate = .15;
//pegar o que a pessoa digitar, e contar o tempo que ela leva 
//
for (var i = 0; i < 2000000; i++) {  
  // 0,0 => 0  
  myNetwork.activate([15,20]);  
  myNetwork.propagate(learningRate, [0]);
  // 0,1 => 1  
  myNetwork.activate([25,25]);  
  myNetwork.propagate(learningRate, [0]);

  myNetwork.activate([90,10]);  
  myNetwork.propagate(learningRate, [0]);

  myNetwork.activate([80,15]);  
  myNetwork.propagate(learningRate, [0]);

  myNetwork.activate([20,20]);  
  myNetwork.propagate(learningRate, [0]);

  // 0,1 => 1  
  myNetwork.activate([30,28]);  
  myNetwork.propagate(learningRate, [0]);

  // 1,1 => 0  
  myNetwork.activate([31,19]);  
  myNetwork.propagate(learningRate, [0]);

  myNetwork.activate([30,18]);  
  myNetwork.propagate(learningRate, [0]);

  // 1,0 => 1  
  myNetwork.activate([40,35]);  
  myNetwork.propagate(learningRate, [1]);

  // 1,1 => 0  
  myNetwork.activate([70,60]);  
  myNetwork.propagate(learningRate, [1]);

  myNetwork.activate([60,58]);  
  myNetwork.propagate(learningRate, [1]);

  // 1,1 => 0  
  myNetwork.activate([65,59]);  
  myNetwork.propagate(learningRate, [1]);

  myNetwork.activate([50,51]);  
  myNetwork.propagate(learningRate, [1]);

  // 1,1 => 0  
  myNetwork.activate([52,53]);  
  myNetwork.propagate(learningRate, [1]);

  myNetwork.activate([15,90]);  
  myNetwork.propagate(learningRate, [1]);

  myNetwork.activate([80,60]);  
  myNetwork.propagate(learningRate, [1]);

}

index.html File(index.html文件)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Utilizando o EJS</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/synaptic/1.1.4/synaptic.js"></script>
    <script src="rna_teste.js"></script>
  </head>
  <body>
    <form>
      <label for="palavra"
        >Palavra
        <input type="text" id="palavra" />
      </label>
      <input type="text" id="idade" />
    </form>
    <button type="button" id="enviar" onclick="iniciarNeuro()">Enviar</button>
    <script>
      var myNetwork = new window.synaptic.Network();
      var tempo = 0;
      var primeiro_tempo = true;
      var valorPrimeiroTempo = 0;

      $("#palavra").keydown(function(event) {
        tempo = event.timeStamp.toFixed(2);
        console.log(tempo);
        if (primeiro_tempo) {
          valorPrimeiroTempo = tempo;
          primeiro_tempo = false;
          console.log("Primeiro tempo" + valorPrimeiroTempo);
        }
        if (event.which == 13) {
          event.preventDefault();
        }
      });
      function temporizador(subtracao) {
        var seconds = (subtracao / 1000).toFixed(0);
        return seconds;
      }

      function iniciarNeuro() {
        var subtracao = temporizador(tempo - valorPrimeiroTempo);
        var idade = $("#idade").val();
        console.log(Math.round(myNetwork.activate([idade, subtracao])));
        console.log(subtracao);
        console.log(tempo - valorPrimeiroTempo);
      }
    </script>
  </body>
</html>

Can anybody help me?

(有谁能够帮助我?)

  ask by RAINAN BOMFIM translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...