Created
June 23, 2015 08:03
-
-
Save mjac/628b8fb4dcca07e1e43a to your computer and use it in GitHub Desktop.
MySQL Normal Distribution CDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION IF EXISTS gauss_cdf; | |
DELIMITER // | |
CREATE FUNCTION gauss_cdf(mean float, stdev float, x float) RETURNS float | |
BEGIN | |
set @z = (x - mean) / stdev; | |
set @b1 = 0.319381530; | |
set @b2 = -0.356563782; | |
set @b3 = 1.781477937; | |
set @b4 = -1.821255978; | |
set @b5 = 1.330274429; | |
set @p = 0.2316419; | |
set @c = 0.39894228; | |
IF @z >= 0.0 THEN | |
set @t = 1.0 / ( 1.0 + @p * @z ); | |
return (1.0 - @c * exp(-@z * @z / 2.0) * @t * ( @t * ( @t * ( @t * ( @t * @b5 + @b4 ) + @b3 ) + @b2 ) + @b1 )); | |
ELSE | |
set @t = 1.0 / ( 1.0 - @p * @z ); | |
return ( @c * exp(-@z * @z / 2.0) * @t * ( @t * ( @t * ( @t * ( @t * @b5 + @b4 ) + @b3 ) + @b2 ) + @b1 )); | |
END IF; | |
END | |
// | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment