New answers tagged

5

Update: You can go even faster with Compile, and exploit the Listable and Parallelization attributes to great effect, if you have a multi-core machine: SeedRandom[0]; cluster = RandomReal[{0, 1}, {5000, 14}]; myDistMatrix = Compile[{{point, _Real, 1}, {tr, _Real, 2}}, Total[(point - tr)^2], RuntimeOptions -> "Speed", ...


4

This is much faster: distMatCompiled = Compile[{{cluster, _Real, 2}}, Outer[Function[diff, diff.diff][#1 - #2] &, cluster, cluster, 1, 1] , CompilationTarget -> "C" ] medoidCompiled[cluster_] := Block[{distances, indexOfMin}, distances = Total@distMatCompiled[cluster]; indexOfMin = First[Ordering[distances, 1]]; {cluster[[indexOfMin]], ...


5

If you're on 10.3+, this should be faster (it's two orders of magnitude faster than your first example on my loungebook): medioid=With[{m = #, d = Tr /@ DistanceMatrix[#, DistanceFunction ->SquaredEuclideanDistance]}, {First@m[[#]], First@#} &@Pick[Range@Length@d, d, Min@d]]&;


2

I think I figured it out. (I should have thought of this before.) Basically, I clustered the data with all possible values of the SignificanceTest suboption, including the "no setting" case (i.e. the default), and compared the results. So it looks like the answer to my question is Gap. FWIW, here's the code to generate datapairs, pretty much as given ...


3

Post-processing the DendrogramPlot output to extract the cluster distances and placing them in appropriate locations: dplt = DendrogramPlot[DirectAgglomerate[data, Style[#, 16] & /@ {"G1", "G2", "G3", "G4", "G5", "G6"}, Linkage -> "Single"], LeafLabels -> Automatic, Orientation -> Right, PlotStyle -> {Red, Thick}, Axes ...



Top 50 recent answers are included