MathGroup Archive 2009

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

Search the Archive

Re: Optimization question.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98210] Re: Optimization question.
  • From: dh <dh at metrohm.com>
  • Date: Fri, 3 Apr 2009 04:32:03 -0500 (EST)
  • References: <gr0gdr$93h$1@smc.vnet.net>


Hi Gregory,

you want to call different functions depending depending on the 

arguments an further function has already seen.

To accomply this you may store function values already calculated by the 

syntax:

f1[x_]:=f1[x]= defintion of f1

If this will use too much memory you may use a global variable where the 

last argument of f1 is stored.

Here is an examples using the first approach. f2 calls f3 or f4 

depending on the arguments f1 has already seen:



f1[x_] := f1[x] = x;

f2[x_] := If[

    Cases[DownValues[f1], HoldPattern[f1[x]], Infinity] == {}, f3[x],

    f4[x]];

f3[x_] := Print["f1 has not seen value: ", x];

f4[x_] := Print["f1 has seen value: ", x];



f1[1];

f2[1]

f2[2]



hope this helps, Daniel



Gregory Duncan wrote:

> I have a very complicated objective function calculated using a recursion.

> It is straightforward to compute the gradient as the function is computed.

> How to I tell Mathematica that when it needs the gradient, it must calculate

> the objective first? Alternatively, is there a way to tell whether the

> objective has "just" been evaluated and tell Mathematica to use one program

> for the gradient if the objective has just been called with the same

> parameter values and another if it was called in a previous iteration or sub

> iteration, e.g. with different parameters. Maybe it is in the documentation

> somewhere but I could not find it.

> 

> Greg Duncan

> 

> 




  • Prev by Date: Re: A simple ordinary differential equation
  • Next by Date: Re: ImageResolution
  • Previous by thread: Optimization question.
  • Next by thread: Footnotes, Endnotes in Mathematica