MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / average_distance

Function average_distance

utils/src/model_utils.py:229–248  ·  view source on GitHub ↗

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]
)

Source from the content-addressed store, hash-verified

227
228
229def 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
251def get_cluster(similarity: np.ndarray, sim_bound: float = 0.65):

Callers 1

get_clusterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected