Search code examples
javascriptsigmoid

Sigmoid with Large Number in JavaScript


From what I understand you use a sigmoid function to reduce a number to the range of 0-1.

Using the function found in this library

function sigmoid(z) {
  return 1 / (1 + Math.exp(-z));
}

This works for a numbers 1-36. Any number higher than this will just return 1.

sigmoid(36) -> 0.9999999999999998
sigmoid(37) -> 1
sigmoid(38) -> 1
sigmoid(9000) -> 1

How do you increase the range so this function can handle a number larger than 36.


Solution

  • A sigmoid function is any function which has certain properties which give it the characteristic s-shape. Your question has many answers. For example, any function whose definition looks like

    const k = 2;
    function sigmoid(z) {
      return 1 / (1 + Math.exp(-z/k));
    }
    

    will fit the bill. The larger the k, the larger the useful domain.