问题描述
有人知道它的许可证与非免费 iPhone 应用程序兼容的良好实现吗?
Anyone know of a good implementation of this whose license is compatible with non-free iPhone apps?
正如这个问题所建议的,Boost 看起来非常棒.但据我所知,它仅在 C++ 中可用.
As suggested in this question, Boost looks absolutely wonderful. But as best I can tell, it is only available in C++.
推荐答案
不需要任何花哨的东西.任何具有良好 C99 数学库的平台(如 iphone)已经拥有您需要的一切——特别是 erfc
函数,它是一个轻微的变体:
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) {
return 0.5 * erfc(-x * M_SQRT1_2);
}
请注意,这是针对标准正态分布(即均值 = 0,方差 = 1),您需要使用适当的缩放比例 - 因此对于某些均值和方差,它将是:
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:
return 0.5 * erfc(((mean - x)/sqrt(variance)) * M_SQRT1_2);
如果您不需要双精度,请将双精度数更改为浮点数,使用erfcf
函数,并将文字更改为单精度文字.
If you don't need double precision, change the doubles to floats, use the erfcf
function, and change the literals to single-precision literals.
请记住,Objective-C 是对 C 的极其轻量级的扩展.每个 C 函数都是一个 Objective-C 函数,不需要包装或其他恶作剧.
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.
这篇关于目标 C 中的累积正态分布函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!