File: v.cluster.html

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (212 lines) | stat: -rw-r--r-- 8,088 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<h2>DESCRIPTION</h2>

<em>v.cluster</em> partitions a point cloud into clusters or clumps.

<p>
If the minimum number of points is not specified with the <b>min</b>
option, the minimum number of points to constitute a cluster is
<i>number of dimensions + 1</i>, i.e. 3 for 2D points and 4 for 3D
points.

<p>
If the maximum distance is not specified with the <b>distance</b>
option, the maximum distance is estimated from the observed distances
to the neighbors using the upper 99% confidence interval.

<p>
<em>v.cluster</em> supports different methods for clustering. The
recommended methods are <b>method=dbscan</b> if all clusters should
have a density (maximum distance between points) not larger than
<b>distance</b> or <b>method=density</b> if clusters should be created
separately for each observed density (distance to the farthest neighbor).

<h3>Clustering methods</h3>

<h4>dbscan method</h4>
The <a href="https://en.wikipedia.org/wiki/DBSCAN">Density-Based Spatial
Clustering of Applications with Noise</a> is a commonly used clustering
algorithm. A new cluster is started for a point with at least
<i>min</i> - 1 neighbors within the maximum distance. These neighbors
are added to the cluster. The cluster is then expanded as long as at
least <i>min</i> - 1 neighbors are within the maximum distance for each
point already in the cluster.

<h4>dbscan2 method</h4>
Similar to <i>dbscan</i>, but here it is sufficient if the resultant
cluster consists of at least <b>min</b> points, even if no point in the
cluster has at least <i>min - 1</i> neighbors within <b>distance</b>.

<h4>density method</h4>
This method creates clusters according to their point density. The
maximum distance is not used. Instead, the points are sorted ascending
by the distance to their farthest neighbor (core distance), inspecting
<i>min - 1</i> neighbors. The densest cluster is created first, using
as threshold the core distance of the seed point. The cluster is
expanded as for DBSCAN, with the difference that each cluster has its
own maximum distance. This method can identify clusters with different
densities and can create nested clusters.

<h4>optics method</h4>
This method is
<a href="https://en.wikipedia.org/wiki/OPTICS_algorithm">Ordering Points to
Identify the Clustering Structure</a>. It is controlled by the number
of neighbor points (option <i>min</i> - 1). The core distance of a
point is the distance to the farthest neighbor. The reachability of a
point <i>q</i> is its distance from a point <i>p</i> (original optics:
max(core-distance(p), distance(p, q))). The aim of the <i>optics</i>
method is to reduce the reachability of each point. Each unprocessed
point is the seed for a new cluster. Its neighbors are added to a queue
sorted by smallest reachability if their reachability can be reduced.
The points in the queue are processed and their unprocessed neighbors
are added to a queue sorted by smallest reachability if their
reachability can be reduced.

<p>
The <i>optics</i> method does not create clusters itself, but produces
an ordered list of the points together with their reachability. The
output list is ordered according to the order of processing: the first
point processed is the first in the list, the last point processed is
the last in the list. Clusters can be extracted from this list by
identifying valleys in the points' reachability, e.g. by using a
threshold value. If a maximum distance is specified, this is used to
identify clusters, otherwise each separated network will constitute a
cluster.

<p>
The OPTICS algorithm uses each yet unprocessed point to start a new
cluster. The order of the input points is arbitrary and can thus
influence the resultant clusters.

<h4>optics2 method</h4>
<b>EXPERIMENTAL</b> This method is similar to OPTICS, minimizing the
reachability of each point. Points are reconnected if their
reachability can be reduced. Contrary to OPTICS, a cluster's seed is
not fixed but changed if possible. Each point is connected to another
point until the core of the cluster (seed point) is reached.
Effectively, the initial seed is updated in the process. Thus separated
networks of points are created, with each network representing a
cluster. The maximum distance is not used.

<h2>NOTES</h2>

By default, cluster IDs are stored as category values of the points
in layer 2.

<h2>EXAMPLE</h2>

