Message Boards Message Boards

1
|
2242 Views
|
0 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

Speeding Up FindMinimum For Unconstrained Problems

For repeated calls to FindMinimum for the same unconstrained problem from different starting points, a speed increase can be obtained by compiling the objective function and its gradient, setting EvaluateSymbolically -> False as a Runtime option for the compilation of the objective function.

Function To Be Minimized: 

In[1]:= expr = E^Sin[50 x] + Sin[60 E^y] + Sin[70 Sin[x]] + Sin[Sin[80 y]] - 
   Sin[10 (x + y)] + 1/4 (x^2 + y^2);

Function to generate n random points with x and y between -3 and 3 

In[2]:= genrands[n_] := 
 Block[{}, SeedRandom[0]; Transpose[RandomReal[#, n] & /@ {{-3, 3}, {-3, 3}}]]

 Repeated FindMinimum Search

In[3]:= Off[FindMinimum::lstol, FindMinimum::sdprec]

In[4]:= opt1[n_] := Sort[FindMinimum[expr, Thread[{{x, y}, #}]] & /@ genrands[n]][[1]]

In[5]:= AbsoluteTiming @ opt1[ 3 10^3]

Out[5]= {2.21029, {-3.30687, {x -> -0.0244031, y -> 0.210612}}}

 Compile the objective function

In[6]:= cexpr = Compile[{x, y}, Evaluate[expr], 
   RuntimeOptions -> {"EvaluateSymbolically" -> False}];

 Compile the gradient of the objective function

In[7]:= dexpr = D[expr, {{x, y}}];

In[8]:= cdexpr = Compile[{x, y}, Evaluate[dexpr]];

In[9]:= opt2[n_] := Sort[
   FindMinimum[cexpr[x, y], Thread[{{x, y}, #}], Gradient :> cdexpr[x, y]] & /@ 
    genrands[n]][[1]]

In[10]:= AbsoluteTiming[opt2[3 10^3]]

Out[10]= {1.2983, {-3.30687, {x -> -0.0244031, y -> 0.210612}}}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract