# Message Boards

1
|
2193 Views
|
0 Replies
|
1 Total Likes
View groups...
Share
 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:= 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:= genrands[n_] := Block[{}, SeedRandom; Transpose[RandomReal[#, n] & /@ {{-3, 3}, {-3, 3}}]] Repeated FindMinimum Search In:= Off[FindMinimum::lstol, FindMinimum::sdprec] In:= opt1[n_] := Sort[FindMinimum[expr, Thread[{{x, y}, #}]] & /@ genrands[n]][] In:= AbsoluteTiming @ opt1[ 3 10^3] Out= {2.21029, {-3.30687, {x -> -0.0244031, y -> 0.210612}}} Compile the objective function In:= cexpr = Compile[{x, y}, Evaluate[expr], RuntimeOptions -> {"EvaluateSymbolically" -> False}]; Compile the gradient of the objective function In:= dexpr = D[expr, {{x, y}}]; In:= cdexpr = Compile[{x, y}, Evaluate[dexpr]]; In:= opt2[n_] := Sort[ FindMinimum[cexpr[x, y], Thread[{{x, y}, #}], Gradient :> cdexpr[x, y]] & /@ genrands[n]][] In:= AbsoluteTiming[opt2[3 10^3]] Out= {1.2983, {-3.30687, {x -> -0.0244031, y -> 0.210612}}}