Message Boards Message Boards

GROUPS:

Why Doesn't EvaluateSymbolically work inside FindMinimum?

Posted 8 years ago
3050 Views
|
4 Replies
|
0 Total Likes
|

A compiled function generated with EvaluateSymbolically -> True still gives a CompiledFunction symbolic argument error when used as the objective function in FindMinimum

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);

In[2]:= cexpr = Compile[{x, y}, Evaluate[expr]];

In[4]:= FindMinimum[cexpr[x, y], {{x, 1}, {y, 1}}]

During evaluation of In[4]:= CompiledFunction::cfsa: Argument x at position 1 should be a machine-size real number. >>

Out[4]= {-0.342853, {x -> 0.953282, y -> 0.291998}}

In[5]:= cexpr1 = 
  Compile[{x, y}, Evaluate[expr], 
   RuntimeOptions -> {"EvaluateSymbolically" -> True}];

In[6]:= FindMinimum[cexpr1[x, y], {{x, 1}, {y, 1}}]

During evaluation of In[6]:= CompiledFunction::cfsa: Argument x at position 1 should be a machine-size real number. >>

Out[6]= {-0.342853, {x -> 0.953282, y -> 0.291998}}
POSTED BY: Frank Kampas
4 Replies

Ok, that all makes sense. Now I'd like to know why FindMinimum runs faster with a compiled objective function with the option EvaluateSymbolically -> False as compared to True.

POSTED BY: Frank Kampas

As documented, FindMinimum evaluates cexpr1[x, y] with symbolic x and y first. In this example, cexpr1 happens to be a compiled function, which means there will be a CompiledFunction::cfsa message -- unless cexpr1[x, y] was explicitly forced to stay unevaluated, which is what EvaluateSymbolically -> False does.

POSTED BY: Ilian Gachevski

I would have thought it would be the other way around. Unless FindMinimum checks to see what the setting of EvaluateSymbolically is.

POSTED BY: Frank Kampas

I think you are actually looking for

RuntimeOptions -> {"EvaluateSymbolically" -> False}
POSTED BY: Ilian Gachevski
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