Skip to content

Commit db2f22b

Browse files
committed
Updated README.md with documentation and added NetLogo demo.
1 parent f83ba5a commit db2f22b

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,84 @@
11
# NetLogo-Extension-DBSCAN
22
NetLogo extension for DBSCAN clustering algorithm
3+
4+
It allows you to perform unsupervised density-based clustering based on specified turtle variables or proximity. The main advantage over supervised algorithms such as K-Means is that it is not necessary to specify the number of resulting clusters in advance.
5+
6+
## Usage
7+
8+
The extension contains two reporters, `cluster-by-variable` and `cluster-by-location`.
9+
10+
### Clustering by variable
11+
12+
Syntax: `cluster-by-variable` *agents-to-be-clustered* *cluster-variable* *minimum-members* *maximum-distance*
13+
14+
Clusters a given agentset *agents-to-be-clustered* by variable *cluster-variable*, requiring a minimum of *minimum-members* agents to constitute a cluster within a range of variable value difference, with the maximum value difference being *maximum-distance*.
15+
16+
The reporter returns a nested list of clustered agents.
17+
18+
Example:
19+
20+
```
21+
22+
... instantiate agents with variable "wealth" ...
23+
24+
; Cluster agents by variable "wealth", with at least 3 members to constitute a cluster, and a maximum value difference of 3
25+
let clusters dbscan:cluster-by-variable agents "wealth" 3 3
26+
27+
; Colour and label the agents by cluster
28+
let ctr 1
29+
(foreach clusters (n-of (length clusters) base-colors)
30+
[ let aset turtles with [member? self ?1 ]
31+
ask aset
32+
[ set color ?2
33+
set label (word "ID: " who ", Cluster: " ctr ", Wealth: " wealth) ]
34+
; Print agent sets
35+
output-print (word "Cluster " ctr ": " aset)
36+
set ctr (ctr + 1) ])
37+
```
38+
39+
### Clustering by location
40+
41+
`cluster-by-location` *agentset-to-be-clustered* *minimum-members* *maximum-distance*
42+
43+
Clusters a given agentset *agents-to-be-clustered* by proximity, requiring a minimum of *minimum-members* agents to constitute a cluster with a maximum distance *maximum-distance*.
44+
45+
The reporter returns a nested list of clustered agents.
46+
47+
Example:
48+
49+
... instantiate agents with coordinates ...
50+
51+
; Cluster agents by location, with at least 3 members to constitute a cluster, and a maximum distance of 3
52+
let clusters dbscan:cluster-by-location agents 3 3
53+
54+
; Colour and label individual agents by cluster
55+
let ctr 1
56+
(foreach clusters (n-of (length clusters) base-colors)
57+
[ let aset turtles with [member? self ?1 ]
58+
ask aset
59+
[ set color ?2
60+
set label (word "ID: " who ", Cluster: " ctr) ]
61+
; Print agent sets
62+
output-print (word "Cluster " ctr ": " aset)
63+
set ctr (ctr + 1) ])
64+
```
65+
66+
## Demo
67+
68+
For more comprehensive examples for both reporters, try out the demo under `demo/dbscan-clustering-demo.nlogo`
69+
70+
Clustering agents by location should produce the following output.
71+
72+
![Location-based clustering demo output](https://github.com/chrfrantz/NetLogo-Extension-DBSCAN/raw/master/doc/ExampleLocationBasedClusteringOutput.png)
73+
74+
## Deployment
75+
76+
### Variant 1: Downloading jar files
77+
78+
To install the extension, download the zip file containing the latest version from the releases page and unzip it in the `NetLogo/extensions` folder of your NetLogo installation (the final structure should be `NetLogo/extensions/dbscan/<jar files>`).
79+
80+
### Variant 2: Building from source
81+
82+
You can build the extension from scratch using maven by running `mvn package` after cloning the repository. In addition, you will need to do the same for the [DBSCAN repository](https://github.com/chrfrantz/DBSCAN.git) which contains the underlying DBSCAN algorithm. Place both jar files in the extensions subfolder `dbscan` (see Variant 1).
83+
84+

demo/dbscan-clustering-demo.nlogo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ end
3232
to cluster-by-variable
3333
setup
3434

35+
; Cluster agents by variable "wealth", with at least 3 members to constitute a cluster, and a maximum value difference of 3
3536
let clusters dbscan:cluster-by-variable agents "wealth" 3 3
3637

3738
; Show number of clusters
@@ -57,6 +58,7 @@ end
5758
to cluster-by-location
5859
setup
5960

61+
; Cluster agents by location, with at least 3 members to constitute a cluster, and a maximum distance of 3
6062
let clusters dbscan:cluster-by-location agents 3 3
6163

6264
; Show number of clusters
22.6 KB
Loading

0 commit comments

Comments
 (0)