# Use FindClusters with the following elements structure?

GROUPS:
 Each X-element below is a pair that has a label and xy-point.How do I cluster the X-elements using the distance between points? The code below balks because the data structure is incompatible with FindClusters. If X had points only then everything works. But here I must maintain the structure of X-elements for later use.I don't see a FindClusters option that would allow this. If another function works then I've missed it. Thanks.Bruce X = {{"a", {12, 30}}, {"b", {13, 31}}, {"c", {100, 102}}, {"d", {101, 103}}}; FindClusters[X, DistanceFunction -> (EuclideanDistance[Last@#1, Last@#2] &)] Error message is "FindClusters does not support this type of data"
1 year ago
5 Replies
 Sander Huisman 2 Votes Please have a look at the documentation next time:You can clearly see that $e_i$ are the values on which the distance is based and $v_i$ the return values. So it is just a matter of reshaping your input: X = {{"a", {12, 30}}, {"b", {13, 31}}, {"c", {100, 102}}, {"d", {101, 103}}}; input = Rule[#2, {##}] & @@@ X FindClusters[input] 
1 year ago
 Bruce Colletti 1 Vote Thank you for the reply, Sander. Your solution uses constructs with which I'm unfamiliar and I will study it.I did study the documentation in advance and saw what you pointed out. None of the documentation's examples (that used the e->v construct) returned what I needed and recognized. Neither did Mathematica Stack Exchange and so I turned to Wolfram Community. As usual, the response was excellent and informative.
1 year ago
 note that: input = Rule[#2, {##}] & @@@ X can be rewritten as: input = Table[i[[2]] -> i,{i,X}] or input = #[[2]] -> #& /@ X or input = MapThread[#2 -> {##} &, Transpose[X]] or input = Reap[Do[Sow@Rule[i[[2]], i], {i, X}]][[2, 1]] or input = Thread[Rule[X[[All, 2]], X]] or .........The last one should be one of the faster ones I presume...
1 year ago
 Bruce Colletti 1 Vote Thanks again, Sander, especially for the second line Table[i[[2]] -> i,{i,X}].This is an eye-opener, one more valuable than what my original posting had sought. Your example is the first time I've seen Table used in this way. No doubt it has been obvious all along but it's just now registering, after years of Mathematica use.I'm now using ## in other applications, thanks to your earlier reply.Bruce
1 year ago
 Frank Kampas 1 Vote I wonder if a Mathematica program could be written that would answer this kind of question.