Hi all,
I have an ongoing project in which I'm using the hdprod() function quite
often. Specifically, the syntax I'm using is something like
Q = hdprod(X, X)
For those unfamiliar: if X is a Txn matrix, the result Q is a T x n^2
matrix in which each row is the Kronecker product of the corresponding row
of X by itself. In other words, in this case each row of Q will be the
vectorised version of a symmetrix nxn matrix. In practice, this is the
(much faster and efficient) equivalent of
<hansl>
matrix Q = {}
loop i = .. cols(X)
xi = x[,i]
loop j = 1 .. cols(X)
Q = Q ~ (xi .* x[,j])
endloop
endloop
</hansl>
Now: I only need the non-repeated columns of Q. While this is easy enough
to accomplish by selecting the appropriate columns, it strikes me as a
very inefficient solution. In fact, each time you call hdprod() with
arguments 1 and 2 being equal, you get a matrix with (potentially) lots of
repeated columns and you perform the same multiplication more times than
you should.
Hence, my proposal: I'd like to modify hdprod() so that the second
argument becomes optional. If absent, it is understood to be equal to the
first one. In that case, the returned matrix will not have n^2 columns,
but only n x (n-1)/2, arranged appropriately. Note that this extension
would be completely backward-compatible.
Note: I'm not tackling for the moment the case where one of the two
arguments may be complex; I guess this can wait.
Any objections to this plan?
-------------------------------------------------------
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
-------------------------------------------------------