MathGroup Archive 2004

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

Search the Archive

Re: argMax


"Pierre Albarede" wrote

>I miss a fast internal function ArgMax.
[snip]
>but this will be much slower that Max. How can I have a faster argMax ?

I've written this without any testing, so I can't tell whether it's faster
or not than your solution (if it happens to be so, it won't be much faster,
though).
You can either have a version of ArgMax that works for onedimensional lists
giving you a list of the elements that produce a max (you can have more than
one)...

    ArgMax[f_, arglist_List] :=
      Module[
        {spectrum},
        spectrum = f /@ arglist;
        Flatten[Take[arglist, #] & /@ Position[spectrum, Max[spectrum]]]
    ]


Or a multidimensional one, that can give you a list of coordinates of the
points giving you a max.

    ArgMax[f_, arglist_List] :=
      Module[
        {spectrum},
        spectrum = Map[f, arglist, -1];
        Take[arglist, #] & /@ Position[spectrum, Max[spectrum]]
    ]

(pattern matching can be adopted to have the proc automatically choose the
code to be employed).

hope this helps,
Peltio
--
Invalid address in reply-to. Crafty demunging required to mail me.





  • Prev by Date: Outer product in mathematica
  • Next by Date: Re: plotting groups of polynomial roots
  • Previous by thread: argMax
  • Next by thread: Re: Re: argMax