15

As a newbie in Machine Learning, I have a set of trajectories that may be of different lengths. I wish to cluster them, because some of them are actually the same path and they just SEEM different due to the noise.

In addition, not all of them are of the same lengths. So maybe although Trajectory A is not the same as Trajectory B, yet it is part of Trajectory B. I wish to present this property after the clustering as well.

I have only a bit knowledge of K-means Clustering and Fuzzy N-means Clustering. How may I choose between them two? Or should I adopt other methods?

Any method that takes the "belongness" into consideration? (e.g. After the clustering, I have 3 clusters A, B and C. One particular trajectory X belongs to cluster A. And a shorter trajectory Y, although is not clustered in A, is identified as part of trajectory B.)

=================== UPDATE ======================

The aforementioned trajectories are the pedestrians' trajectories. They can be either presented as a series of (x, y) points or a series of step vectors (length, direction). The presentation form is under my control.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174

4 Answers4

13

It might be a little late but I am also working on the same problem. I suggest you take a look at TRACLUS, an algorithm created by Jae-Gil Lee, Jiawei Han and Kyu-Young Wang, published on SIGMOD’07. http://web.engr.illinois.edu/~hanj/pdf/sigmod07_jglee.pdf

This is so far the best approach I have seen for clustering trajectories because:

  • Can discover common sub-trajectories.
  • Focuses on Segments instead of points (so it filters out noise-outliers).
  • It works over trajectories of different length.

Basically is a 2 phase approach:

  1. Phase one - Partition: Divide trajectories into segments, this is done using MDL Optimization with complexity of O(n) where n is the numbers of points in a given trajectory. Here the input is a set of trajectories and output is a set of segments.

    • Complexity: O(n) where n is number of points on a trajectory
    • Input: Set of trajectories.
    • Output: Set D of segments
  2. Phase two - Group: This phase discovers the clusters using some version of density-based clustering like in DBSCAN. Input in this phase is the set of segments obtained from phase one and some parameters of what constitutes a neighborhood and the minimum amount of lines that can constitute a cluster. Output is a set of clusters. Clustering is done over segments. They define their own distance measure made of 3 components: Parallel distance, perpendicular distance and angular distance. This phase has a complexity of O(n log n) where n is the number of segments.

    • Complexity: O(n log n) where n is number of segments on set D
    • Input: Set D of segments, parameter E that sets neighborhood treshold and parameter MinLns that is the minimun number of lines.
    • Output: Set C of Cluster, that is a Cluster of segments (trajectories clustered).

Finally they calculate a for each cluster a representative trajectory, which is nothing else that a discovered common sub-trajectory in each cluster.

They have pretty cool examples and the paper is very well explained. Once again this is not my algorithm, so don't forget to cite them if you are doing research.

PS: I made some slides based on their work, just for educational purposes: http://www.slideshare.net/ivansanchez1988/trajectory-clustering-traclus-algorithm

1vand1ng0
  • 1,203
  • 1
  • 16
  • 18
  • 2
    Great answer, this is exactly what ended up using (1 year ago, lol). – Sibbs Gambling Mar 17 '15 at 05:34
  • Cool @SibbsGambling, Where your results close to what you expected. In case you are interested I can post the results of my attempt to approximate trajectory clustering when I finish my research. My plan is to use an approximation to reduce time complexity via Locality sensitive Hashing. – 1vand1ng0 Mar 17 '15 at 23:12
  • Just in case someone is interested, this is my implementation of the traclus algorithm (in Java). Needs some refactoring and tuning but is working. https://github.com/ivansanchezvera/TrajectoryClustering – 1vand1ng0 Apr 26 '15 at 14:52
  • 1
    @1vand1ng0 does your implementation support 3D positions? Every TraClus implementation I've found is 2D only, even though the original paper says any number of dimensions is possible. – beldaz Feb 01 '22 at 05:08
  • 1
    @beldaz My implementation only supports 2D positions. I did that quite some years ago and I think my implementation is not the most efficient one, my skills have improved but haven't had the time to redo the project, so I suggest you do your own better developed implementation =) . I guess you could extrapolate it to any number of dimensions with the computational overhead to compute the distances, I think 3 dimensions is feasible. – 1vand1ng0 Feb 03 '22 at 15:21
9

Every clustering algorithm needs a metric. You need to define distance between your samples. In your case simple Euclidean distance is not a good idea, especially if the trajectories can have different lengths.

If you define a metric, than you can use any clustering algorithm that allows for custom metric. Probably you do not know the correct number of clusters beforehand, then hierarchical clustering is a good option. K-means doesn't allow for custom metric, but there are modifications of K-means that do (like K-medoids)

The hard part is defining distance between two trajectories (time series). Common approach is DTW (Dynamic Time Warping). To improve performance you can approximate your trajectory by smaller amount of points (many algorithms for that).

kudkudak
  • 496
  • 3
  • 7
  • 2
    -1 : you cannot use K-means if you define a custom metric. K-means is well defined only for the eucliean metric. K-medoids or kernelized k-means can overcome this limitation but at the cost of additional computational resources. – lejlot Sep 16 '13 at 09:14
  • now the answer is inconsistent, simply remove the part saying that "If you define a metric, than every clustering algorithm is viable" instead of just adding clarification on the end. It will be much more valuable for the reader. – lejlot Sep 16 '13 at 09:30
  • 1
    Actually, no. There are clustering algorithms that do not need a metric. E.g. COOLCAT. It's just that those that can work with arbitrary distances (most do not need a metric, just a dissimilarity) are more flexible, if the user cares to choose a good distance for his problem. – Has QUIT--Anony-Mousse Sep 17 '13 at 07:31
  • 2
    @Anony Mousse has a good point about making clear distinction between *metric* and *dissimilarity*. This can also be a case for clustering method usind pseudo-kernels (which do not induce the kernel-metric) As well as clusterings based on some model/distribution fitting, where we do not care about any concept of *distance* between data, we rather measure probability of coming from some parametrized model (which is not just a point in the input space). – lejlot Sep 17 '13 at 10:40
7

Neither will work. Because what is a proper mean here?

Have a look at distance based clustering methods, such as hierarchical clustering (for small data sets, but you probably don't have thousands of trajectories) and DBSCAN.

Then you only need to choose an appropriate distance function that allows e.g. differences in time and spatial resolution of trajectories.

Distance functions such as dynamic time warping (DTW) distance can accomodate this.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • 1
    You could use K-Means with DTW as a distance measure (to determine similarity) and calculate the centroid in each iteration using DBA, which is a new method to average different time series when DTW is used as a metric. http://www.cs.ucr.edu/~eamonn/ICDM_2014_DTW_average.pdf – 1vand1ng0 Sep 07 '15 at 08:47
0

This is good concept and having possibility for real-time applications. In my view, one can adopt any clustering but need to select appropriate dissimilarity measure, later need to think about computational complexity. Paper (http://link.springer.com/chapter/10.1007/978-81-8489-203-1_15) used Hausdorff and suggest the technique for reducing complexity, and paper (http://www.cit.iit.bas.bg/CIT_2015/v-15-2/4-5-TCMVS%20A-edited-md-Gotovop.pdf) described the use of "Trajectory Clustering Technique Based on Multi-View Similarity"

Dr KP
  • 1