MathGroup Archive 2005

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

Search the Archive

Re: Optimization doing more function evaluations than claimed?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63383] Re: Optimization doing more function evaluations than claimed?
  • From: "Joshua Solomon" <J.A.Solomon at city.ac.uk>
  • Date: Wed, 28 Dec 2005 03:55:39 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I was just wondering if there had been any progress on this issue. My
problem is similar to the one that Gareth originally reported, except
instead of double or triple evaluations, mine produces sextuple
evaluations! Code follows. Two salient facts: 1) the hack Gareth
stumbled upon doesn't work for me; I don't pass secondary arguments
(each one of my arguments is a parameter) and 2) the dummy function is
just that, i.e. something that can be evaluated rapidly and produces
sextuple evaluations; I really want to use a more complicated
(4-parameter) function that cannot be evaluated rapidly.

Code:

data = {{0.01,0.01, 0.01, 0.02, 0.03, 0.05, 0.08, 0.13, 0.2, 0.32},
     {0.03, 0.02, 0.02, 0.01, 0.02, 0.04, 0.06, 0.07, 0.09, 0.13}};

dummy[a_?NumericQ,b_?NumericQ,p_?NumericQ,pMinusQ_?NumericQ]:=
       Plus@@((data[[2]]-(FindMinimum[

(1-a*(Sqrt[t^2]+#)^p/(b^(p-pMinusQ)+(Sqrt[t^2]+#)^(p-pMinusQ))+
               a*#^p/(b^(p-pMinusQ)+#^(p-pMinusQ)))^2,
          {t,.01}][[2,1,2]]&/@(data[[1]])))^2);

FindMinimum[err = dummy[a, b, p, pMinusQ],
     {{a, 10}, {b, 0.03}, {p, 3}, {pMinusQ, 0.44}},
     EvaluationMonitor :> Print[
          "err=", err, " a=", a, " b=", b, " p=", p, " pMinusQ=",
pMinusQ]]

Thanks in advance for any replies,
Josh

On 21 May 2005 07:11:52, Gareth Russell <gjr2... at columbia.edu> said:

> 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 <gjr2... 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


  • Prev by Date: Re: Re: Questions regarding MatrixExp, and its usage
  • Next by Date: Coefficients from Fit as a list?
  • Previous by thread: Re: PaddedForm-like behavior for GridBox[]
  • Next by thread: Coefficients from Fit as a list?