/* Mid-point version of Latin Hypercube up to dim=1,2,3,..,M */ /* This program is simple but requires lots of memory. */ new; cls; nn=10; dim=3; x=LHmp(nn,dim); library pgraph; graphset; _plctrl=-1; xtics(0,1,0.1,0); ytics(0,1,0.1,0); ztics(0,1,0.1,0); xyz(x[.,1],x[.,2],x[.,3]); /* ** LHmp.txt - Latin Mid Points U(0,1). ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Calculates Latin Mid-point numbers in a very easy way. New algorithm. ** ** Format: x=LHmp(nn,dim); ** ** Input: nn scalar, max number of index (1,2,3,...,nn) ** ** dim scalar, dimension (1,...,dim) ** ** ** Output: x 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. */ proc LHmp(nn,dim); local x,b,n,z,y,indexvec,i,index,U; /* convert x(base 10) to y(base b) */ x=seqa(1,1,nn^dim-1); b=nn; n=maxc(log(x)/log(b))+1; z=reshape(b,n,rows(x)); y=rev(recserrc(x,z))'; indexvec=y+1; /* shift all elements by 1 */ indexvec=ones(1,dim)|indexvec; /* insert 1's at the 1st row */ /* representative mid-point values */ U=(indexvec-0.5)/nn; /* randomize the order as a row */ x=zeros(nn^dim,dim); i=1; do while i<=nn^dim-1; index=ceil((nn^dim-(i-1))*rndu(1,1)); x[i,.]=U[index,.]; if index==1; U=U[2:rows(U),.]; elseif index==rows(U); U=U[1:rows(U)-1,.]; else; U=U[1:(index-1) (index+1):rows(U),.]; endif; i=i+1; endo; x[nn^dim,.]=U; retp(x); endp;