MathGroup Archive 2009

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

Search the Archive

Re: Fast calculation of pair correlation function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101619] Re: Fast calculation of pair correlation function
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 10 Jul 2009 23:26:43 -0400 (EDT)
  • References: <200904141019.GAA07830@smc.vnet.net> <h2v30e$ldj$1@smc.vnet.net>

On Jul 8, 10:54 pm, markus <markusg.p... at googlemail.com> wrote:
> Very interesting, I didn't know the HierarchicalClustering package
> until now. The DistanceMatrix function does exactly what I wanted
> to do. But, unfortunately, a list of 10^4 elements seems to be the
> maximum that this function can handle before the Kernel shuts down,
> telling me "No more memory available".
> I think it would be good to have the DistanceMatrix function in the
> Mathematica kernel, because it's a very time and memory consuming
> calculation.

With n = 12000 elements, the DistanceMatrix+Tally code runs out of
memory on my system, too, whereas the compiled code I posted needs
only O[n] space and has no problems. Moreover, with n = 10000, on my
system the compiled code takes only 39 sec, compared to 54 sec for
DMT. On a system such as Carl's, the compiled code should do 10000
elements in about 5.4 sec, and 12000 elements in about 7.6 sec.

        ....G5....   ....64-bit...........
  n     DMT   funk   DMT    estimated funk

10000    54    39    7.43   5.4 = 7.43*(39/54)

12000    --    55     --    7.6 = 55*(7.43/54)

Here is a revised version of the compiled code, that eliminates
the trailing zeros in the returned frequency-count vector:

funk = Compile[{{x,_Real,1},{y,_Real,1},{z,_Real,1},{w,_Real}},
Module[{n,m,f}, n = Length@x; m = 2 Ceiling[
Sqrt@Max[(x-Tr@x/n)^2 + (y-Tr@y/n)^2 + (z-Tr@z/n)^2]/w];
f = Table[0,{m}]; Do[Scan[f[[#]]++&, Ceiling[Sqrt[
(Drop[x,i]-x[[i]])^2 + (Drop[y,i]-y[[i]])^2 +
(Drop[z,i]-z[[i]])^2]/w]], {i,n-1}];
Take[f,While[f[[m]]==0,--m];m]]]


  • Prev by Date: Re: 2dFFT & image processing
  • Next by Date: Re: Is it possible to impose a condition on an iterator of
  • Previous by thread: Re: Fast calculation of pair correlation function
  • Next by thread: Re: Re: Re: Is Orange translucent? - What