torch_geometric.metrics.LinkPredPersonalization
- class LinkPredPersonalization(k: int, max_src_nodes: Optional[int] = 4096, batch_size: int = 65536)[source]
Bases:
_LinkPredMetric
A link prediction metric to compute the Personalization @ \(k\), i.e. the dissimilarity of recommendations across different users.
Higher personalization suggests that the model tailors recommendations to individual user preferences rather than providing generic results.
Dissimilarity is defined by the average inverse cosine similarity between users’ lists of recommendations.
- Parameters:
k (int) – The number of top-\(k\) predictions to evaluate against.
max_src_nodes (int, optional) – The maximum source nodes to consider to compute pair-wise dissimilarity. If specified, Personalization @ \(k\) is approximated to avoid computation blowup due to quadratic complexity. (default:
2**12
)batch_size (int, optional) – The batch size to determine how many pairs of user recommendations should be processed at once. (default:
2**16
)
- update(pred_index_mat: Tensor, edge_label_index: Union[Tensor, Tuple[Tensor, Tensor]], edge_label_weight: Optional[Tensor] = None) None [source]
Updates the state variables based on the current mini-batch prediction.
update()
can be repeated multiple times to accumulate the results of successive predictions, e.g., inside a mini-batch training or evaluation loop.- Parameters:
pred_index_mat (torch.Tensor) – The top-\(k\) predictions of every example in the mini-batch with shape
[batch_size, k]
.edge_label_index (torch.Tensor) – The ground-truth indices for every example in the mini-batch, given in COO format of shape
[2, num_ground_truth_indices]
.edge_label_weight (torch.Tensor, optional) – The weight of the ground-truth indices for every example in the mini-batch of shape
[num_ground_truth_indices]
. If given, needs to be a vector of positive values. Required for weighted metrics, ignored otherwise. (default:None
)
- Return type: