Skip to content

Instantly share code, notes, and snippets.

@denpazakura
Created December 6, 2023 11:58
Calculates probability density, assuming normal distribution
# The normal probability density function (PDF) is used in statistics to calculate the probability of a specific value occurring in a normal distribution.
func normalProbabilityDensityFunction(x: Double, mean: Double, stdDev: Double) -> Double {
let power = pow((x - mean), 2)
let numerator = exp(-1.0 * power / (2.0 * stdDev * stdDev))
let denominator = 2.0 * Double.pi * stdDev * stdDev
return 1.0 / sqrt(denominator) * numerator
}
print(normalProbabilityDensityFunction(x: 60, mean: 64.43, stdDev: 2.99))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment