How to use the numjs.sqrt 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 MindExMachina / smartgeometry / services / sketch-rnn / lib / sketch_rnn.js View on Github external
for (i = 0; i < N; i++) {
            s = [sequence[i][0] / scale_factor, sequence[i][1] / scale_factor, sequence[i][2], sequence[i][3], sequence[i][4]];
            forward_sequence.push(s);
        }
        for (i = N - 1; i >= 0; i--) {
            s = [forward_sequence[i][0], forward_sequence[i][1], forward_sequence[i][2], forward_sequence[i][3], forward_sequence[i][4]];
            reverse_sequence.push(s);
        }
        var output_fw = enc_fw_lstm.encode(forward_sequence);
        var output_bw = enc_bw_lstm.encode(reverse_sequence);
        var output = nj.concatenate([output_fw, output_bw]);
        var mu = nj.add(nj.dot(output, enc_mu_w), enc_mu_b);
        // optimization:
        if (temp > 0) {
            var presig = nj.add(nj.dot(output, enc_sigma_w), enc_sigma_b);
            var sigma = nj.sqrt(nj.exp(presig));
            var eps = nj.multiply(nj.array(random_normal_vector(), 'float32'), temp);
            var z = nj.add(mu, nj.multiply(eps, sigma));
        } else {
            var z = mu;
        }
        return z.tolist();
    };
github MindExMachina / smartgeometry / services / sketch-rnn / lib / sketch_rnn.js View on Github external
var N = sequence.length;
        for (i = 0; i < N; i++) {
            s = [sequence[i][0] / scale_factor, sequence[i][1] / scale_factor, sequence[i][2], sequence[i][3], sequence[i][4]];
            forward_sequence.push(s);
        }
        for (i = N - 1; i >= 0; i--) {
            s = [forward_sequence[i][0], forward_sequence[i][1], forward_sequence[i][2], forward_sequence[i][3], forward_sequence[i][4]];
            reverse_sequence.push(s);
        }
        var output_fw = enc_fw_lstm.encode(forward_sequence);
        var output_bw = enc_bw_lstm.encode(reverse_sequence);
        var output = nj.concatenate([output_fw, output_bw]);
        var mu = nj.add(nj.dot(output, enc_mu_w), enc_mu_b);

        var presig = nj.add(nj.dot(output, enc_sigma_w), enc_sigma_b);
        var sigma = nj.sqrt(nj.exp(presig));

        return [mu, sigma];
    };