Am 10.06.2021 um 17:55 schrieb Riccardo (Jack) Lucchetti:
On Thu, 10 Jun 2021, Sven Schreiber wrote:
> Am 10.06.2021 um 10:57 schrieb Riccardo (Jack) Lucchetti:
>> package. Note: for large input vectors (n > 5) the recursion approach
>> really is much slower than direct calculation, so there is quite a lot
>> of room for optimisation.
>>
>> Opinions?
>
> OK, so what's the use case?
I had written this in the context of a loop where I was comparing
models of size k chosen from a set of n regressors. But of course this
is more general than this. By the way, Octave has a similar function
(nchoosek, IIRC).
Right, a couple of remarks:
-
https://de.mathworks.com/help/matlab/ref/nchoosek.html
- in gretl we have the closely related native bincoeff() function
- The bincoeff(n,k) doc says that k>n leads to NA, but actually
bincoeff(2,3) resuls in an invalid argument error, so I guess the doc
must be adjusted. (Same for k<0.) But especially for matrix inputs
(which are treated element-per-element, although this could be made
clearer in the doc, too) this is a bit unfortunate since the whole
operation then fails if just one element is out of bounds.
- So our bincoeff function cannot be overloaded like Matlab's nchoosek
anymore, given that matrix inputs are already allowed, but handled and
interpreted differently.
- In the extra addon we also have the powerset function, but (a) that
operates on strings (arrays), and (b) it does not limit itself to
subsets of k elements only.
FWIW,
sven