       Re: Keeping global parameters in an evaluated function

• To: mathgroup at smc.vnet.net
• Subject: [mg113267] Re: Keeping global parameters in an evaluated function
• From: "Carl K. Woll" <carlw at wolfram.com>
• Date: Thu, 21 Oct 2010 07:02:39 -0400 (EDT)

```On 10/20/2010 3:10 AM, Davide Mancusi 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?
>
> Davide
>
>

You might try using calculus and homotopic continuation. For example,
suppose you're trying to minimize

f[x, c]

for a given value of c. Let x[c] be the value of x that minimizes f for
a given value of c. Then, x[c] should be a stationary point of f. That
is, let:

g[x_, c_] = D[f[x, c], x]

Then x[c] should satisfy:

g[x[c], c]==0

If we differentiate this equation with respect to c, we obtain an ODE
that x[c] should satisfy, which can be solved by NDSolve. As a concrete
example, suppose:

f[x_,c_]:=(x^4+c x^2-c^2 x)

Then the derivative with respect to x is:

In:= g[x_,c_]=D[f[x,c],x]
Out= -c^2+2 c x+4 x^3

The ODE that needs to be solved is:

In:= eqn=D[g[x[c],c],c]==0
Out= -2 c+2 x[c]+2 c (x^\[Prime])[c]+12 x[c]^2 (x^\[Prime])[c]==0

The minimizer for c=10 is:

In:= min10=ArgMin[f[x,10],x]
Out= Root[-25+5 #1+#1^3&,1]

Use NDSolve to find the minimizer for values of c from 1 to 10:

In:= min=x/.NDSolve[{eqn,x==min10},x,{c,1,10}][]
Out= InterpolatingFunction[{{1.,10.}},<>]

Check:

In:= ArgMin[f[x, 5.], x]
min

Out= 1.40072
Out= 1.40072

In:= ArgMin[f[x,2.],x]
min
Out= 0.682328
Out= 0.682327

So, min is an interpolating function that gives the minimizer x[c] as a
function of c. To get the minimum value, one can do:

f[min[c], c]

for a particular value of c.

Carl Woll
Wolfram Research

```

• Prev by Date: Re: argument list for ArrowBox?
• Next by Date: Re: Keeping global parameters in an evaluated function
• Previous by thread: Re: Keeping global parameters in an evaluated function
• Next by thread: Re: Keeping global parameters in an evaluated function