How to use the numjs.subtract 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
function adjust_temp(z_old, temp) {
        var z = nj.array(z_old);
        var i;
        var x;
        //console.log("before="+z_old.get(0));
        for (i = z.shape[0] - 1; i >= 0; i--) {
            x = z.get(i);
            x = Math.log(x) / temp;
            z.set(i, x);
        }
        x = z.max();
        z = nj.subtract(z, x);
        z = nj.exp(z);
        x = z.sum();
        z = nj.divide(z, x);
        //console.log("after="+z.get(0));
        return z;
    };
github MindExMachina / smartgeometry / services / sketch-rnn / lib / sketch_rnn.js View on Github external
function get_pdf(s) {
        var h = s[0];
        var NOUT = N_mixture;
        var z = nj.add(nj.dot(h, dec_output_w), dec_output_b);
        var z_pen_logits = z.slice([0, 3]);
        var z_pi = z.slice([3 + NOUT * 0, 3 + NOUT * 1]);
        var z_mu1 = z.slice([3 + NOUT * 1, 3 + NOUT * 2]);
        var z_mu2 = z.slice([3 + NOUT * 2, 3 + NOUT * 3]);
        var z_sigma1 = nj.exp(z.slice([3 + NOUT * 3, 3 + NOUT * 4]));
        var z_sigma2 = nj.exp(z.slice([3 + NOUT * 4, 3 + NOUT * 5]));
        var z_corr = nj.tanh(z.slice([3 + NOUT * 5, 3 + NOUT * 6]));
        z_pen_logits = nj.subtract(z_pen_logits, z_pen_logits.max());
        var z_pen = nj.softmax(z_pen_logits);
        z_pi = nj.subtract(z_pi, z_pi.max());
        z_pi = nj.softmax(z_pi);

        return [z_pi, z_mu1, z_mu2, z_sigma1, z_sigma2, z_corr, z_pen];
    };
github MindExMachina / smartgeometry / services / sketch-rnn / lib / sketch_rnn.js View on Github external
function get_pdf(s) {
        var h = s[0];
        var NOUT = N_mixture;
        var z = nj.add(nj.dot(h, dec_output_w), dec_output_b);
        var z_pen_logits = z.slice([0, 3]);
        var z_pi = z.slice([3 + NOUT * 0, 3 + NOUT * 1]);
        var z_mu1 = z.slice([3 + NOUT * 1, 3 + NOUT * 2]);
        var z_mu2 = z.slice([3 + NOUT * 2, 3 + NOUT * 3]);
        var z_sigma1 = nj.exp(z.slice([3 + NOUT * 3, 3 + NOUT * 4]));
        var z_sigma2 = nj.exp(z.slice([3 + NOUT * 4, 3 + NOUT * 5]));
        var z_corr = nj.tanh(z.slice([3 + NOUT * 5, 3 + NOUT * 6]));
        z_pen_logits = nj.subtract(z_pen_logits, z_pen_logits.max());
        var z_pen = nj.softmax(z_pen_logits);
        z_pi = nj.subtract(z_pi, z_pi.max());
        z_pi = nj.softmax(z_pi);

        return [z_pi, z_mu1, z_mu2, z_sigma1, z_sigma2, z_corr, z_pen];
    };