Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Customizable sigmoid function (See related posts)

/**
 * Calculates S-curve for point x in the interval 0 .. normV
 * 
 * @param x input coordinate
 * @param normV scale value which corresponds to 1.0 if x is normalized
 * @param sharpness adjusts steepness of curve (value of 1 equals undistorted sigmoid)
 *
 * @return sigmoid for point X
 */
public float sigmoid(float x, float normV, float sharpness) {
  x=(x/normV*2-1)*5*sharpness;
  return 1.0f / (1.0f + (float)Math.exp(-x));
}

public double sigmoid(double x, double normV, double sharpness) {
  x=(x/normV*2-1)*5*sharpness;
  return 1.0 / (1.0 + Math.exp(-x));
}

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts