Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Mata slow?


From   Brendan Halpin <[email protected]>
To   [email protected]
Subject   st: Mata slow?
Date   Wed, 22 Nov 2006 17:04:04 +0000

I responded to Kit Baum's encouragement to investigate Mata, and
have re-written a small plugin in it. I'm impressed by how easy it
was to express parts of the task very concisely in Mata. However,
performance is poor, surprisingly so. Mata takes about 40 times as
long as the plugin.

Is this normal? 

The heart of the algorithm is the following nested loop. s1 and s2
are vectors, matrices A, B and C are predefined and matrix D is
filled from top-left iteratively, using A, B, C and values above
and to the left:

  for (i=2; i<=length(s1) + 1; i++) {
    for (j=2; j<=length(s2) + 1; j++) {
      D[i, j] = min((D[i,   j-1] + A[i, j],
                     D[i-1, j  ] + B[i, j],
                     D[i-1, j-1] + C[i, j] ));
      }
    }

Is there an obvious, more efficient way to express this?

Any tips for time-profiling Mata code?


Regards,

Brendan
-- 
Brendan Halpin,  Department of Sociology,  University of Limerick,  Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F2-025 x 3147
mailto:[email protected]  http://www.ul.ie/sociology/brendan.halpin.html
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index