本文介绍了目标C中的累积正态分布函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道这个许可证与非免费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 function,并将文字更改为单精度文字。

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中的累积正态分布函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:38