       Re: FindMinimum of a compiled function??

• To: mathgroup at smc.vnet.net
• Subject: [mg23672] Re: FindMinimum of a compiled function??
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Mon, 29 May 2000 12:24:02 -0400 (EDT)
• Organization: Universitaet Leipzig
• References: <8gsnfe\$ec6@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

FindMinumum[] must calculate the gradient form the symbolic
expression. So you have to supply (and to compile the gradient)
and

f = Compile[{{x, _Real}, {y, _Real}}, x^2 + x + y^2]

dfdx = 2*x + 1;
dfdy = 2*y;

FindMinimum[Evaluate[f], {x, 2}, {y, 2}, Gradient -> {dfdx, dfdy}]

run with out an error message.

And it is one of the best things that Mathematica uses symbolic
variables and *not* a list of real numbers to compute minima. The
speed you miss come from the interpreter and not form the unique
style of Mathematica's solution form. Let me give you an example.
A interpreter *must* check in every call of x[[i]] and make sure that
the
i is not not of range. A FORTRAN or C program will crash
in this case and force the programmer to serach for the error until
it is fixed. When Mathematica would crash with every input error you
will never finish anything. How ever index checking is very time
consuming
and I have seen C-programs that spend 70 % of their live with
index checks.

Regards
Jens

Wijnand Schepens wrote:
>
> Hi everybody
>
> I want to minimize a function of many variables a number of times,
> starting from
> different initial values each time.
> There doesn't seem to be a way to pass a compiled function to
> FindMinimum, because you have to give explicit names to the arguments. I
> know that FindMinimum
> tries to compile the function. The problem is that I repeat this
> procedure a lot of times, and I don't want FindMinimum to do all the
> compiling-work every time over and over.
> Does FindMinimum remember the compiled version of a function for
> subsequent minimization?
> I would think it is more efficient to compile the function once
> (possibly the derivatives too), and pass this compiled version to
> FindMinimum... But I fear this is impossible...
> No?
>
> It's a shame that there isn't a version of FindMinimum which takes a
> function working
> on a list of real numbers (or a matrix, like in Compile).
> This is a VERY common thing to do in global minimization (of continuous
> functions), molecular modeling, and all sorts of simulations.
> Mathematica's routines isn't fast enough to be competitive with
> classical procedural languages.
> Especially since so much attention has been paid to speed up Mathematica
> vector-routines by packed-array technology, I find it strange that there
> Can onyone explain me why? Is something of the sort planned for future
> versions?
>
> In my ideal Mathematica-world there would be a function like Minimize:
>
> fc=Compile[{x,_Real,1}, ...some function of the x[[i]]... ];
>
> xlist=Table[Random[],10];
>
> fc[xlist]
> returns real number
>
> Minimize[fc, xlist]
> or
> Minimize[ {x,_Real,1}, fc, xlist ]
> or
>
> Minimize would return {minvalue, xlist} where xlist contains the
> coordinated at the minimum
>
> Is this impossible??
>
> Wijnand Schepens
>
> p.s.  do Mathematica-developers pay attention to this mailing-list?
> Maybe they only look at the titles and sigh...

```

• Prev by Date: RE: Reverse Axes in Plot
• Next by Date: Re: FindMinimum of a compiled function??
• Previous by thread: Re: FindMinimum of a compiled function??
• Next by thread: Re: FindMinimum of a compiled function??