MathGroup Archive 2007

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

Search the Archive

Re: is there a better way to iterate this?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77838] Re: [mg77820] is there a better way to iterate this?
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Mon, 18 Jun 2007 06:53:47 -0400 (EDT)
  • References: <17667533.1182085910140.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

The first Table WITHIN a table...

Table[Transpose[{listB[[j]], randomizedlistA[[k, j]]}, {j,
    Length[listB]}], {k, Length[randomizedlistA]}]

is a complete waste of computer cycles; you discard the result without  
using it for anything.

The last table:

Table[N[Correlation[Flatten[foo[[i]], 1][[All, 1]],
     Flatten[foo[[i]], 1][[All, 2]], {i, Length[foo]}];

has illegal syntax. There's a missing bracket somewhere.

Most of those nested Tables are not needed, I'm sure, but to debug any  
further, I'd need enough detail (the value of listA, for instance) to  
actually run the code and figure out what you're doing.

Send me the notebook, if you like. A small example would be perfect.

Bobby

On Sun, 17 Jun 2007 05:13:05 -0500, dantimatter <dantimatter at gmail.com> 

wrote:

>
> Hello all,
>
> I have a question about a specific problem I'm working now.  I would
> like to do 100000+ iterations of a series of operations, but the way
> I'm doing it now is slow and memory intensive.  I know there's a
> better way to do it, but I just can't figure it out.  The problem: I
> have two lists of 21 sublists: listA and listB, and I would like to
> shuffle the order of the sublists in listA around and then correlate
> them with listB.  Here's how I'm doing it now:
>
> ------------------------  begin inefficient code
> -----------------------
>
> randomizedlistA = Table[RandomPermutation[listA], {100000}];
>
> listAlistBpairs =
>                     Table[Table[
>                       Transpose[{listB[[j]], randomizedlistA[[k, j]]},
> {j, Length[listB]}], {k, Length[randomizedlistA]}];
>
> foo =
>         Table[Table[
>             listAlistBpairs[[k, All, i]], {i,
>               Length[listAlistBpairs[[k, 1]]]}], {k,
>             Length[listAlistBpairs]}];
>
> bar =
>       Table[N[Correlation[Flatten[foo[[i]], 1][[All,1]],
> Flatten[foo[[i]], 1][[All, 2]], {i,
>           Length[foo]}];
>
> ------------------------  end inefficient code
> --------------------------
>
> The variable 'bar' should now be a list of 100000 correlation
> coefficients. I realize this is probably bad Mathematica code, but I
> wrote it quickly and it worked great for smaller numbers of
> permutations.  Can anyone suggest an easy way to do this better?
>
> Also, though it's not written in that code, I'd like to take those
> correlation coefficients and generate a probability distribution out
> of them.  For 10000 permutations it comes out as a beautiful
> Gaussian;  I can only assume it's going to look even better for
> 100000+ permutations.  Any suggestions on how to generate a
> probability distribution, and how to calculate P-values from that
> distribution, would also be extremely helpful.
>
> Many thanks,
> Dan
>
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Re: Manipulate a complex expression
  • Next by Date: Re: RuleDelayed plot options and Show
  • Previous by thread: Re: is there a better way to iterate this?
  • Next by thread: Re: is there a better way to iterate this?