Hi,
I am facing a scalability problem when working with matrix elements.
Below is a fragment of the script I am working with.
</script>
nulldata 1000
scalar nobs_full = $nobs
scalar nmc = 400
...
# generate a matrix of zeros, with rows = number of obs, cols = number
of Monte Carlo runs
matrix M = zeros(nobs_full, nmc)
# outer loop for operations on rows (actually, series of data)
loop for j=1..nmc --progressive --quiet
# series-wise operations go here
...
genr y_new = constant + 0.5 * x1 + 0.5 * x2 # an example
...
#inner loop for operations on elements of matrix
loop for i=2..nobs_full --progressive --quiet
# element-wise operations go here
...
M[i,j] += exp(y_new[i]) * M[i-1,j] # an example
...
endloop
endloop
</script>
The amount of calculation is proportionate to matrix size (generate
series and perform element-wise operations), no regressions, no matrix
manipulations. I did some quick tests and here are the results:
* Create a matrix 1000x20, run 1000 iterations (inner loop) time 20
iterations (outer loop). Time: 7 seconds.
* Matrix 1000x40, 1000 iterations by 40 iterations. Time:33 seconds.
* Matrix 1000x100, 1000 iterations by 100 iterations. Time: 4 minutes 21
seconds.
It looks like the problem is not in the loops, but in the way gretl
handles matrices, because:
* Matrix 1000x40, 1000 iterations by 20 iterations (affecting only the
first 20 columns of the matrix). Time: 15 seconds.
* Matrix 1000x60, 1000 iterations by 20 iterations (affecting only the
first 20 columns of the matrix). Time: 24 seconds.
* Matrix 1000x100, 1000 iterations by 20 iterations (affecting only the
first 20 columns of the matrix). Time: 41 second.
Actually, I was planning to test a matrix of size 1000x400, but it would
have taken too much time.
By the way, I found no way to forcibly terminate a running script
(self-compiled version 1.9.5 running on Ubuntu Linux). It would be nice
to have a button (or hotkey, or something similar) for this purpose.
Regards,
Vitalie CIUBOTARU