## 5 Clustering with Flocking
### Similarity and Dissimilarity  
The three basic rules of flocking allow the agents to move naturally as a group. In order to use it as a clustering algorithm, it is necessary to modify it so the similar agents will form a group and the dissimilar agents will avoid each other. Hence, two new forces are added: similarity and dissimilarity. These forces, described in [45], help the agents form clusters in an unsupervised manner without specifying the number we are looking for. The similarity of agents in clustering with flocking is primarily based on the measurement of distance. Since the spatial information is qualitative, the function cannot work as it is. An evaluation function becomes necessary to accomplish such a task. This evaluation function should be independent from the number of qualitative classes used (in our case, we have eight). An automatically generated graph could fill that role. Figure 7 represents the graph that was used in this project. The arcs between the nodes are weights representing the relation of similarity between directions. Those values are found by dividing the highest similarity value (100% similar) by half the number of different directions. The advantage of this method is that it creates a clear separation between the representation and the clustering algorithm. In consequence, the directions framework could be changed (to add more directions, for example), and the only step that would be necessary is to regenerate the neighborhood graph. To be more precise, let us quickly break down the process of adapting a clustering algorithm to exploit it with flocking behavior. Step 1. We model the basic principles of flocking behavior with the three main rules: cohesion, alignment, and separation. As mentioned, these rules govern how agents  
Figure 6: Basic rules of Flocking. (**a**) Alignment; (**b**) separation; (**c**) cohesion. In green is the actual distance between the bold and flockmates, and in red is the steering direction imposed by the rule. Figure 7: The neighborhood graph of the qualitative directions with the similarity as percentage. (representing data points) move within a group to maintain cohesion while avoiding collisions with neighboring agents. Step 2. We need to modify the flocking algorithm to suit the requirements of clustering. Instead of merely mimicking the natural movement of agents, the algorithm should encourage the formation of clusters where similar agents are grouped together while dissimilar agents are kept apart. Step 3. We need to introduce the similarity and dissimilarity forces. Add two additional forces to the flocking algorithm: similarity and dissimilarity. The similarity force attracts agents that are similar to each other, encouraging them to cluster together. This force is based on a measure of similarity, such as distance or similarity scores between data points. Conversely, the dissimilarity force repels agents that are dissimilar, preventing them from clustering together. This force helps maintain separation between distinct clusters. Step 4. We need to define the similarity and dissimilarity metrics, which means how similarity and dissimilarity between agents will be measured. This involves defining distance metrics or similarity/dissimilarity scores based on the characteristics of the data being clustered. In the context of qualitative spatial information, we use evaluation functions that assess similarity based on qualitative attributes, such as directional relationships. Step 5. We need to create a neighborhood graph construction. We created a neighborhood graph that represents the relationships between agents based on their similarity and dissimilarity. Each agent is represented as a node in the graph, and the edges between nodes are weighted to indicate the strength of the relationship between agents. The weights of the edges can be calculated based on the similarity/dissimilarity metrics defined earlier. For example, higher similarity scores result in stronger connections between nodes, while dissimilar nodes have weaker connections. Step 6.