DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Customizable Sigmoid Function

09.18.2006
| 6880 views |
  • submit to reddit
        
/**
 * 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));
}