The startTesting function does not work, how can I indicate that the variables need to be taken from startLearning?

function startLearning() { var XOR_INPUT = [ [0, 0], [1, 0], [0, 1], [1, 1] ]; var XOR_IDEAL = [ [0], [1], [1], [0] ]; var con = ENCOG.GUI.Console.create('out'); var network = ENCOG.BasicNetwork.create([ ENCOG.BasicLayer.create(ENCOG.ActivationSigmoid.create(), 2, 1), ENCOG.BasicLayer.create(ENCOG.ActivationSigmoid.create(), 3, 1), ENCOG.BasicLayer.create(ENCOG.ActivationSigmoid.create(), 1, 0) ]); network.randomize(); var train = ENCOG.PropagationTrainer.create(network, XOR_INPUT, XOR_IDEAL, "RPROP", 0, 0); var iteration = 1; do { train.iteration(); var str = "Training Iteration #" + iteration + ", Error: " + train.error; con.writeLine(str); iteration++; } while (iteration < 1000 && train.error > 0.01); var input = [0, 0]; var output = new Array(1); } function startTesting(test_INPUT) { con.writeLine("Testing neural network"); for (var i = 0; i < test_INPUT.length; i++) { network.compute(test_INPUT[i], output); var str = "Input: " + String(test_INPUT[i][0]) + " ; " + String(test_INPUT[i][1]) + " Output: " + String(output[0]) + " Ideal: " + String(XOR_IDEAL[i][0]); con.writeLine(str); } } 
 <html> <head> <script src="encog.js"></script> <script src="encog-widget.js"></script> <script type="text/javascript" src="neuro.js"></script> </head> <body> <button onclick="startLearning()">Learning</button> </br> <div id="out"></div> </br> <button onclick="startTesting([[0,1],[1,1]])">Testing</button> </body> </html> 

  • to declare variables outside a function? From the scope of the function, you will not get them in another way - Vasily Barbashev

1 answer 1

Transfer variables to the common, for both functions, scope, or, alternatively, use localStorage.