How to deep learn from a row of numbers using Node.js and convnetjs and predicted a new value?

Viewed 2082

I try to to use convnetjs to make Node.js learn from a row of numbers in x,y coordiinates. The goal is to predicted next value in a simple number row.

First of all a very simple row [0,1,0,2,0,3,0,4,0,5,0,6] maybe later sin and cos number row.

I do not want to go to deep into the deep learning materia so I am using convnetjs.

So far I tried :

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 < 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 < 100; i++) {
    think();
    var predicted_values = net.forward(x);
    console.log('predicted value: ' + predicted_values.w[0]);
}

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?

What this the right way to train x more to predict a value? I guess this is not trivial as that because the predicted value goes not into direction of value 9 ^^.

1 Answers
Related