Re: Trace'ing Gradient in FindMinimum
- To: mathgroup at smc.vnet.net
- Subject: [mg87434] Re: Trace'ing Gradient in FindMinimum
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 10 Apr 2008 02:15:03 -0400 (EDT)
- References: <fti3st$odo$1@smc.vnet.net>
Hi,
try
f[x_List] := (x.x - 10)^2
df[x : {__?NumericQ}] := (Sow[x]; 4 (x.x - 10) x)
init = RandomReal[1, {3}];
Reap[FindMinimum[f[x], {x, init}, Gradient -> df[x]]]
Regards
Jens
Art wrote:
> 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 =
> Trace[
> 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
> EvaluationMonitor:
>
> ev = {};
> tr =
> ReleaseHold /@
> Flatten@Trace[
> 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
> Trace.
>
> 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.
>