Re: Re: argMax
- To: mathgroup at smc.vnet.net
- Subject: [mg51277] Re: [mg51270] Re: argMax
- From: DrBob <drbob at bigfoot.com>
- Date: Tue, 12 Oct 2004 01:57:40 -0400 (EDT)
- References: <ckaj3i$m3r$1@smc.vnet.net> <200410110525.BAA05047@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
The dichotomy isn't really one-dimensional versus multi-dimensional, I think; it's values versus positions. These should work for data of any shape at all: positions[f_,arglist_List]:=Module[{spectrum=Map[f,arglist,-1]}, Position[spectrum,Max[spectrum]]] values[f_,arglist_List]:=Extract[arglist,positions[f,arglist]] data=Array[Random[Integer,10]&,{10,5}] values[Identity,data] positions[Identity,data] {{9,5,0,5,4},{7,2,3,6,10},{5,3,0,1,10},{10,1,4,1,3},{8,6,4,1,6},{9,0, 0,7,1},{0,7,9,0,10},{5,8,2,8,8},{0,3,3,7,7},{5,3,9,9,5}} {10,10,10,10} {{2,5},{3,5},{4,1},{7,5}} Bobby On Mon, 11 Oct 2004 01:25:29 -0400 (EDT), Peltio <peltio at twilight.zone> wrote: > "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. > > > > > > > -- DrBob at bigfoot.com www.eclecticdreams.net
- References:
- Re: argMax
- From: "Peltio" <peltio@twilight.zone>
- Re: argMax