5
$\begingroup$

I have data like this:

data = {5, 12, 18, 19, 20, 23, 24, 26};

number line

On Mathematica 11.1, clustering produces a variable final choice of clusters. For example:

Tally@Table[ClusteringComponents[data, Method -> "Agglomerate"], 100]

gives:

{{{1, 2, 3, 3, 3, 3, 3, 3}, 74}, {{1, 2, 2, 2, 3, 3, 3, 3}, 8},
 {{1, 2, 2, 3, 3, 3, 3, 3}, 18}}

But on Mathematica 10.4, I always get:

{{{1, 2, 2, 2, 2, 2, 2, 2}, 100}}

Fixing the number of clusters in Mathematica 11.1:

Tally@Table[ClusteringComponents[data, 2, Method -> "Agglomerate"], 100]

also produces a variable answer:

{{{1, 2, 2, 2, 2, 2, 2, 2}, 30}, {{1, 1, 2, 2, 2, 2, 2, 2}, 70}}

Is this correct? If so, what has changed and how is this final decision controlled?


As mentioned in Alexey's comment, you can control randomness with RandomSeeding. However, it remains unclear to me why version 10.4 gives a different answer to the random answers of v11.1. In other words, there does not seem to be a random seed for v11.1 that will give the same answer as v10.4.

To clarify further, the first data point (5) has a greater distance to 12 than between any of the other neighbouring points. Hence, using single linkage shouldn't one expect the first data point to be one of the final two clusters?

$\endgroup$
  • $\begingroup$ mathematica.stackexchange.com/a/140427 $\endgroup$ – Alexey Golyshev Apr 13 '17 at 6:57
  • $\begingroup$ @AlexeyGolyshev, with regard to the link you mention, I get the same clusters whether I use FindClusters or ClusteringComponents. $\endgroup$ – Simplex Apr 17 '17 at 6:40
  • $\begingroup$ With version 11.0.1 I get {{{1, 1, 1, 1, 1, 1, 1, 1}, 100}} for the input Tally@Table[ClusteringComponents[data, Method -> "Agglomerate"], 100]. $\endgroup$ – Alexey Popkov Apr 18 '17 at 4:05
4
$\begingroup$

There is undocumented option RandomSeeding.

SeedRandom[0];
data = RandomInteger[{1, 30}, {100, 8}];

c1 = ClusteringComponents[data, 2, Method -> "Agglomerate", RandomSeeding -> 0];
c2 = ClusteringComponents[data, 2, Method -> "Agglomerate", RandomSeeding -> 0];

c1 === c2

True

What is the most convenient way to read definitions of in-memory symbols when we don't have the source files?

$\endgroup$
  • $\begingroup$ Thank you. I have edited my question to clarify what I think remains unanswered. $\endgroup$ – Simplex Apr 13 '17 at 6:14
3
$\begingroup$

Wolfram Technical Support have clarified the situation as described above (for Agglomerate). Here is my interpretation of the discussion:

  • ClusteringComponents in v11.1 uses ClusterClassify to produce the final clusters.
  • A set of clusters ("training clusters") is chosen using a single-linkage Agglomerate algorithm. This is deterministic as expected.
  • ClusterClassify is designed to generalise (to some extent) to future classification problems. Therefore, it picks a representative from each training cluster near the centroid of each cluster. This selection is nondeterministic.
  • This classifier is then run against the original data to produce the final set of clusters (which can therefore be different to the "training clusters").
  • Setting RandomSeeding can help with this randomness. However, this does not necessarily recover the original deterministic clusters used to train the classifier, and nor does it match the results of Mathematica 10.4 (which is a straightforward, deterministic clustering of the data supplied).
  • There does not appear to be a simple workaround for this, although ClusteringTree can be used to visualise the underlying hierarchy.
$\endgroup$

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.