3
$\begingroup$

I am working with a large list of elements, each of which are assigned five values. The first 3 are coordinates, while the remainder are other important properties. I need to cluster these elements using their coordinates only via the "FindClusters" command. Ideally, I would like some way to mask or hide the last two properties for each element during the "FindClusters" evaluation so that they remain grouped with the coordinates when they are clustered, and then I can unmask them. However, I am not sure that is even possible.

If the above technique isn't possible, then I need to recombine each elements' coordinates back with its other properties after it has been clustered. What is the most computationally efficient way to do this? It would seem such a solution would return the recombined result while simultaneously eliminating said element from further consideration. Also, a result would only be returned when a recombination had been made, eliminating the proliferation of "Nulls" currently plaguing the program.

I have been able to derive the solution below, but it is extremely inefficient as the vast majority of the calculations return "Null":

numPart = 10^5;
partList = RandomReal[{-9, 9}, {numPart, 5}];
coordList = partList[[All, 1 ;; 3]];
clustList = FindClusters[coordList]; 

ParallelTable[If[clustList[[j, i]] == partList[[k, 1 ;; 3]],
Flatten[AppendTo[clustList[[j, i]], partList[[k, 4 ;;]]]]],
{j, 1, numClust},
{i, 1, clustLength[[j]]}, {k, 1, numPart}];
$\endgroup$
7
$\begingroup$

I believe this input form solves the problem directly:

enter image description here

For your data this would be:

FindClusters[coordList -> partList]

A simplified example:

foo = {{1, 6, 2}, {2, 1, 7}, {10, 3, 3}, {12, 7, 4}, {3, 8, 5}, {1, 9, 9}, {13, 4, 
   1}, {25, 9, 1}};

bar = foo[[All, 1]];

FindClusters[bar]

FindClusters[bar -> foo]
{{1, 2, 3, 1}, {10, 12, 13, 25}}

{{{1, 6, 2}, {2, 1, 7}, {3, 8, 5}, {1, 9, 9}},
 {{10, 3, 3}, {12, 7, 4}, {13, 4, 1}, {25, 9, 1}}}
$\endgroup$
  • $\begingroup$ So FindClusters[coordList -> partList] took 6 seconds on my laptop (with $10^5$ data points coming from two joint balls, to make indeed two clusters). Neat, +1. $\endgroup$ – corey979 Nov 12 '16 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.