Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function get_init_state_from_latent_vector(y) {
if (y.constructor != Array) {
console.log("error, the argument passed into decode must be a Javascript normal Array type.");
y = Array.prototype.slice.call(y);
};
var z = nj.array(y);
/**
* for backward compatibility.
*/
if (this.info.version < 6) {
z = nj.tanh(z); // for older versions, clip the latent variable.
}
var init_state = nj.tanh(nj.add(nj.dot(z, enc_w), enc_b));
var c = init_state.slice([0, dec_num_units]).clone();
var h = init_state.slice([dec_num_units, 2 * dec_num_units]).clone();
return [h, c];
};
if (y.constructor != Array) {
console.log("error, the argument passed into decode must be a Javascript normal Array type.");
y = Array.prototype.slice.call(y);
};
var z = nj.array(y);
/**
* for backward compatibility.
*/
if (this.info.version < 6) {
z = nj.tanh(z); // for older versions, clip the latent variable.
}
var init_state = nj.tanh(nj.add(nj.dot(z, enc_w), enc_b));
var c = init_state.slice([0, dec_num_units]).clone();
var h = init_state.slice([dec_num_units, 2 * dec_num_units]).clone();
return [h, c];
};
LSTMCell.prototype.forward = function(x, h, c) {
var concat = nj.concatenate([x, h]);
var hidden = nj.add(nj.dot(concat, this.Wfull), this.bias);
var num_units = this.num_units;
var forget_bias = this.forget_bias;
var i = nj.sigmoid(hidden.slice([0 * num_units, 1 * num_units]));
var g = nj.tanh(hidden.slice([1 * num_units, 2 * num_units]));
var f = nj.sigmoid(nj.add(hidden.slice([2 * num_units, 3 * num_units]), forget_bias));
var o = nj.sigmoid(hidden.slice([3 * num_units, 4 * num_units]));
var new_c = nj.add(nj.multiply(c, f), nj.multiply(g, i));
var new_h = nj.multiply(nj.tanh(new_c), o);
return [new_h, new_c];
};
LSTMCell.prototype.encode = function(sequence) {
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];
};
LSTMCell.prototype.forward = function(x, h, c) {
var concat = nj.concatenate([x, h]);
var hidden = nj.add(nj.dot(concat, this.Wfull), this.bias);
var num_units = this.num_units;
var forget_bias = this.forget_bias;
var i = nj.sigmoid(hidden.slice([0 * num_units, 1 * num_units]));
var g = nj.tanh(hidden.slice([1 * num_units, 2 * num_units]));
var f = nj.sigmoid(nj.add(hidden.slice([2 * num_units, 3 * num_units]), forget_bias));
var o = nj.sigmoid(hidden.slice([3 * num_units, 4 * num_units]));
var new_c = nj.add(nj.multiply(c, f), nj.multiply(g, i));
var new_h = nj.multiply(nj.tanh(new_c), o);
return [new_h, new_c];
};
LSTMCell.prototype.encode = function(sequence) {