Re: Keeping global parameters in an evaluated function

• To: mathgroup at smc.vnet.net
• Subject: [mg113271] Re: Keeping global parameters in an evaluated function
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Thu, 21 Oct 2010 07:03:23 -0400 (EDT)

```Hi Davide,

Looks like your guess about initial evaluation of the function is correct.
If you restrict your argument to be numeric, you get what you want:

In[84]:=
Clear[ff];
ff[x_?NumericQ] := (x - c)^4
c = 1;
iterations = 1;
FindMinimum[ff[x], {x, 1001}, StepMonitor :> {c = c/2; iterations++}]
Print[{c // N, iterations}]

Out[88]= {1.0531*10^-30, {x -> 3.20345*10^-8}}

During evaluation of In[84]:= {5.16988*10^-26,85}

Regards,
Leonid

On Wed, Oct 20, 2010 at 1:10 AM, Davide Mancusi <d.mancusi at ulg.ac.be> wrote:

> Hello everyone,
>
> I have a function that depends on some variables and a parameter (say
> c). My goal is to find the global minimum of the function for a given
> value of the parameter, say c=0. However, the function has a lot of
> local minima for c=0, and is thus very difficult to hit the global
> one. For c=1, however, the function is much smoother, and the
> minimization algorithms work pretty well.
>
> What I'm trying to do is to change the value of the parameter
> continuously while Mathematica minimizes the function. By doing so I
> hope to trap the minimization algorithms close to the global minimum
> using the smooth version of the function, and then slowly let c go to
> 0.
>
> I have come up with the following toy model (I use NMinimize in the
> real problem, but that shouldn't be important):
>  f[x_] := (x - c)^4
>  c=1;
>  iterations=1;
>  FindMinimum[ f[x], {x, 1001}, StepMonitor :> {c = c/2; iterations+
> +} ]
>  Print[{c // N,iterations}]
> If I run this I get
>  {4.48416*10^-32, {x -> 1.}}
>  {1.45519*10^-11,37}
> The algorithm finds the minimum at x==1 while I would like it to find
> it close to 1.45519*10^-11.
>
> I think the problem lies in the fact that f[x] is evaluated only once,
> at the beginning of the minimization algorithm, and the global value
> of c gets substituted. Thus, even if I change c later, that doesn't
> affect the function being minimized.
>
> Can anyone suggest a way to update c from within the minimization
> routine?
>