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