Calculate the average distance between a point (idx) and a cluster (cluster_idx). Args: similarity (np.ndarray): The similarity matrix. idx (int): The index of the point. cluster_idx (list): The indices of the cluster. Returns: float: The average distan
(
similarity: torch.Tensor, idx: int, cluster_idx: list[int]
)
| 227 | |
| 228 | |
| 229 | def average_distance( |
| 230 | similarity: torch.Tensor, idx: int, cluster_idx: list[int] |
| 231 | ) -> float: |
| 232 | """ |
| 233 | Calculate the average distance between a point (idx) and a cluster (cluster_idx). |
| 234 | |
| 235 | Args: |
| 236 | similarity (np.ndarray): The similarity matrix. |
| 237 | idx (int): The index of the point. |
| 238 | cluster_idx (list): The indices of the cluster. |
| 239 | |
| 240 | Returns: |
| 241 | float: The average distance. |
| 242 | """ |
| 243 | if idx in cluster_idx: |
| 244 | return 0 |
| 245 | total_similarity = 0 |
| 246 | for idx_in_cluster in cluster_idx: |
| 247 | total_similarity += similarity[idx, idx_in_cluster] |
| 248 | return total_similarity / len(cluster_idx) |
| 249 | |
| 250 | |
| 251 | def get_cluster(similarity: np.ndarray, sim_bound: float = 0.65): |