title: How to deep learn from a row of numbers using Node.js and convnetjs and predicted a new value?
body: <p>I try to to use <a href="http://cs.stanford.edu/people/karpathy/convnetjs/" rel="noreferrer">convnetjs</a> to make Node.js learn from a row of numbers in <code>x,y</code> coordiinates. The goal is to predicted next value in a simple number row.</p>
  
  <p>First of all a very simple row <code>[0,1,0,2,0,3,0,4,0,5,0,6]</code> maybe later <code>sin</code> and <code>cos</code> number row.</p>
  
  <p>I do not want to go to deep into the deep learning materia so I am using convnetjs. </p>
  
  <p>So far I tried :</p>
  
  <pre><code>var convnetjs = require("./convnet-min.js");
  
  // create a net out of it
  var net = new convnetjs.Net();
  
  var layer_defs = [];
  layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth:1});
  layer_defs.push({type:'fc', num_neurons:5, activation:'sigmoid'});
  layer_defs.push({type:'regression', num_neurons:1});
  var net = new convnetjs.Net();
  net.makeLayers(layer_defs);
  
  var my_data = [
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8,9,10,
      0,1,2,3,4,5,6,7,8
  ];
  
  var x = new convnetjs.Vol(my_data);
  
  var trainer = new convnetjs.SGDTrainer(net, {learning_rate:1.1, momentum:0.0, batch_size:1, l2_decay:0.001});
  
  var think = function () {
      for (var i = 0; i &lt; my_data.length; i++) {
          x.w[i] = my_data[i]; // Vol.w is just a list, it holds your data
          trainer.train(x, my_data[i]);
      }
  }
  
  for (var i = 0; i &lt; 100; i++) {
      think();
      var predicted_values = net.forward(x);
      console.log('predicted value: ' + predicted_values.w[0]);
  }
  </code></pre>
  
  <p>To realize learning I want to predict the next value, but I wonder (knowing the next value [9]) how to tell the trainer he did a bad, good or very good job? </p>
  
  <p>What this the right way to train <code>x</code> more to predict a value? I guess this is not trivial as that because the predicted value goes not into direction of value  <code>9</code> ^^. </p>