MathGroup Archive 2000

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

Search the Archive

Re: minimization of a function operating on a vector or reals

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23224] Re: minimization of a function operating on a vector or reals
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 25 Apr 2000 01:40:28 -0400 (EDT)
  • References: <8dok32$jdj@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Wijnand ,
Just putting together your code.


Attributes[myFindMinimum] = {HoldAll};

myFindMinimum[f_, initlst_] :=
  (# /. FindMinimum[f[#], ##2][[2]]) &
        [#, Sequence @@ (Thread[{#, initlst}])] &[
    Table[Unique[x], {Length[initlst]}]]

f[lst_] := Plus @@ Map[#^2 &, lst]

initlst = {1.0, 2.0, -1.0};

myFindMinimum[f, initlst]

\!\({1.3322676295501878`*^-15,
    2.6645352591003757`*^-15, \(-1.3322676295501878`*^-15\)}\)

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Wijnand Schepens" <Wijnand.Schepens at rug.ac.be> wrote in message
news:8dok32$jdj at smc.vnet.net...
> I wish there were a kind of FindMinimum for high dimensions without
> having to mention all (dummy) variables...
>
> This is a simplification of my problem:
>
> Suppose I have a function f[lst] which maps a list of real numbers (a
> vector) into a number, e.g.
>
> f[lst_]:=Plus @@ Map[#^2 &, lst]
>
> Now I want to minimize f w.r.t. every element in the list, e.g.
>
> FindMinimum[ f[{x1,x2,x3}], {x1,1.}, {x2,2.}, {x3,-1.} ]
>
> This works fine, but I want to do the minimization for large lists (of
> any length, say 10). I have the initial values in a list, e.g.
>
> n = 10;
>
> initlst = N[Range[n]];
>
> First I need to create dummy-variables
>
> dummy := Module[{x}, x];
>
> varlst = Table[dummy, {n}];
>
> Then I must feed this to FindMinimum to get something like
> FindMinimum[f[{dummies...}, {dummy1,init1}, {dummy2,init2}, ...].
> I did it like this:
>
> r = FindMinimum[f[varlst], Evaluate[Sequence @@ MapThread[List, {varlst,
> initlst}]]]
>
> The final result then is
>
> varlst /. r[[2]]
>
> This gives the desired result.
>
> But this all seems such a lot of trouble. And is it efficient???
> Is there an alternative?
> Is there a way to avoid the generation of a list of dummy-arguments?
>
> I would think that the core-code of the FindMinimum routine works with
> vectors of real numbers. Is this true? If so, is it usable or do we
> always have to go via FindMinimum??
>
>
>
> Off the record:
>
> If my function to be minimized is a compiled function working
> on a vector (rank 1 tensor)
> e.g.
>
> f2=Compile[{{lst,_Real,1}},Plus @@ Map[#^2 &, lst]
>
> then f2[initlst] gives the same answer, but f2[varlst] gives an error
> because the argument is symbolical.
> Nevertheless, I can feed f2 to FindMinimum just like before, and get the
> correct answer in less time. Luckily.
>
> But still, I have the feeling that there could be a more fundamental
> minimization routine where one wouldn't have to supply symbols for dummy
> variables...
>
>
>
>




  • Prev by Date: Re: fastest way to do pair-sum / make pair-list
  • Next by Date: RE: Q: open palletes in a specific on screen position.
  • Previous by thread: minimization of a function operating on a vector or reals
  • Next by thread: Help, my MathLink Examples segfault.