Add Class

Add ( )

activation
(
  • name
  • activation
  • derivative
)

Add a custom activation function.

  • name String

    the name of the new activation function.

  • activation Function

    the activation function.

  • derivative Function

    the derivative of this activation function.

Example

Add.activation('myfunc',
  (x) => {
    if (x <= 0) {
      return 0;
    } else {
      return 1;
    }
  },
  (x) => {
    return 0;
  }
);
let nn = new Dann();
nn.outputActivation('myfunc');
nn.log();

loss
(
  • name
  • loss
)

Add a custom loss function.

  • name String

    the name of the new loss function.

  • loss Function

    the loss function.

Example

Add.loss('myfunc',
  (predictions, target) => {
    let sum = 0;
    let ans = 0;
    let n = target.length;
    for (let i = 0; i < n; i++) {
      let y = target[i];
      let yHat = predictions[i];
      sum += abs(y - yHat);
    }
    ans = sum / n;
    return ans;
  }
);
let nn = new Dann();
nn.setLossFunction('myfunc');
nn.log();