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

I wonder if a Mathematica program could be written that would answer this kind of question.

POSTED BY: Frank Kampas

Please have a look at the documentation next time:

enter image description here

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]
POSTED BY: Sander Huisman
Posted 9 years ago

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.

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard