Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Re: argMax

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51375] Re: [mg51328] Re: argMax
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 15 Oct 2004 02:47:24 -0400 (EDT)
  • References: <ckaj3i$m3r$1@smc.vnet.net> <200410110525.BAA05047@smc.vnet.net> <ckfrv9$ise$1@smc.vnet.net> <200410141037.GAA14939@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

I definitely should have tested with functions other than Identity.

Bobby

On Thu, 14 Oct 2004 06:37:10 -0400 (EDT), Peltio <peltio at twilight.zone> wrote:

> "DrBob"  wrote
>
>> The dichotomy isn't really one-dimensional versus multi-dimensional, I
> think; it's values versus positions.
>
> Since the OP was looking for a fast procedure I thought it would have been
> better to use 'dedicated' functions for each special case in order to keep
> the overhead to a minimum. I got my second procedure totally wrong though.
> Yours is fine, instead, but...
>
>>    positions[f_,arglist_List]:=
>>        Module[
>>            {spectrum=Map[f,arglist,-1]},
>>            Position[spectrum,Max[spectrum]]
>>    ]
>>    values[f_,arglist_List]:=Extract[arglist,positions[f,arglist]]
>
> I think you had a 'lapsus digitae' after reading my mistake. : ) In fact
>     Map[f,arglist,-1]
> should read
>     Map[f,arglist,{-1}]
> (with onedimensional lists and Identity there are no differences since
> either there is no nesting or when there is nesting, nesting Identity won't
> change anything).
>
> I was thinking about a way to make the procedure a little faster, but I fear
> there is little room for improvement (at least without a real breakthrough -
> such as an undocumented function that does just that : )))).
> For a start: if the function f to be applied is rather complicated, it could
> be advisable to use N.
> Also, when the procedure ArgMax is called many times. using With instead of
> Module could reduce its overhead (or at least I think so [1]).
> I am not sure if, when the original data structure is very complex, there
> could be any improvement in processing the flattened structure (but I guess
> it's unlikely to have data in a form that is not a neat list, matrix or
> tensor...)
>
> Should that be true, this proc should have a ( theoretical : ) ) edge in
> case ArgMax is called very many times feeding it complex data structures and
> timeconsuming functions:
>
>     argMax[f_, arglist_List] :=
>       With[ {newarg = Flatten[N[arglist]]},
>         spectrum = Map[f, newarg];
>         Extract[newarg, Position[spectrum, Max[spectrum]] ]
>     ]
>
> But it's very likely it won't show any sensible -practical- improvement over
> the original (corrected) multidimensional version. Moreover, Flatten is
> useless when the list is onedimensional, so if the other tricks have any
> effect whatsoever, it'd be better to use a dedicated proc for onedimensional
> lists.
>
> [1] I recall a discussion on Bahder's book (Mathematica for Scientist and
> Engineers [2]) about different versions of a procedure called trapIntegrate.
> [2] Wouldn't it be nice to have that book updated?
>
> cheers,
> Peltio
> Invalid address in reply-to. Crafty demunging required to mail me.
>
>
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • References:
  • Prev by Date: Re: Solving an equation
  • Next by Date: Re: Eigenvalues and eigenvectors of a matrix with nonpolynomial elements.
  • Previous by thread: Re: argMax
  • Next by thread: Re: argMax