我想使用Halton序列在[0,1]上创建一个包含M
“均匀”分布的数字的向量。我曾经尝试过这种方法,但是它又产生了相同的数字……我该如何改善呢?我想我像wikipedia中那样做。
u=double(zeros(M,1));
for index= 1:M
i=index;
r=0;
f=1;
while true
if not(i>0)
break;
end
f=double(f)./double(base);
r=r+f.*(mod(i,base));
i= floor(double(i)./double(base));
endwhile
u(index)=r;
这是我到目前为止所拥有的,这要归功于下面发布的解决方案。它创建了一个序列,但是这个序列在[0,1]上是不一致的,任何想法为何?
从Halton序列的伪代码中,我想您可以像下面那样调整while
循环,然后重试
while true
if not(index>0 && number<M+1)
break;
end
f=double(f)./double(base);
r=r+f.*(mod(index,base))
index= floor(index./base);
u(number)=r;
number=number+1;
end