Analysis of random points for areas in areas of the vector
<i>urbanarea</i> (North Carolina sample dataset).

<p>
First generate 1000 random points within the areas the vector urbanarea
and within the subregion, then do clustering and visualize the result:

<div class="code"><pre>
# pick a subregion of the vector urbanarea
g.region -p n=272950 s=188330 w=574720 e=703090 res=10

# create random points in areas
v.random output=random_points npoints=1000 restrict=urbanarea

# identify clusters
v.cluster input=random_points output=clusters_optics method=optics

# set random vector color table for the clusters
v.colors map=clusters_optics layer=2 use=cat color=random

# display in command line
d.mon wx0

# note the second layer and transparent (none) color of the circle border
d.vect map=clusters_optics layer=2 icon=basic/point size=10 color=none
</pre></div>


<center>
<img src="v_cluster_4_methods.png">
<p><em>
    Figure: Four different methods with default settings applied to
    1000 random points generated in the same way as in the example.
</em></p>
</center>

<!--
g.region -p n=272950 s=188330 w=574720 e=703090 res=10
v.random output=rand_clust npoints=1000 restrict=urbanarea

v.cluster in=rand_clust out=rand_clusters_dbscan method=dbscan
v.colors map=rand_clusters_dbscan layer=2 use=cat color=random

v.cluster in=rand_clust out=rand_clusters_dbscan2 method=dbscan2
v.colors map=rand_clusters_dbscan2 layer=2 use=cat color=random

v.cluster in=rand_clust out=rand_clusters_density method=density
v.colors map=rand_clusters_density layer=2 use=cat color=random

v.cluster in=rand_clust out=rand_clusters_optics2 method=optics2
v.colors map=rand_clusters_optics2 layer=2 use=cat color=random

v.cluster in=rand_clust out=rand_clusters_optics method=optics
v.colors map=rand_clusters_optics layer=2 use=cat color=random

# seems we have to remove first to avoid drawing into an old image
rm v_cluster_4_methods.png

d.mon cairo out=v_cluster_4_methods.png

# the font doesn't work
d.font "LiberationSans-Regular"

d.frame frame=dbscan at=50,100,0,50 -c
d.vect map=rand_clusters_dbscan layer=2 icon=basic/point size=10 color=none
d.text text="dbscan" at=5,5 size=10 bgcolor=white

d.frame frame=optics at=50,100,50,100 -c
d.vect map=rand_clusters_optics layer=2 icon=basic/point size=10 color=none
d.text text="optics" at=5,5 size=10 bgcolor=white

d.frame frame=density at=0,50,0,50 -c
d.vect map=rand_clusters_density layer=2 icon=basic/point size=10 color=none
d.text text="density" at=5,5 size=10 bgcolor=white

d.frame frame=optics2 at=0,50,50,100 -c
d.vect map=rand_clusters_optics2 layer=2 icon=basic/point size=10 color=none
d.text text="optics2" at=5,5 size=10 bgcolor=white

d.mon stop=cairo
-->

Generate random points for analysis (100 points per area), use different
method for clustering and visualize using color stored the attribute table.

<div class="code"><pre>
# pick a subregion of the vector urbanarea
g.region -p n=272950 s=188330 w=574720 e=703090 res=10

# create clustered points
v.random output=rand_clust npoints=100 restrict=urbanarea -a

# identify clusters
v.cluster in=rand_clust out=rand_clusters method=dbscan

# create colors for clusters
v.db.addtable map=rand_clusters layer=2 columns="cat integer,grassrgb varchar(11)"
v.colors map=rand_clusters layer=2 use=cat color=random rgb_column=grassrgb

# display with your preferred method
# remember to use the second layer and RGB column
# for example use
d.vect map=rand_clusters layer=2 color=none rgb_column=grassrgb icon=basic/circle
</pre></div>

<h2>SEE ALSO</h2>

<em>
<a href="r.clump.html">r.clump</a>,
<a href="v.hull.html">v.hull</a>,
<a href="v.distance.html">v.distance</a>
</em>

<h2>AUTHOR</h2>

Markus Metz