On 14/09/2023 14:16, Cottrell, Allin wrote:
On Wed, Sep 13, 2023 at 8:11 AM Riccardo (Jack) Lucchetti
<p002264(a)staff.univpm.it> wrote:
> Well, Luca and I were thinking of using them in the upcoming new version
> of the ParMA package, and I believe Marcin was in favour too.
And Peter Summers added, "FWIW, I've used Matlab's dec2bin for running
Markov-switching models, so I like this new functionality too."
I notice that Matlab's dec2bin employs a string composed of '0's and
'1's to represent a binary number. Maybe we want to do that too? In
its native form an unsigned integer occupies 4 bytes = 32 bits. If
converted a la Matlab that goes up to 33 bytes = 264 bits (allowing
for the terminating NUL byte). As currently documented in git, our
representation occupies 32 * 8 = 256 bytes or 2048 bits, since a
double is used to represent each bit of the integer. This seems kinda
profligate in terms of the storage used.
I agree. However, our current implementation makes it possible to
convert several items at once, as in, for example "dec2bin(seq(1,6)')"
or "bin2dec(I(4))".
A less contrived example could be given by considering a non-recursive
algorithm for computing all possible binary vectors of size n that sum
to k (useful, for example in conditional or fixed-effects logit models):
<hansl>
n = 5
k = 3
tmp = dec2bin(seq(2^k-1, 2^n-1)')[,1:n]
eval selifr(tmp, sumr(tmp) .= k)
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------