首页 > 其他 > 详细

[objective-c] 正态分布概率函数

时间:2014-04-06 13:00:16      阅读:505      评论:0      收藏:0      [点我收藏+]

网上找来的 mark之

No need for anything fancy. Any platform with a good C99 math library (like the iphone) already has everything you need -- specifically the erfc function, which is a slight variant:

#import <math.h>double cumulativeNormal(double x){return0.5* erfc(-x * M_SQRT1_2);}

Note this is for the standard normal distribution (i.e. mean = 0, variance = 1), you‘ll need to use the appropriate scaling -- so for some mean and variance, it will be:

return0.5* erfc(((mean - x)/sqrt(variance))* M_SQRT1_2);

If you don‘t need double precision, change the doubles to floats, use the erfcf function, and change the literals to single-precision literals.

Remember, Objective-C is an extremely light extension to C. Every C function is an Objective-C function, with no wrapping or other shenanigans required.

摘自http://stackoverflow.com/questions/2785944/cumulative-normal-distribution-function-in-objective-c

P.S. stackoverflow是我最近看的最多的网站……

[objective-c] 正态分布概率函数,布布扣,bubuko.com

[objective-c] 正态分布概率函数

原文:http://www.cnblogs.com/ImpGeek/p/3648361.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!