Theory Behind Affinity Propagation
Affinity Propagation identifies representative observations, known as exemplars, which serve as cluster representatives. It does not require n_clusters; instead, similarities and preference values induce a number of exemplars. Preference does not estimate an optimal number of clusters.
1. Key Concepts in Affinity Propagation
1.1 Similarity
The Affinity Propagation algorithm starts by defining a similarity measure between pairs of data points. The similarity represents how well-suited data point is to be the exemplar for data point . The similarity can be calculated using various distance metrics, such as Euclidean distance or cosine similarity. In the case of Euclidean distance, the similarity is typically defined as:
Here, and are the feature vectors of data points and , respectively, and denotes the Euclidean distance between them. The negative sign ensures that points closer to each other have higher similarity.
1.2 Responsibility and Availability
Affinity Propagation relies on two types of messages exchanged between data points: responsibility and availability. These messages are iteratively updated to determine which data points should be exemplars.
-
Responsibility : The responsibility message reflects how well-suited point is to be the exemplar for point , considering other potential exemplars for . Mathematically, it is defined as:
This equation implies that the responsibility is the similarity minus the maximum of the sum of availability and similarity for any other candidate exemplar . This helps to focus on the best candidate exemplar.
-
Availability : The availability message reflects how appropriate it would be for point to choose point as its exemplar, considering how many other points want to select as their exemplar. It is computed as:
Here, is the self-responsibility, indicating the extent to which is suitable as its own exemplar. The sum captures how many other points consider to be their exemplar.
1.3 Message Passing
The key to Affinity Propagation lies in iteratively updating these responsibility and availability messages until convergence. Initially, all availability values are set to zero:
The responsibility and availability messages are then updated iteratively according to the following rules:
-
Update Responsibility:
-
Update Availability:
-
Self-Responsibility:
For each point to consider itself as an exemplar:
These updates continue until the changes in responsibility and availability are below a certain threshold, indicating convergence.
1.4 Selection of Exemplars
After the message-passing process converges, the exemplars are selected. For each data point , the exemplar is chosen based on the maximum of the sum of responsibility and availability:
This means that the exemplar for point is the point that maximizes the sum of responsibility and availability.
2. Preference Parameter
The preference parameter plays a crucial role in Affinity Propagation. It determines the likelihood of each point being chosen as an exemplar. Typically, is set to the median or minimum of the input similarities to influence the number of clusters. A higher preference value increases the number of clusters, while a lower value reduces it.
3. Convergence and Stability
Affinity Propagation can be sensitive to initialization and parameter choices, particularly the preference parameter. Convergence is not always guaranteed, and the algorithm may oscillate between configurations. To mitigate this, damping factors are often introduced in the update equations to stabilize the iterations.
3.1 Damping Factor
The damping factor is introduced to control the update of messages. Damping mixes each old message with the newly computed undamped message:
In scikit-learn, damping must be in ; larger values can suppress oscillation but slow adaptation. Convergence is still not guaranteed. convergence_iter requires stable exemplar decisions for that many iterations, while max_iter is a hard stop.
Each iteration updates dense messages, giving roughly quadratic time per iteration and quadratic memory. With affinity='euclidean', scikit-learn uses negative squared Euclidean distances as similarities. With affinity='precomputed', supply similarities where larger is better, including diagonal preferences—not a distance matrix.
4. Advantages and Disadvantages
4.1 Advantages
- Automatic Cluster Detection: Affinity Propagation does not require the number of clusters to be specified beforehand.
- Flexibility: It can find clusters of various shapes and sizes, making it useful for diverse data types.
- Exemplar-Based: The algorithm identifies actual data points as exemplars, providing a clear representative for each cluster.
4.2 Disadvantages
- Computationally Intensive: The algorithm can be computationally expensive, particularly for large datasets.
- Sensitivity to Parameters: The algorithm's performance can be highly sensitive to the choice of the preference parameter.
- Convergence Issues: Without careful tuning, the algorithm may fail to converge, especially in the presence of noise.
Conclusion
Affinity Propagation offers an exemplar-based partition without a requested cluster count. Its output is preference-sensitive, may fail to converge, and has quadratic storage, so similarity semantics, damping, convergence, and stability must all be reported.