MathGroup Archive 2002

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

Search the Archive

RE: Again, How to speed up this calculation? and more

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37272] RE: [mg37246] Again, How to speed up this calculation? and more
  • From: "DrBob" <drbob at bigfoot.com>
  • Date: Mon, 21 Oct 2002 02:29:45 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Why make a list of them at all?  That is, you know what the pairs are
without listing them, and you can form any pair you want without listing
them.  So -- why spend all that memory, even if you have it?  (And you
don't.)  I just see no reason for it.

Bobby

-----Original Message-----
From: Cheng Liu [mailto:cliu at lanl.gov] 
To: mathgroup at smc.vnet.net
Subject: [mg37272] [mg37246] Again, How to speed up this calculation? and more


Dear group,

         Thank you all for the responses.  I might not make my question 
very clear.  Suppose that I have a list of points {p1,p2, ..., pn}, I
try 
to find all possible pairs of them.  The pairs may include {pi,pi}, but 
{pi,pj} and {pj,pi} are considered the same and only one is counted.

         That said.  After some try and error, I came to the following
way:

         h=4;w=5;
         points=Flatten[Outer[List,Range[w],Range[h]],1];
 
pairs=Flatten[Map[Outer[List,{#},Drop[points,Position[points,#][[1,1]]-1
],1][[1]]&,points],1];

The speed of the above calculation is reasonably fast.  But I run into
the 
memory problem.  For example, for h=64 and w=64, the length of the list 
pairs will be w*h (w*h+1)/2 = 8,390,656.  In my case, The numbers for h
and 
w will be a lot larger than 64.  How can I get around this memory
problem 
or that's the dead end for my calculation (I do have 1 GB physical mem
in 
my machine)?  Thanks a lot.

Cheng

At 12:26 PM 10/16/2002, you wrote:
>Dear group,
>
>          I have the following question regarding a lengthy calculation
>using Mathematica:
>
>For given w points in x direction and h points in y direction, I can
>construct all the points using
>
>          h=10; w=8;
>          points=Flatten[Transpose[Outer[List,Range[w],Range[h]]],1]
>
>Next, I need to find all the possible pairs of point including points
>themselves, i.e., pair AA.  I can use
>
>          pairs=Outer[List,points,points,1]
>
>Then, I have to clear those pairs that repeat themselves, i.e., pair AB
and
>pair BA.  Also, when w and h are of the order of 1000s, the computation
>takes a very long time.  Is there a better way of doing the second part
of
>the computation?  Thanks in advance.
>
>Sincerely
>
>Cheng
>
>
>====================================================
>Cheng Liu, Ph.D.
>MST-8, Structure/Property Relations
>Materials Science and Technology Division
>Los Alamos National Laboratory
>Los Alamos, New Mexico 87545
>
>Phone: 505-665-6892 (office), 505-667-9950 (lab)
>Fax:   505-667-8021
>email: cliu at lanl.gov
>====================================================

====================================================
Cheng Liu, Ph.D.
MST-8, Structure/Property Relations
Materials Science and Technology Division
Los Alamos National Laboratory
Los Alamos, New Mexico 87545

Phone: 505-665-6892 (office), 505-667-9950 (lab)
Fax:   505-667-8021
email: cliu at lanl.gov
====================================================






  • Prev by Date: problem with Collect[] for long polynomial
  • Next by Date: Raising Contour Plot Graphics to 3D - II
  • Previous by thread: Re: Again, How to speed up this calculation? and more
  • Next by thread: Formatting and Printing