Group Abstract Group Abstract

Message Boards Message Boards

Use FindClusters with the following elements structure?

Posted 9 years ago

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"

POSTED BY: Bruce Colletti
5 Replies
POSTED BY: Sander Huisman
Posted 9 years ago

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

POSTED BY: Bruce Colletti

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...

POSTED BY: Sander Huisman
Posted 9 years ago
POSTED BY: Bruce Colletti
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard