How to use the ml-matrix.Matrix.rowVector function in ml-matrix

To help you get started, weā€™ve selected a few ml-matrix 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 image-js / image-js / packages / image-js / src / filters / convolution.ts View on Github external
for (let x = 0; x < cutWidth; x++) {
      const wOffset = (x + kernelOffsetX) * channels;
      for (let y = 0; y < height; y++) {
        columnData[y] = convolvedData[y * cutWidth + x];
      }
      const result = columnConvolution.convolve(columnData);
      for (let i = 0; i < result.length; i++) {
        const idx = (i + kernelOffsetY) * hFactor + wOffset + c;
        newImage.data[idx] = round(clamp(result[i]));
      }
    }
  }

  // Calculate kernel from separated kernels.

  const matrixX = Matrix.rowVector(kernelX);
  const matrixY = Matrix.columnVector(kernelY);
  const kernel = matrixY.mmul(matrixX).to2DArray();

  // Apply convolution on the left and right borders
  for (let c = 0; c < channels; c++) {
    for (let bY = 0; bY < height; bY++) {
      for (let bX = 0; bX < kernelOffsetX; bX++) {
        const idx = (bY * width + bX) * channels + c;

        const bXopp = width - bX - 1;
        const bYopp = height - bY - 1;
        const idxOpp = (bYopp * width + bXopp) * channels + c;

        newImage.data[idx] = computeConvolutionPixel(
          bX,
          bY,
github image-js / image-js / src / image / transform / warping.js View on Github external
let f = (1.0 / (n23 * n33)) * ((n21 * n31 - (n21 * n33 + n23 * n31) * u0 + n23 * n33 * u0 * u0) + (n22 * n32 - (n22 * n33 + n23 * n32) * v0 + n23 * n33 * v0 * v0));
  if (f >= 0) {
    f = Math.sqrt(f);
  } else {
    f = Math.sqrt(-f);
  }

  let A = new Matrix([[f, 0, u0], [0, f, v0], [0, 0, 1]]);
  let At = A.transpose();
  let Ati = inverse(At);
  let Ai = inverse(A);

  let n2R = Matrix.rowVector(n2);
  let n3R = Matrix.rowVector(n3);

  let arReal = Math.sqrt(dotVect(n2R.mmul(Ati).mmul(Ai).to1DArray(), n2) / dotVect(n3R.mmul(Ati).mmul(Ai).to1DArray(), n3));


  if (arReal === 0 || arVis === 0) {
    finalW = Math.ceil(w);
    finalH = Math.ceil(h);
  } else if (arReal < arVis) {
    finalW = Math.ceil(w);
    finalH = Math.ceil(finalW / arReal);
  } else {
    finalH = Math.ceil(h);
    finalW = Math.ceil(arReal * finalH);
  }
  return [finalW, finalH];
}
github mljs / feedforward-neural-networks / src / Layer.js View on Github external
backpropagation(delta, a) {
    this.dW = a.transpose().mmul(delta);
    this.db = Matrix.rowVector(delta.sum('column'));

    var aCopy = a.clone();
    return delta.mmul(this.W.transpose()).mul(aCopy.apply(this.derivate));
  }
github mljs / regression / src / regression / poly-fit-regression2d.js View on Github external
for (var i = 0; i <= this.order; ++i) {
      var limit = this.order - i;
      for (var j = 0; j <= limit; ++j) {
        var result = powColVector(x1, i).mulColumnVector(powColVector(x2, j));
        A.setColumn(col, result);
        col++;
      }
    }

    var svd = new SVD(A.transpose(), {
      computeLeftSingularVectors: true,
      computeRightSingularVectors: true,
      autoTranspose: false
    });

    var qqs = Matrix.rowVector(svd.diagonal);
    qqs = qqs.apply(function (i, j) {
      if (this.get(i, j) >= 1e-15) this.set(i, j, 1 / this.get(i, j));
      else this.set(i, j, 0);
    });

    var qqs1 = Matrix.zeros(examples, coefficients);
    for (i = 0; i < coefficients; ++i) {
      qqs1.set(i, i, qqs.get(0, i));
    }

    qqs = qqs1;

    var U = svd.rightSingularVectors;
    var V = svd.leftSingularVectors;

    this.coefficients = V.mmul(qqs.transpose())
github image-js / image-js / src / image / transform / warping.js View on Github external
let n33 = n3[2];


  let f = (1.0 / (n23 * n33)) * ((n21 * n31 - (n21 * n33 + n23 * n31) * u0 + n23 * n33 * u0 * u0) + (n22 * n32 - (n22 * n33 + n23 * n32) * v0 + n23 * n33 * v0 * v0));
  if (f >= 0) {
    f = Math.sqrt(f);
  } else {
    f = Math.sqrt(-f);
  }

  let A = new Matrix([[f, 0, u0], [0, f, v0], [0, 0, 1]]);
  let At = A.transpose();
  let Ati = inverse(At);
  let Ai = inverse(A);

  let n2R = Matrix.rowVector(n2);
  let n3R = Matrix.rowVector(n3);

  let arReal = Math.sqrt(dotVect(n2R.mmul(Ati).mmul(Ai).to1DArray(), n2) / dotVect(n3R.mmul(Ati).mmul(Ai).to1DArray(), n3));


  if (arReal === 0 || arVis === 0) {
    finalW = Math.ceil(w);
    finalH = Math.ceil(h);
  } else if (arReal < arVis) {
    finalW = Math.ceil(w);
    finalH = Math.ceil(finalW / arReal);
  } else {
    finalH = Math.ceil(h);
    finalW = Math.ceil(arReal * finalH);
  }
  return [finalW, finalH];