Re: Optimization doing more function evaluations than claimed?
- To: mathgroup at smc.vnet.net
- Subject: [mg57242] Re: Optimization doing more function evaluations than claimed?
- From: Gareth Russell <gjr2008 at columbia.edu>
- Date: Sat, 21 May 2005 02:41:11 -0400 (EDT)
- Organization: Columbia University
- References: <d6k9kl$12g$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello again, Daniel Lichtblau sent me a suggestion (thanks Daniel), which led tangentially to the following observation: the double evaluation I described goes away if I remove the large secondary arguments (vectors and matrices that are the datasets) from the function by making them global variables. So the new function is lDistExp[b1_?NumericQ] := Module[{distQ,pMaps, logList, logLike}, distQ = mapExponential2[distMaps, b1]; pMaps = Map[toProbs[#] &, distQ]; logList = Log[MapThread[#1[[#2]] &, {pMaps, e}]]; loglike=Apply[Plus, logList]; Print[{b1,logLike}]; logLike ] and distMaps and e are global. My practical problem is now solved, but can anyone explain why the passing of large numerical expressions as arguments might cause a double evaluation when the function is within a FindMinimum statement? Just wondering, really... Gareth On 2005-05-20 05:11:49 -0400, Gareth Russell <gjr2008 at columbia.edu> said: > Hi All, > > I have been using FindMaximize without symbolic derivatives to maximize > a likelihood function that operates on a large dataset. Because the > process is slow, I want to track progress as it happens, so I include a > Print[{parameter1, parameter2, ..., likelihood}] step in the function > being evaluated. In doing so, I have noticed that the function appears > to be evaluated twice for each trial of the parameter values. When I > look at diagnostics after the fit is complete, such as the output of > the EvaluationMonitor option, it shows each trial only once. For > example, if Mathematica claims 20 steps after the fact, the number of > printed outputs is always 40, in identical pairs. The 40 outputs appear > evenly spaced in time, and the total timing of the fitting process, > compared to the timing of one evaluation of the function, confirms that > indeed, it was evaluated 40 times. > > Does anyone know why (i.e., under what conditions) FindMinimum might do > this? You won't be able to evaluate my function, as it calls the > datasets, but here it is anyway, with some info: > > lDistExp[distMaps_, e_, b1_?NumericQ] := Module[{distQ, pMaps, > logList, logLike}, > distQ = mapExponential2[distMaps, b1]; > pMaps = Map[toProbs[#] &, distQ]; > logList = Log[MapThread[#1[[#2]] &, {pMaps, e}]]; > loglike=Apply[Plus, logList]; > Print[{b1,logLike}]; > logLike > ] > distMaps is a (large) matrix of reals, e is a vector of integers, > and b1 is a real. > > The functions mapExponential2[] and toProbs[] are compiled functions > (for speed). > > The function is maximized with respect to b1. > > As a side note that may be relevant, if I load the > Optimization`UnconstrainedProblems` package and use the FindMinimumPlot > function, the target function is be evaluated THREE times per step, > even though the output again says just 20 steps. > > Because the fitting procedure is necessarily slow because of dataset > size, I don't want to be doing more function evaluations than are > necessary! > > Thanks, > > Gareth Russell > Columbia University