/* Scrambled Improved LHS-Sobol Sequence */ /* Notice:Very slow. Wait for a while... */ new; cls; nn=5; dim=3; x=siLHSSobol(nn,dim); library pgraph; graphset; pqgwin auto; _plctrl=-1; call hist(x[.,1],19); call hist(x[.,2],19); call hist(x[.,3],19); xy(x[.,1],x[.,2]); xy(x[.,2],x[.,3]); xy(x[.,1],x[.,3]); xyz(x[.,1],x[.,2],x[.,3]); /* ** siLHSHalton.txt - Scrambled Improved LHS-Sobol Sequence. ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Calculates Scrambled Improved LHS-Sobol numbers in a very easy way. ** ** Format: xx=siLHSSobol(nn,dim); ** ** Input: nn scalar, max number of index (1,2,3,...,nn) ** ** dim scalar, dimension (1,...,dim) ** ** ** Output: xx matrix, (nn^dim) x (dim) of resulting U(0,1) numbers ** ** Notice: It takes lots of memory to run. Light version of GAUSS will not work in most cases. ** ** This procedure uses procedure 'dimindex3' with 'rerankindx' and 'Sobol' inside. */ proc siLHSSobol(nn,dim); local y,x,bb,SO,xx,j,i; {y,x,bb}=dimindex3(nn,dim); /* y: location parameter of Hypercube */ /* x: ordering parameter in each quasi sequence */ /* bb: dimension parameter in each quasi sequence */ SO=Sobol((nn^dim),dim); xx=zeros(nn^dim,dim); j=1; do while j<=dim; i=1; do while i<=nn^dim; if rndu(1,1)<0.5; xx[i,j]=SO[x[i,j],bb[i,j]]/nn+(y[i,j]-1)/nn; /* Now, use bb as random dimension index */ /* [ in each cell ]+[ location ] */ else; xx[i,j]=(1/nn-SO[x[i,j],bb[i,j]]/nn)+(y[i,j]-1)/nn; /* [ in each cell ]+[ location ] */ endif; i=i+1; endo; j=j+1; endo; retp(xx); endp; proc Sobol(nn,dim); local x,lastq,Sseed,maxdim,seed,v,p,m,i,j,k,l,jj,newv,inc,rec,tempseed; if dim<2 or dim>40; errorlog "ERROR: Dimension number must be an integer where 2 <= dim <= 40."; retp("."); endif; x=zeros(nn,dim); lastq=zeros(1,dim); Sseed=0; max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21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 7 11 13 29 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 7 5 7 11 113 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 5 3 15 19 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 1 1 9 27 89 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 3 7 31 15 45 23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 3 9 9 25 107 39 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; p={1, 3, 7, 11, 13, 19, 25, 37, 59, 47, 61, 55, 41, 67, 97, 91, 109, 103, 115, 131, 193, 137, 145, 143, 241, 157, 185, 167, 229, 171, 213, 191, 253, 203, 211, 239, 247, 285, 369, 299}; i=1; v[i,1:30]=ones(1,30); i=2; do while i<=maxdim; m=sumc(p[i].>=(2^seqa(1,1,9))); j=p[i]; inc=zeros(m,1); k=m; do while k>=1; jj=floor(j/2); inc[k]=(j/=2*jj); j=jj; k=k-1; endo; j=m+1; do while j<=30; newv=v[i,j-m]; l=1; k=1; do while k<=m; l=2*l; if inc[k]; newv=eor(newv,l*v[i,j-k]); endif; k=k+1; endo; v[i,j]=newv; j=j+1; endo; i=i+1; endo; l=1; j=30-1; do while j>=1; l=2*l; v[1:dim,j]=v[1:dim,j]*l; j=j-1; endo; rec=1/(2*l); if seed==Sseed+1; l=low0(seed); elseif seed<=Sseed; Sseed=0; l=1; lastq[1:dim]=0; tempseed=Sseed; do while tempseed<=seed-1; l=low0(tempseed); i=1; do while i<=dim; lastq[i]=eor(lastq[i],v[i,l]); i=i+1; endo; tempseed=tempseed+1; endo; l=low0(seed); elseif Sseed+1rows(b2); b2=zeros(rows(a2)-rows(b2),1)|b2; elseif rows(a2)