# Clustering with Nature-Inspired Algorithm Based on Territorial Behavior of Predatory Animals
## 3 Proposed Approach
For each of those points, the individual calculates weight according to the equation \(P_{j}.weight=(M_{0}+Su)^{\frac{1}{b+distance(I_{i},p_{j}^{*})}}\), where \(P_{j}\) is the point being evaluated, \(M_{0}\), \(S\) and \(b\) are the parameters of the algorithm, and \(u\) is the ratio of unmarked points in the evaluated set of points. 2. After assigning weights, individuals 'jump' to single points they draw with weights they calculated. Those points become their new positions. 3. Each marked point is assigned a Time-to-Live value that begins at 0. Each time any of the individuals others than the one that marked the point is the closest individual to that point, the Time-to-Live is incremented. As it reaches \(t\frac{N}{F}\), the point becomes unmarked again. Should the individual that marked it become the closest individual, the Time-to-Live value is set to 0 again. 4. Individuals perform their jumps in turns until there are no unmarked points. After each turn Time-to-Live values are evaluated for all points in the dataset. ```
1:procedurefindClusters(\(dataSet\), \(k\), \(l_{correct}\), \(l_{search}\), \(b\),\(M_{0}\), \(S\), \(\alpha\), \(correctionRuns\), \(F\),\(T\))
2:\(MAXTOL\leftarrow\frac{N}{k}*T\)
3: Initialize \(I_{1},...I_{k}\) as individuals at positions of random points from the set
4: Set \(TTL\) of all points to 0
5: Set cluster numbers of all points in \(dataSet\) as \(null\)
6:forall\(I_{i}\)\(\in\) individuals do
7:\(randomNumber\gets randomIntegerFrom(0,dataSet.size)\)
8:\(I_{i}.position\gets dataSet[randomNumber].position\)
9:\(dataSet[randomNumber].cluster=I_{i}.clusterId\)
10: Remove \(randomNumber\) from futher random integer generation in this loop
11:endfor
12:while there exists at least one point with \(cluster=null\)do
13:for\(i\in[1,k]\)do
14:\(points\leftarrow\) set of \(l_{search}*dataSet.size\) closest points to \(I_{i}\)
15:\(u\leftarrow\frac{numberOf(points.unmarked)}{l_{search}*dataset.size}\)
16:forall\(P_{j}\in points\)do
17:\(P_{j}.weight\leftarrow(M_{0}+Su)^{\frac{1}{b+actual(j,P_{j})}}\)
18:endfor
19:\(pointToumpTo\gets randomizeWithWeights(points)\)
20:\(l_{i}.position\gets pointTojumpTo.position\)
21:\(pointToumpTo.cluster\gets I_{i}.clusterId\)
22:endfor
23:forall\(P_{j}\in marked\) points do
24:if There exists individual that is closer to \(P_{j}\) than the one that marked it then
25:\(TTL_{j}\gets TTL_{j}+1\)
26:if\(TTL_{j}>MAXTOL\)then
27:\(P_{j}.cluster\gets null\)
28:endif
29:endif
30: Else \(TTL_{j}\gets 0\)
31:endfor
32:endwhile
33:for\(iter=1,2,...,CR\)do
34:\(newClusterNumbers\leftarrow dataSet.clusterNumbers\)
35:forall\(P_{i}\in dataSet\)do
36:\(points\leftarrow\) set of \(l_{correct}*dataSet.size\) closest points to \(P_{i}\)
37: Initialize table of weights \(weights\), its size being the number of clusters
38:forall\(c\in c,1,2,...,k\)do
39:\(D_{mem}\leftarrow\) mean distance to all points from cluster \(c\) from \(points\)
40:\(p\leftarrow\) number of points from cluster \(c\) in \(points\) divided by size of \(points\)
41:\(weight[c]\gets F(D_{mem},p)\)
42:if\(c\
eq P_{i}.cluster\)then
43:\(weight[c]\gets weight[c]*\alpha\)
44:endif
45:endfor
46:\(maxWeight\gets indexOfMaxElement(weight)\)
47:\(newClusterNumbers[i]\leftarrow maxWeight\)
48:endfor
49:\(dataSet.clusterNumbers\gets newClusterNumbers\)
50:endforreturn\(dataSet.clusterNumbers\)
51:endprocedure
```  
**Algorithm 1** Clustering with Predatory Animals Algorithm. The second phase is focused on slight corrections to the clustered set--it aims to correct points that are surrounded by points from other clusters and not by the points from their own cluster. This is performed in the following way:  
1. During the correction phase, all points are evaluated separately. 2. \(t_{correction}*N\) nearest points to the evaluated one are considered. 3. For each point, for each cluster, values \(D_{mean}\) and \(p\) are calculated.