How to use the ml-matrix.Matrix.eye 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 mljs / pca / src / __tests__ / iris.js View on Github external
it('loadings should be orthogonal', function () {
    let m = pca
      .getLoadings()
      .transpose()
      .mmul(pca.getLoadings())
      .round();
    expect(m.sub(Matrix.eye(4, 4)).sum()).toStrictEqual(0);
  });
github mljs / regression / src / regression / kernel-ridge-regression.js View on Github external
this.alpha = outputs.alpha;
      this.inputs = outputs.inputs;
      this.kernelType = outputs.kernelType;
      this.kernelOptions = outputs.kernelOptions;
      this.kernel = new Kernel(outputs.kernelType, outputs.kernelOptions);
    } else {
      inputs = Matrix.checkMatrix(inputs);
      options = Object.assign({}, defaultOptions, options);

      const kernelFunction = new Kernel(
        options.kernelType,
        options.kernelOptions
      );
      const K = kernelFunction.compute(inputs);
      const n = inputs.rows;
      K.add(Matrix.eye(n, n).mul(options.lambda));

      this.alpha = solve(K, outputs);
      this.inputs = inputs;
      this.kernelType = options.kernelType;
      this.kernelOptions = options.kernelOptions;
      this.kernel = kernelFunction;
    }
  }