Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: computation time of function lsqnonlin Date: Fri, 13 Sep 2013 19:09:06 +0000 (UTC) Organization: The MathWorks Inc Lines: 84 Message-ID: <l0vnsi$jkk$1@newscl01ah.mathworks.com> References: <l0u1au$ei4$1@newscl01ah.mathworks.com> <l0v783$po$1@newscl01ah.mathworks.com> <l0v8n7$so5$1@newscl01ah.mathworks.com> <l0vn9q$8pp$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: rubyext-02-ls.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1379099346 20116 172.20.102.178 (13 Sep 2013 19:09:06 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 13 Sep 2013 19:09:06 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 869951 Xref: news.mathworks.com comp.soft-sys.matlab:802399 "Toan Cao" <toancv3010@gmail.com> wrote in message <l0vn9q$8pp$1@newscl01ah.mathworks.com>... > "Steven_Lord" <slord@mathworks.com> wrote in message <l0v8n7$so5$1@newscl01ah.mathworks.com>... > > > > > > "Rakesh Kumar" <r.kumar_spamhole@mathworks.com> wrote in message > > news:l0v783$po$1@newscl01ah.mathworks.com... > > > "Toan Cao" <toancv3010@gmail.com> wrote in message > > > <l0u1au$ei4$1@newscl01ah.mathworks.com>... > > >> Hi, > > >> I write an objective function in both m-file (fileA1.m) and C mex file > > >> (fileA2.c). Given an input to this objective function, computation time > > >> in C mex file is 15 times faster than that of m- file. However, when i > > >> use the objective function in function lsqnonlin of Matlab, computation > > >> time which lsqnonlin gets a optimal solution is almost the same for both > > >> files (~101 minutes for C mex file and ~104 minutes for m-file). > > >> I hope when i use C mex file, i will save more time for optimization > > >> process, but it is not. > > >> Can you help me explain why lsqnonlin spends almost the same computation > > >> time? > > >> I would like to understand more how lsqnonlin of Matlab works to reduce > > >> its time? > > >> Thanks in advance! > > >> > > >> Toan > > > > > > Hi Toan, > > > This is unexpected. First, I would suggest to compare the #iterations and > > > #function evaluations in two scenarios (just to make sure we have same > > > implementation in MATLAB and C). If these numbers are similar, then I > > > would profile and see where the time is spent in two scenarios. Can you > > > report back here with your findings? Thanks! > > > > In addition, make sure you're comparing apples and oranges. Do fileA1.m and > > fileA2.$MEXEXT return the EXACT SAME, down to the last bit, results given > > the exact same inputs? Even a small difference in the return values could > > affect the path in the solution space the optimization routines follow, if I > > remember correctly. > > > > -- > > Steve Lord > > slord@mathworks.com > > To contact Technical Support use the Contact Us link on > > http://www.mathworks.com > > Hi Rakesh, > > When i set just for 5 iteration , following outputs of optimization process make me more confusion: > ----------------------------------------------------------------------------------------- > m-file: > First-Order Norm of > Iteration Func-count Residual optimality Lambda step > 0 1 9.02706 1.1 0.02 > 1 4 8.15864 0.775 2 0.715913 > 2 6 7.12331 0.592 20 0.19392 > 3 7 6.6927 0.546 2 0.147436 > 4 9 6.4763 0.513 20 0.124842 > 5 10 6.37183 0.486 2 0.112678 > 6 12 6.28601 0.465 20 0.106625 > Elapsed time is 3240.325396 seconds. > > C mex file: > > First-Order Norm of > Iteration Func-count Residual optimality Lambda step > 0 1 9.02706 1.1 0.02 > 1 4 8.15864 0.775 2 0.715913 > 2 6 7.12331 0.592 20 0.19392 > 3 7 6.6927 0.546 2 0.147436 > 4 9 6.4763 0.513 20 0.124842 > 5 10 6.37183 0.486 2 0.112678 > 6 12 6.28601 0.465 20 0.106625 > Elapsed time is 8275.102153 seconds. > ----------------------------------------------------------------------------------------- > Uhmmmm, as you see every parameters are similar but it is terrible when elapsed time for C mex file is even longer than that of m-file for above case. > > Hi Steve Lord, > There are some things relating to what you say. In Jacobian matrix returned by the objective function, when i use Matlab to compare element by element between these two matrices of 2 files, Matlab indicates some different values among elements. > However, if i run comparison two times of the same output Jacobian matrices , locations of difference at each running time are not the same. Then, i check some locations , some values of 2 elements are different at last digit as Matlab indicates. (for example: 4.559150742630094 vs 4.559150742630095), some values are the same (for example: 1.641766402933731 vs 1.641766402933731). > Therefore, i think this is due to machine error between values returned by c mex file and m-file. But i can not still explain where is the problem relating computation time of lsqnonlin. > > Looking forward to your reply. > Toan What about the profiler report? Can you post the profiler report for top 10 self-time for functions and how many times they are called?