On Fri, 30 Jul 1999, CHASALOW, SCOTT [AG/2165] wrote:
> the same answers.) Generating (but not doing anything interesting with)
> the 15504 combinations of 1:20 taken 5 at a time took each function
> around 45 seconds on a 300 MHz Pentium running S-PLUS 4.5 under Win NT.
> For much larger problems, I strongly second Bill's comment that this
> "is the sort of territory where dynamically loaded code starts to become
> unavoidable."
As Bill probably has long forgotten, there is C code to do precisely
that in the lqs function in the V&R3 MASS library, as in
/*
Find all subsets of size k in order: this gets a new one each call
*/
void
next_set(Sint * x, int n, int k)
{
int i, j, tmp;
j = k - 1;
tmp = x[j]++;
while (j > 0 && x[j] >= n - (k - 1 - j)) tmp = ++x[--j];
for (i = j + 1; i < k; i++) x[i] = ++tmp;
}
and you will need to look at the code to see how it is initialized
(x is 1:k). (This is often called a Gray code algorithm.)
And although I originally wrote this as a loop in S, doing 100000 subsets
meant that I needed to do it all in C.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|