0
Halton序列的伪代码可以在here找到。我写了一个函数来做这件事,但由于某种原因检查了第四维Halton序列的Matlab结果,我的数字不匹配,我不知道为什么。这里是我的代码:实现四维Halton序列
double Halton_Seq(int index, double base){
double f = 1, r;
while(index > 0){
f = f/base;
r = r + f*(fmod(index,base));
index = index/base;
}
return r;
}
以下是前10个结果,我得到:
1
0.25
0.5
0.75
0.0625
0.3125
0.5625
0.8125
0.125
0.375
这里是前10个结果MATLAB得到:
Columns 1 through 2
0 0.5000
Columns 3 through 4
0.2500 0.7500
Columns 5 through 6
0.1250 0.6250
Columns 7 through 8
0.3750 0.8750
Columns 9 through 10
0.0625 0.5625
除了不初始化r之外,您的C++代码还可以。你的Matlab代码是生成基2的序列而不是4 – samgak
@samgak你确定,我设置d = 4,所以我认为它是基4 – Scooby