C#的正态性检验?

3

我们的代码库中有一个伪随机数生成器,我们认为它在产生符合给定正态分布的数字的方法上存在错误。

是否有C#实现的正态性测试可以在我的单元测试套件中使用,以确保该模块的行为符合预期?

我更喜欢具有以下签名的东西:

bool NormalityTest.IsNormal(IEnumerable<int> samples)

正常性是否是唯一重要的,或者随机性也同等重要? - Alan
如果您在C#中有一些随机性测试(如DIEHARD),那也会很有帮助,但是这个问题的重点是“这组样本值是否看起来正常”。 - gap
3个回答

1
你可以尝试这个:http://accord-framework.net/docs/html/T_Accord_Statistics_Testing_ShapiroWilkTest.htm 向下滚动到示例部分:
// Let's say we would like to determine whether a set
// of observations come from a normal distribution:
double[] samples =
{
    0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43,
    0.21, 4.75, 0.71, 1.52, 3.24, 0.93, 0.42, 4.97,
    9.53, 4.55, 0.47, 6.66
};

// For this, we can use the Shapiro-Wilk test. This test tests the null hypothesis 
// that samples come from a Normal distribution, vs. the alternative hypothesis that 
// the samples do not come from such distribution. In other words, should this test
// come out significant, it means our samples do not come from a Normal distribution.

// Create a new Shapiro-Wilk test:
var sw = new ShapiroWilkTest(samples);

double W = sw.Statistic; // should be 0.90050
double p = sw.PValue;    // should be 0.04209
bool significant = sw.Significant; // should be true

// The test is significant, therefore we should reject the null 
// hypothesis that the samples come from a Normal distribution.

1

1
你推荐这个包中的哪些函数?我在http://en.wikipedia.org/wiki/Normality_test上尝试查找类似Lilliefors测试的内容。 - gap
你的伪随机数生成器是否继承自.NET的Random类? - EkoostikMartin
没有...那有什么关系呢? - gap
因为这个库中MathNet.Numerics.Distributions命名空间中的许多类需要随机数生成器来执行此操作。同时,在.Net自定义RNG中,这是最佳实践。 - EkoostikMartin
我们尝试使用这个库来实现Kolmogorov-Smirnov检验,但结果却拒绝了我们通过直方图检查所接受的正态分布...你具体是如何建议使用这个库来回答问题的? - gap

0

我不知道有任何关于正态性测试数据的c-implementation。我曾经遇到过同样的问题,然后自己编写了一个程序。这个网页对我帮助很大。它是为在Excel中执行测试而编写的,但它提供了所有必要的系数(Royston)和逻辑。


这绝对是正确的想法...但我希望我能在我的nunit测试中访问它。 - gap

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接