# Tag Info

32

ClusteringComponents is indeed the function to go for. To get the same results as MATLAB you need to do the following: x = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25}}; cc = ClusteringComponents[x, 2, 1, Method -> "KMeans", "DistanceFunction" -> SquaredEuclideanDistance, "...

26

Since Mr.Wizard mentions that ClusteringComponents is unavailable in Mathematica 7, here's an implementation of Lloyd's algorithm for k-means clustering (can also be interpreted as an Expectation-Maximization approach) that will run on version 7. Clear[kmeans] kmeans[list_, k_, opts : OptionsPattern[ {DistanceFunction -> SquaredEuclideanDistance, "...

24

Finding the cluster centers is the hard part. There are zillions of ways to do this, such as standardizing $(x,y,t)$ and applying some (almost any) kind of cluster analysis. But these data are special: the eye movement has a measurable speed. The gaze is resting if and only if the speed is low. The threshold for "low" is physically determined (but can ...

18

I think FindClusters is ideal tool. It just needs slight tweaking. One of your data sets: data = gazeSeq[3][[All, ;; 2]]; This works: Show[ ListPlot[#, PlotStyle -> PointSize[.003]], Graphics[{Red, Thick, Circle[#, .3]}& /@ Mean/@ #], AspectRatio -> Automatic, PlotRange -> All, Frame -> True, Axes -> False ]& @ ...

16

Your data seems to be composed of two components: An offset for each x-location (or an offset-function of x) and a density relative to that offset. If you had either of the two, estimating the other would be easy. Right so far? One common solution for this kind of problem is the EM algorithm. Basically, you start with some estimate for one variable (e.g. ...

14

DendrogramPlot accepts Axes as an option. Despite syntax highlighting in red of Axes and AxesOrigin, GridLines etc. these options seem to work with DendrogramPlot. Inter-cluster distance in a Cluster object is given as the third element. Several combinations of DistanceFunction and Linkage where inter-cluster distances are highlighted in red and shown as ...

13

In version 7 and 8 you have MorphologicalComponents which can do this. Its default Method (version 8) is "Connected" with 8 point connectivity being the default (you can switch this off with the option CornerNeighbors->False). So, this seems ideally suited to your requirements. An example from the MorphologicalComponents doc page:

13

Here is an image processing solution that gives you the following result for the 7 different datasets: Approach: First, we plot it without any frames or axes and convert to a binary image. plotRange = Function[xy, #[gazeSeq[2][[All, xy]]] & /@ {Min, Max}] /@ {1, 2}; img = Image@ListPlot[gazeSeq[2][[All, ;; 2]], Axes -> False, PlotRange -> ...

12

This is a straightforward application of FindClusters: ListPlot@FindClusters[#, 2] & /@ Transpose@PairSet // GraphicsRow See the DistanceFunction and Method options to further fine tune your clustering or use a different metric.

12

Here's some code implementing the purely local strategy suggested in my comment. points = << "~/tmp/Plot B Points.txt"; xwidth = 200; ywidth = 0.1; binnedPoints = Partition[points, xwidth]; histograms = BinCounts[#, {Min@points, Max@points, ywidth}] & /@ binnedPoints; align[a_, b_] := First@Ordering[ListCorrelate[a, b, {-1, 1}, 0], -1] - Length@a; ...

12

Here is one solution. Find a small number of nearest neighbors (NN's) for each point. Make a graph each node of which corresponds to a data point and each edge corresponds to a NN's pair. Partition the graph into connected components, or communities, or cliques. In order the last step to work well, it might be a good idea to remove the points in the ...

11

The problem is that your "Background" is not a cluster with the usual distance function. You can tweak it (to some extent) with something like: data1 = RandomReal[{-0.1, 0.1}, {10^2, 2}]; data2 = RandomReal[{-1, 1}, {2*10^2, 2}]; data3 = RandomReal[{-0.3, -0.2}, {2*10^2, 2}]; data5 = Join[data1, data2, data3]; ListPlot[FindClusters[data5, ...

11

Try this: First, set the distance threshold. d = 0.1; The main function uses Fold, which, along with its companion FoldList and MapThread, is one of the most useful "functional" functions in the language. test = Fold[If[EuclideanDistance[Most@#2, Mean[Most /@ Last[#1]]] < d, Join[Most[#1], {Join[Last[#1], {#2}]}], Join[#1, {{#2}}]] &, ...

11

Based on the data you provide, it seems that hierarchical clustering (see wiki here) with type "agglomerate" (bottom up) solves your problem, i.e.: out = FindClusters[data, 6, Method -> "Agglomerate"]; ListPointPlot3D[out] and get: Based on how your full dataset looks like (e.g. if you know how many clusters there are etc.), you might need to adapt ...

11

This generates a 20 by 20 binary matrix and finds the morphological components. SeedRandom[11]; m=RandomInteger[{0,1},{20,20}]; a=MorphologicalComponents[m,CornerNeighbors->False] Notice that morphological component 2, in row 1, col 6, abuts morphological component 42 in row 20, col 6. Morphological components 2 and 39 abut in column 8. These ...

10

The code below is very instructive. I get from Sjoerd C. de Vries's comment here. GraphicsGrid[ Table[ data1 = Table[{RandomReal[]/5, RandomReal[]}, {100}]; data2 = Table[{RandomReal[]/5 + distance, RandomReal[]}, {100}]; dataM = Flatten[{data1, data2}, 1] // RandomChoice[#, Length[#]] &; Table[clusters = ClusteringComponents[dataM, 2, 1,...

9

This may give you a start. Code below is built on an example from this page, where you can find more very neat stats examples. Get some data on duration of Old Faithful geyser eruptions and construct a distribution based on it: data = ExampleData[{"Statistics", "OldFaithful"}]; \[ScriptCapitalD] = KernelMixtureDistribution[data, "SheatherJones"]; Now ...

9

You can get the same results with: FindClusters[pts, Method -> {"Agglomerate", "Linkage" -> "Complete", "SignificanceTest" -> {"Gap", "Tolerance" -> 3}}] But it is impossible to test its significance until you post more point sets.

8

Clustering is a relatively unstable process. Points which exist near to cluster boundaries may have small Euclidean, or other, distances between them, but be on different sides of the local boundary. So, in and of themselves, point separation distance metrics may be misleading. If clusters in the data overlap to any degree, a common case, then there is ...

8

I tested ClusteringComponents with the examples provided in the Documentation Center (http://reference.wolfram.com/mathematica/ref/ClusteringComponents.html) of Mathematica. In Options > DistanceFunction there is an example provided how to use your own DistanceFunction in ClusteringComponents: ClusteringComponents[{{1, 2}, 3, {10, 11}, {12, {13}}, 14}, 2, 1,...

8

Use the Bray-Curtis distance Total[Abs[u-v]]/Total[Abs[u+v]]: FindClusters[{110, 111, 115, 117, 251, 254, 254, 259, 399, 400, 401, 402, 542, 546, 549, 554, 660, 660, 660, 660}, DistanceFunction -> BrayCurtisDistance] (* {{110, 111, 115, 117}, {251, 254, 254, 259}, {399, 400, 401, 402}, {542, 546, 549, 554}, {660, ...

8

One possible approach is to look for a larger number of clusters, so that the background is split into multiple clusters. c = FindClusters[data5, 8]; ListPlot[c] The data clusters will be those with a larger number of members and smaller size (not necessarily true - see update) ListPlot[ Transpose[{{Length /@ c, Sqrt[Total[Variance[#]]] & /@ c}}, {...

8

Apart from the output format, the main differences are: FindClusters can take a custom DistanceFunction whereas ClusteringComponents can only use those listed in the documentation FindClusters works with strings and lists of True/False but ClusteringComponents only takes numerical arrays FindClusters takes a 1D list as input, ClusteringComponents can take ...

8

I guess this is approximately what you want: ListLogPlot[ FindClusters[Standardize@mydata, 3, Method -> {"Agglomerate", "Linkage" -> "Complete"}] /. Thread[Standardize@mydata -> mydata], PlotStyle -> {Directive[Red, PointSize[Large]], Directive[Blue, PointSize[Large]], Directive[Green, PointSize[Large]]...

8

Some time ago (before Mathematica had the function Classify) I developed a package for construction of Decision trees and classification with them. The trees produced by that package might be a good start for making the trees from the three different perspectives listed in the question. More precisely, with the package one can build a tree using entropy ...

7

Here I can give you some direction! Bi-variate Data We draw random data from a built-in distribution in MMA. First see the PDF of our BinormalDistribution. Now we draw some $10000$ data sample and visualize it using ListPlot data = With[{\[Rho] = -0.4}, RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, \[Rho]],10000]]; ListPlot[data, Frame -> ...

7

The following seems to work at least for small grayscale images and a few points. My current computing power doesn't allow me to test it for larger examples. As this question was posed more than three years ago I decided to post this, despite the fact that I don't know how it scales. It makes a Voronoi partition and minimizes the Variance of the region ...

7

If you want something like this : (colors are random) the code is : dendogram = DendrogramPlot[data, LeafLabels -> Range[12], HighlightLevel -> 3, HighlightStyle -> {Red, Green, Blue}]; Show[ dendogram, Graphics[(Cases[dendogram, Rectangle[___], {1, Infinity}] // SortBy[#, -#[[2, 2]] &] & ) /. x : Rectangle[...

7

This is roughly 30 times faster than your approach and can be tuned easier than FindClusters[]: getOneCluster[pts_List, maxDist_?NumericQ] :=(*Returns a cluster*) Module[{f}, f = Nearest[pts]; FixedPoint[Union@Flatten[f[#, {Infinity, maxDist}] & /@ #, 1] &, {First@pts}]] clusters[data_] := Module[{f, dist}, (* Some Characteristic Distance, ...

7

I've spotted three issues with your approach and posted code: Spectral clustering uses the eigenvectors associated with the $k$ smallest eigenvalues of the Laplacian, but your code is selecting those associated with the $k$ largest eigenvalues. You need to Transpose your Kvecs prior to passing them to ClusteringComponents. As currently written, you're ...

Only top voted, non community-wiki answers of a minimum length are eligible