How to use the ml-matrix.Matrix.columnVector 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
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,
          c,
github image-js / image-js / src / image / transform / warping.js View on Github external
let [x2, y2] = [0, widthRect - 1];
  let [x3, y3] = [heightRect - 1, widthRect - 1];
  let [x4, y4] = [heightRect - 1, 0];

  let S = new Matrix([
    [x1, y1, 1, 0, 0, 0, -x1 * X1, -y1 * X1],
    [x2, y2, 1, 0, 0, 0, -x2 * X2, -y2 * X2],
    [x3, y3, 1, 0, 0, 0, -x3 * X3, -y1 * X3],
    [x4, y4, 1, 0, 0, 0, -x4 * X4, -y4 * X4],
    [0, 0, 0, x1, y1, 1, -x1 * Y1, -y1 * Y1],
    [0, 0, 0, x2, y2, 1, -x2 * Y2, -y2 * Y2],
    [0, 0, 0, x3, y3, 1, -x3 * Y3, -y3 * Y3],
    [0, 0, 0, x4, y4, 1, -x4 * Y4, -y4 * Y4]
  ]);

  let D = Matrix.columnVector([X1, X2, X3, X4, Y1, Y2, Y3, Y4]);

  let svd = new SingularValueDecomposition(S);
  let T = svd.solve(D); // solve S*T = D
  let [a, b, c, d, e, f, g, h] = T.to1DArray();

  let Xt = new Matrix(heightRect, widthRect);

  for (let channel = 0; channel < this.channels; channel++) {
    for (let i = 0; i < heightRect; i++) {
      for (let j = 0; j < widthRect; j++) {
        Xt.set(i, j, projectionPoint(i, j, a, b, c, d, e, f, g, h, this, channel));
      }
    }
    newImage.setMatrix(Xt, { channel: channel });
  }
github mljs / regression / src / regression / poly-fit-regression2d.js View on Github external
constructor(inputs, outputs, options) {
    super();
    if (inputs === true) {
      // reloading model
      this.coefficients = Matrix.columnVector(outputs.coefficients);
      this.order = outputs.order;
      if (outputs.r) {
        this.r = outputs.r;
        this.r2 = outputs.r2;
      }
      if (outputs.chi2) {
        this.chi2 = outputs.chi2;
      }
    } else {
      options = Object.assign({}, defaultOptions, options);
      this.order = options.order;
      this.coefficients = [];
      this.X = inputs;
      this.y = outputs;

      this.train(this.X, this.y, options);