torch_geometric.metrics.LinkPredNDCG

class LinkPredNDCG(k: int)[source]

Bases: LinkPredMetric

一个用于计算NDCG @ \(k\)(归一化折扣累积增益)的链接预测指标。

Parameters:

k (int) – The number of top-\(k\) predictions to evaluate against.

update(pred_index_mat: Tensor, edge_label_index: Union[Tensor, Tuple[Tensor, Tensor]]) None

根据当前小批量预测更新状态变量。

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

Return type:

None

compute() Tensor

计算最终的度量值。

Return type:

Tensor

reset() None

将度量状态变量重置为其默认值。

Return type:

None