Re: Trace'ing Gradient in FindMinimum
- To: mathgroup at smc.vnet.net
- Subject: [mg87406] Re: Trace'ing Gradient in FindMinimum
- From: dh <dh at metrohm.ch>
- Date: Thu, 10 Apr 2008 02:09:45 -0400 (EDT)
- References: <fti3st$odo$1@smc.vnet.net>
Hi Art, the most Trace will deliver you may see by: Trace[FindMinimum[f[x], {x, init}, Gradient -> df[x]], _] (do not try this with dimension=1000!!) As you will see, the gradient nowhere appears in unevaluated form. Therefore, no need to search for it. You may be better off with Print statements. hope this helps, Daniel 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. >