On Sat, 16 Jun 2018, Henrique Andrade wrote:
I would like to make some speed tests using the approaches suggested
by me
and Jack before we decide the best way (in terms of speed) to use the
powerset function inside Gretl. I think we could consider using C code too
(the powerset is really a bottleneck when we have more than 15 variables to
combine).
I guess that the computational cost of the combinatorics is probably
comparable to the actual CPU usage for estimation. For example:
<hansl>
set verbose off
function matrices AltPSetMat(matrix X)
if rows(X) == 0
matrices PowerSet = defarray({})
else
matrix Set = msortby(uniq(vec(X)), 1)
n = rows(Set)
N = 2^n
matrices PowerSet = array(N)
if n == 1
PowerSet[1] = {}
PowerSet[2] = Set[1]
else
tmp = AltPSetMat(Set[1:n-1])
PowerSet = tmp
loop i = 1 .. nelem(tmp) --quiet
PowerSet += tmp[i] ~ Set[n]
endloop
endif
endif
return PowerSet
end function
open mroz87.gdt --quiet
list X = 3 4 5 6 10 11 15 16 18 19
matrix mx = X
set stopwatch
matrices C = AltPSetMat(mx)
t0 = $stopwatch
n = nelem(C)
bestbic = $huge
best = 0
loop i = 1 .. n --quiet
xi = C[i]
list Z = xi
ols WW const Z --quiet
if $bic < bestbic
best = i
bestbic = $aic
list bestZ = $xlist
endif
endloop
t1 = $stopwatch
print t0 t1
print best n
ols WW bestZ
</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
-------------------------------------------------------