[R] quasi-random sequences

Duncan Murdoch murdoch at stats.uwo.ca
Sat Apr 26 13:14:18 CEST 2008

baptiste Auguié wrote:
> Dear list useRs,
> I have to generate a random set of coordinates (x,y) in [-1 ; 1]^2  
> for say, N points. At each of these points is drawn a circle (later  
> on, an ellipse) of random size, as in:
The quasi-random sequences are useful for integration, but they're not 
random in the sense of being unpredictable.

Here's an idea for a sequence that might work for you:  divide the 
square into an n x n grid of smaller squares.  Randomly select a smaller 
square, then uniformly select a point within it.  (Or just permute the 
list of all n^2 squares, and proceed through the permuted list.)

This won't guarantee a separation, but it will tend to lead to one.  If 
you want a guarantee, then only select from squares with even coordinates.

Once you've selected all the squares in the grid, go to a 2n x 2n grid, 
and repeat.  (If you are doing the "even coordinates" modification, 
you'll have had to
select non-uniformly for this to work.)

Duncan Murdoch
>> N <- 100
>> positions <- matrix(rnorm(2 * N, mean = 0 , sd= 0.5), nrow=N)
>> sizes<-rnorm(N, mean = 0 , sd= 1)
>> plot(positions,type="p",cex=sizes)
> My problem is to avoid collisions (overlap, really) between the  
> points. I would like some random pattern, but with a minimum  
> exclusion distance. In looking up "Numerical recipes in C", I found  
> out about some Sobol quasi-random sequences, which one can call from  
> the gsl package,
>> library(gsl)
>> g <- qrng_alloc(type="sobol",dim=2)
>> qrng_get(g,n= N) ->xy
>> plot((xy),t="p",cex=0.5)
> but this does not look very random: I clearly see some pattern  
> (diagonals, etc...), and even the non-overlapping condition is not  
> impressive.
> One (painful) way I can foresee is to check the distance between each  
> symbol and the others, and move the overlapping ones in a recursive  
> manner. Before delving into this, I wanted to check I'm not  
> overlooking something in the rgl quasi-random sequences, or missing a  
> more obvious way to generate such patterns. Perhaps solving an  
> electrostatic problem with a potential both attractive at long  
> distances and repulsive at short distances is a better way? I have a  
> vague recollection of hearing that somewhere to position points  
> evenly on a sphere.
> Thanks for any comment / suggestion,
> Baptiste
> _____________________________
> Baptiste Auguié
> Physics Department
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
> Phone: +44 1392 264187
> http://newton.ex.ac.uk/research/emag
> http://projects.ex.ac.uk/atto
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list