How to use the numjs.dot function in numjs

To help you get started, we’ve selected a few numjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eimg / burmese-text-classifier / train.js View on Github external
var prev_synapse_1_weight_update = nj.zeros(synapse_1.shape);

    var synapse_0_direction_count = nj.zeros(synapse_0.shape);
    var synapse_1_direction_count = nj.zeros(synapse_1.shape);

    for(var j = 0; j < epochs + 1; j++) {

        var layer_0 = X;
        var layer_1 = nj.sigmoid(nj.dot(layer_0, synapse_0));

        if(dropout) {
            // I don't understand what this does yet
            // layer_1 *= nj.random.binomial([np.ones((len(X),hidden_neurons))], 1-dropout_percent)[0] * (1.0/(1-dropout_percent));
        }

        var layer_2 = nj.sigmoid(nj.dot(layer_1, synapse_1));
        var layer_2_error = y.subtract(layer_2);

        if( (j % 10000) == 0 && j > 5000 ) {
            // if this 10k iteration's error is greater than
            // the last iteration, break out
            if (nj.mean(nj.abs(layer_2_error)) < last_mean_error) {
                console.log("delta after " + j + " iterations:" + nj.mean(nj.abs(layer_2_error)) );
                last_mean_error = nj.mean(nj.abs(layer_2_error));
            } else {
                console.log ("break:" + nj.mean(nj.abs(layer_2_error)) + ">" + last_mean_error );
                break;
            }
        }

        var layer_2_delta = layer_2_error.multiply( curve(layer_2) );
        var layer_1_error = layer_2_delta.dot(synapse_1.T);
github eimg / burmese-text-classifier / train.js View on Github external
var last_mean_error = 1;

    var synapse_0 = nj.array( rand(X_arr[0].length, hidden_neurons) );
    var synapse_1 = nj.array( rand(hidden_neurons, classes.length) );

    var prev_synapse_0_weight_update = nj.zeros(synapse_0.shape);
    var prev_synapse_1_weight_update = nj.zeros(synapse_1.shape);

    var synapse_0_direction_count = nj.zeros(synapse_0.shape);
    var synapse_1_direction_count = nj.zeros(synapse_1.shape);

    for(var j = 0; j < epochs + 1; j++) {

        var layer_0 = X;
        var layer_1 = nj.sigmoid(nj.dot(layer_0, synapse_0));

        if(dropout) {
            // I don't understand what this does yet
            // layer_1 *= nj.random.binomial([np.ones((len(X),hidden_neurons))], 1-dropout_percent)[0] * (1.0/(1-dropout_percent));
        }

        var layer_2 = nj.sigmoid(nj.dot(layer_1, synapse_1));
        var layer_2_error = y.subtract(layer_2);

        if( (j % 10000) == 0 && j > 5000 ) {
            // if this 10k iteration's error is greater than
            // the last iteration, break out
            if (nj.mean(nj.abs(layer_2_error)) < last_mean_error) {
                console.log("delta after " + j + " iterations:" + nj.mean(nj.abs(layer_2_error)) );
                last_mean_error = nj.mean(nj.abs(layer_2_error));
            } else {
github eimg / burmese-text-classifier / classify.js View on Github external
function think(sentence) {
    var x = bow(sentence, words);

    var l0 = x;
    var l1 = nj.sigmoid(nj.dot(l0, synapse_0));
    var l2 = nj.sigmoid(nj.dot(l1, synapse_1));

    return l2;
}