MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Trace'ing Gradient in FindMinimum

  • To: mathgroup at
  • Subject: [mg87384] Trace'ing Gradient in FindMinimum
  • From: Art <grenander at>
  • Date: Wed, 9 Apr 2008 05:54:56 -0400 (EDT)

Can I track Gradient computations in FindMinimum using Trace? Here, tr
is empty though df is evaluated several times:

f[x_List] := (x.x - 10)^2
df[x : {__?NumericQ}] := 4 (x.x - 10) x
init = RandomReal[1, {1000}];

tr =
    FindMinimum[f[x], {x, init}, Gradient -> df[x]],
    df[x_] -> Norm[x]

But Tracing the evaluation of f[] is possible and yields the same as

ev = {};
tr =
 ReleaseHold /@
    FindMinimum[f[x], {x, init}, Gradient -> df[x],
     EvaluationMonitor :> AppendTo[ev, Norm[x]] ],
    f[x_] -> Norm[x]];

Here, tr == ev.

It looks like FindMinimum eats the function df and doesn't ever
explicitly call it, but it doesn't eat f.

I am trying to resolve an error where FindMinimum immediately
complains my Gradient doesn't evaluate to a vector of reals for init
and returns. Placing a Print inside df shows that FindMinimum does
actually call df with init and when I separately evaluate df[init],
there is no problem. I know I am doing something wrong so I was hoping
to figure it out with Trace on df. I would also like to learn to use

Second question: Is there a way to specify that FindMinimum should not
try to find symbolic derivatives and such for it's arguments other
than using patterns like x:{__?NumericQ}, which probably take time to
compute. It would be nice for something like f[x_ /;
And@@(MatrixQ[#,NumericQ]&/@x)] not to be evaluated each iteration. Is
there a global $TrustUserUnconditionally = True option?

Thanks for any suggestions.

  • Prev by Date: Re: Filling problem in Plot3D
  • Next by Date: Re: ListCorrelate on lists with different sampling rates
  • Previous by thread: Re: Pattern problem: How to count from a long list of numbers all occurrences of 2 numbers next to each others?
  • Next by thread: Re: Trace'ing Gradient in FindMinimum