<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263859</link>
    <title>MATLAB Central Newsreader - Speeding up Matlab</title>
    <description>Feed for thread: Speeding up Matlab</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 22 Oct 2009 14:01:04 -0400</pubDate>
      <title>Speeding up Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263859#689014</link>
      <author>Hugh </author>
      <description>Hi there,&lt;br&gt;
&lt;br&gt;
I have the following code which seeks to find the optimal solution to a rpoblem. Using a linear search over a hyperbox. The problem is I need a reasonably good granularity 1000+ on each parameter but becasue the scale of the problem rises exponentially with the granularity used this soon makes the problem prohibitively expensive in terms of computational time. Is there an in built matlab function I an use which will speed this process up?&lt;br&gt;
&lt;br&gt;
function [Result] =PrimePermOp(tau,Y)&lt;br&gt;
tic;&lt;br&gt;
tau=tau.';&lt;br&gt;
Y=Y.';&lt;br&gt;
&lt;br&gt;
nObs=length(Y);&lt;br&gt;
&lt;br&gt;
z=1;&lt;br&gt;
&lt;br&gt;
for(j=1:10)&lt;br&gt;
&lt;br&gt;
L5=j/200+0.01;&lt;br&gt;
&lt;br&gt;
for(k=1:10)&lt;br&gt;
&lt;br&gt;
L4=k/200+0.01;&lt;br&gt;
&lt;br&gt;
for(l=1:10)&lt;br&gt;
&lt;br&gt;
L3=l/200+0.01;&lt;br&gt;
&lt;br&gt;
for(m=1:10)&lt;br&gt;
&lt;br&gt;
L2=m/200+0.01;&lt;br&gt;
&lt;br&gt;
for(n=1:10)&lt;br&gt;
&lt;br&gt;
L1=n/200+0.01;&lt;br&gt;
&lt;br&gt;
G= [ones(nObs,1) L1*(1-exp(-tau./L1))./(tau) (1-exp(-((tau-L2).^2)/L3))./(((tau-L2).^2)/L3) (1-exp(-((tau-L4).^2)/L5))./(((tau-L4).^2)/L5) ];&lt;br&gt;
%c0(1)+c0(2)*c0(5)*(1-exp(-xdata./c0(5)))./(xdata) + c0(3)*(1-exp(-((xdata-c0(6)).^2)/c0(7)))./(((xdata-c0(6)).^2)/c0(7))+ c0(4)*(1-exp(-((xdata-c0(8)).^2)/c0(9)))./(((xdata-c0(8)).^2)/c0(9));&lt;br&gt;
&lt;br&gt;
alpha =G\Y;&lt;br&gt;
u=Y-G*alpha;&lt;br&gt;
stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G)));&lt;br&gt;
Sum_u2 = sum(u.^2);&lt;br&gt;
error2=(Y-G*alpha).^2;&lt;br&gt;
error2 = sum(error2);&lt;br&gt;
Res(z,:) = [Sum_u2 alpha' L1 L2 L3 L4 L5 error2];&lt;br&gt;
z=z+1;&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
optim=find(Res(:,11)==min(Res(:,11)));&lt;br&gt;
%Result=Res(optim,2:end)&lt;br&gt;
Result=toc;</description>
    </item>
    <item>
      <pubDate>Thu, 22 Oct 2009 14:35:14 -0400</pubDate>
      <title>Re: Speeding up Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263859#689027</link>
      <author>Bogdan Cristea</author>
      <description>&quot;Hugh &quot; &amp;lt;h_a_patience@hotmail.com&amp;gt; wrote in message &amp;lt;hbpoj0$5ld$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi there,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have the following code which seeks to find the optimal solution to a rpoblem. Using a linear search over a hyperbox. The problem is I need a reasonably good granularity 1000+ on each parameter but becasue the scale of the problem rises exponentially with the granularity used this soon makes the problem prohibitively expensive in terms of computational time. Is there an in built matlab function I an use which will speed this process up?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function [Result] =PrimePermOp(tau,Y)&lt;br&gt;
&amp;gt; tic;&lt;br&gt;
&amp;gt; tau=tau.';&lt;br&gt;
&amp;gt; Y=Y.';&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; nObs=length(Y);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; z=1;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for(j=1:10)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L5=j/200+0.01;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for(k=1:10)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L4=k/200+0.01;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for(l=1:10)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L3=l/200+0.01;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for(m=1:10)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L2=m/200+0.01;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for(n=1:10)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; L1=n/200+0.01;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; G= [ones(nObs,1) L1*(1-exp(-tau./L1))./(tau) (1-exp(-((tau-L2).^2)/L3))./(((tau-L2).^2)/L3) (1-exp(-((tau-L4).^2)/L5))./(((tau-L4).^2)/L5) ];&lt;br&gt;
&amp;gt; %c0(1)+c0(2)*c0(5)*(1-exp(-xdata./c0(5)))./(xdata) + c0(3)*(1-exp(-((xdata-c0(6)).^2)/c0(7)))./(((xdata-c0(6)).^2)/c0(7))+ c0(4)*(1-exp(-((xdata-c0(8)).^2)/c0(9)))./(((xdata-c0(8)).^2)/c0(9));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; alpha =G\Y;&lt;br&gt;
&amp;gt; u=Y-G*alpha;&lt;br&gt;
&amp;gt; stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G)));&lt;br&gt;
&amp;gt; Sum_u2 = sum(u.^2);&lt;br&gt;
&amp;gt; error2=(Y-G*alpha).^2;&lt;br&gt;
&amp;gt; error2 = sum(error2);&lt;br&gt;
&amp;gt; Res(z,:) = [Sum_u2 alpha' L1 L2 L3 L4 L5 error2];&lt;br&gt;
&amp;gt; z=z+1;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; optim=find(Res(:,11)==min(Res(:,11)));&lt;br&gt;
&amp;gt; %Result=Res(optim,2:end)&lt;br&gt;
&amp;gt; Result=toc;&lt;br&gt;
&lt;br&gt;
I don't know if there is a built in function doing the same computation, however I would advise to write your own C/C++ routine and interface this routine with Matlab. You could also use Matlab profiler to find what is the most computationally expensive part of your program and implement in C only that part.</description>
    </item>
    <item>
      <pubDate>Fri, 23 Oct 2009 08:39:03 -0400</pubDate>
      <title>Re: Speeding up Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263859#689205</link>
      <author>Hugh </author>
      <description>&quot;Bogdan Cristea&quot; &amp;lt;cristeab@gmail.com&amp;gt; wrote in message &amp;lt;hbpqj2$iad$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Hugh &quot; &amp;lt;h_a_patience@hotmail.com&amp;gt; wrote in message &amp;lt;hbpoj0$5ld$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi there,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have the following code which seeks to find the optimal solution to a rpoblem. Using a linear search over a hyperbox. The problem is I need a reasonably good granularity 1000+ on each parameter but becasue the scale of the problem rises exponentially with the granularity used this soon makes the problem prohibitively expensive in terms of computational time. Is there an in built matlab function I an use which will speed this process up?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; function [Result] =PrimePermOp(tau,Y)&lt;br&gt;
&amp;gt; &amp;gt; tic;&lt;br&gt;
&amp;gt; &amp;gt; tau=tau.';&lt;br&gt;
&amp;gt; &amp;gt; Y=Y.';&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; nObs=length(Y);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; z=1;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for(j=1:10)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; L5=j/200+0.01;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for(k=1:10)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; L4=k/200+0.01;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for(l=1:10)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; L3=l/200+0.01;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for(m=1:10)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; L2=m/200+0.01;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for(n=1:10)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; L1=n/200+0.01;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; G= [ones(nObs,1) L1*(1-exp(-tau./L1))./(tau) (1-exp(-((tau-L2).^2)/L3))./(((tau-L2).^2)/L3) (1-exp(-((tau-L4).^2)/L5))./(((tau-L4).^2)/L5) ];&lt;br&gt;
&amp;gt; &amp;gt; %c0(1)+c0(2)*c0(5)*(1-exp(-xdata./c0(5)))./(xdata) + c0(3)*(1-exp(-((xdata-c0(6)).^2)/c0(7)))./(((xdata-c0(6)).^2)/c0(7))+ c0(4)*(1-exp(-((xdata-c0(8)).^2)/c0(9)))./(((xdata-c0(8)).^2)/c0(9));&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; alpha =G\Y;&lt;br&gt;
&amp;gt; &amp;gt; u=Y-G*alpha;&lt;br&gt;
&amp;gt; &amp;gt; stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G)));&lt;br&gt;
&amp;gt; &amp;gt; Sum_u2 = sum(u.^2);&lt;br&gt;
&amp;gt; &amp;gt; error2=(Y-G*alpha).^2;&lt;br&gt;
&amp;gt; &amp;gt; error2 = sum(error2);&lt;br&gt;
&amp;gt; &amp;gt; Res(z,:) = [Sum_u2 alpha' L1 L2 L3 L4 L5 error2];&lt;br&gt;
&amp;gt; &amp;gt; z=z+1;&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; optim=find(Res(:,11)==min(Res(:,11)));&lt;br&gt;
&amp;gt; &amp;gt; %Result=Res(optim,2:end)&lt;br&gt;
&amp;gt; &amp;gt; Result=toc;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I don't know if there is a built in function doing the same computation, however I would advise to write your own C/C++ routine and interface this routine with Matlab. You could also use Matlab profiler to find what is the most computationally expensive part of your program and implement in C only that part.&lt;br&gt;
&lt;br&gt;
Thanks I can probably code this up in C++, but how can I interface this with Matlab? I've never done this before it is relatively easy?&lt;br&gt;
&lt;br&gt;
+ can I use the free express edition iof visual C++ to do the development. (I realise it's limited in the type of files it cam produce)</description>
    </item>
    <item>
      <pubDate>Fri, 23 Oct 2009 10:50:25 -0400</pubDate>
      <title>Re: Speeding up Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263859#689243</link>
      <author>tristram.scott@ntlworld.com (Tristram Scott)</author>
      <description>Hugh &amp;lt;h_a_patience@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi there,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have the following code which seeks to find the optimal solution to a&lt;br&gt;
&amp;gt; rpoblem. Using a linear search over a hyperbox. The problem is I need a&lt;br&gt;
&amp;gt; reasonably good granularity 1000+ on each parameter but becasue the scale&lt;br&gt;
&amp;gt; of the problem rises exponentially with the granularity used this soon&lt;br&gt;
&amp;gt; makes the problem prohibitively expensive in terms of computational time.&lt;br&gt;
&amp;gt; Is there an in built matlab function I an use which will speed this process&lt;br&gt;
&amp;gt; up?&lt;br&gt;
&lt;br&gt;
[snip]&lt;br&gt;
&lt;br&gt;
So, if I read this correctly, you are solving for the minimum of your&lt;br&gt;
function in five-dimensional space by complete enumeration on a grid. &lt;br&gt;
&lt;br&gt;
What would be a useful set of input parameters to you function, so we might&lt;br&gt;
attempt to reproduce your results?&lt;br&gt;
&lt;br&gt;
I am guessing that your function has many local minima, or you would just&lt;br&gt;
use a simple Newton search or similar.  Is that correct?  &lt;br&gt;
&lt;br&gt;
If you want to solve this using generic techniques, it would seem to fit&lt;br&gt;
into the realms of non-linear programming.  The MATLAB optimisation toolbox&lt;br&gt;
should cover that in one if not more ways.  Alternatively, use a third&lt;br&gt;
party solver e.g. MINOS or CPLEX.&lt;br&gt;
&lt;br&gt;
If you want to code it up yourself, I would suggest using a course grid to&lt;br&gt;
find the region of the global minimum, and then to use a Newton search in&lt;br&gt;
the region near the solution from the course grid search.&lt;br&gt;
&lt;br&gt;
There are many texts on math programming.  One of the good ones is&lt;br&gt;
Optimization Theory for Large Systems by Leon Lasdon.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Dr Tristram J. Scott               &lt;br&gt;
Energy Consultant                  </description>
    </item>
  </channel>
</rss>

