Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Why is Mata much slower than MATLAB at matrix inversion?


From   Pradipto Banerjee <pradipto.banerjee@adainvestments.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Why is Mata much slower than MATLAB at matrix inversion?
Date   Mon, 23 Jul 2012 10:04:02 -0500

Patrick,

I had the same issue. I think different applications have their pros and cons. Both Stata and Matlab have their places.

Stata is great for data manipulation and data visualization, merging databases, or trying to quickly see whether a few variables are related to others, carrying out variety of regressions both across time and cross-section, i.e. primarily to build insights from a database without first building a whole set of tools around a database.

On the other hand, once all the insights are developed in Stata, Matlab is perhaps preferable to build the rest of the application because it is faster, has many use toolboxes like optimization, integrates well with the engineering & financial world (e.g. Bloomberg, lots of financial databases & APIs), programming is much easier, awesome editor and is very good as a single environment to develop a complete package.

Thanks.


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Patrick Roland
Sent: Saturday, July 21, 2012 4:29 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Why is Mata much slower than MATLAB at matrix inversion?

As a brief followup, and since StataCorp have responded, I tested
matrix multiplication too. Stata 12.0 takes fully 100 times longer to
multiply two 2000x2000 matrices than MATLAB R2011b.

This code took ~21 seconds in Mata:

mata
j = rnormal(2000,2000,0,1)
timer_on(1)
g =j*j'
timer_off(1)
timer()
end

This code took ~0.21 seconds in MATLAB:

j = randn(2000,2000);
tic;
g = j*j';
toc;

Happy to stand corrected if I've made a mistake.


On Fri, Jul 20, 2012 at 6:19 PM, Richard Herron
<richard.c.herron@gmail.com> wrote:
> Snap. Yes, your m from -runiform()- will certainly be invertible.
>
> Richard Herron
>
>
> On Fri, Jul 20, 2012 at 7:14 PM, Patrick Roland
> <patrick.rolande@gmail.com> wrote:
>> To be clear, my point was that all Mata matrix inverse functions are
>> slower than MATLAB. It does seem though that this is not true for
>> small matrices (e.g. 100x100), but the difference is easily an order
>> of magnitude when it comes to larger matrices (2000x2000).
>>
>> The fact that I compared cholinv() and a general inverse function
>> should be to Mata's favor, since cholinv should presumably be faster
>> if it exploits the special structure of the matrix.
>>
>> X'X is positive definite if X is invertible (as in my example),
>> because a'X'Xa  = (Xa)'(Xa) > 0.
>>
>> On Fri, Jul 20, 2012 at 2:48 PM, David M. Drukker <ddrukker@stata.com> wrote:
>>> Patrick Roland <patrick.rolande@gmail.com> posted that the Mata function
>>> -cholinv()- is slower than a Matlab function for large matrices.
>>>
>>> Others have discussed some issues with Patrick's example.  Despite these
>>> issues, we took Patrick's post seriously, looked at the code, and found
>>> something that could be sped up.
>>>
>>> We will release a faster version of -cholinv()- in an upcoming executable
>>> update.
>>>
>>> Note that any speed difference related to -cholinv()- is only noticeable for
>>> large matrices.  For small matrices, such as variance-covariance matrices
>>> for models with 100 or fewer parameters, the difference is much harder to
>>> find.  For example, the computation takes about .001 seconds on my machine.
>>>
>>> Best,
>>> David
>>> ddrukker@stata.com
>>>
>>>
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/statalist/faq
>>> *   http://www.ats.ucla.edu/stat/stata/
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

 This communication is for informational purposes only. It is not intended to be, nor should it be construed or used as, financial, legal, tax or investment advice or an offer to sell, or a solicitation of any offer to buy, an interest in any fund advised by Ada Investment Management LP, the Investment advisor.  Any offer or solicitation of an investment in any of the Funds may be made only by delivery of such Funds confidential offering materials to authorized prospective investors.  An investment in any of the Funds is not suitable for all investors.  No representation is made that the Funds will or are likely to achieve their objectives, or that any investor will or is likely to achieve results comparable to those shown, or will make any profit at all or will be able to avoid incurring substantial losses.  Performance results are net of applicable fees, are unaudited and reflect reinvestment of income and profits.  Past performance is no guarantee of future results. All f!
 inancial data and other information are not warranted as to completeness or accuracy and are subject to change without notice.

Any comments or statements made herein do not necessarily reflect those of Ada Investment Management LP and its affiliates. This transmission may contain information that is confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index