How to use the ml-matrix.Matrix.rand 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 / feedforward-neural-networks / src / Layer.js View on Github external
var derFunction = params > 1 ? (val) => selectedFunction.derivate(val, options.activationParam) : selectedFunction.derivate;

    this.activationFunction = function (i, j) {
      this.set(i, j, actFunction(this.get(i, j)));
    };
    this.derivate = function (i, j) {
      this.set(i, j, derFunction(this.get(i, j)));
    };

    if (options.model) {
      // load model
      this.W = Matrix.checkMatrix(options.W);
      this.b = Matrix.checkMatrix(options.b);
    } else {
      // default constructor
      this.W = Matrix.rand(this.inputSize, this.outputSize);
      this.b = Matrix.zeros(1, this.outputSize);

      this.W.apply(function (i, j) {
        this.set(i, j, this.get(i, j) / Math.sqrt(options.inputSize));
      });
    }
  }