torch_geometric.nn.functional.gini

gini(w: Tensor) Tensor[source]

The Gini coefficient from the “Improving Molecular Graph Neural Network Explainability with Orthonormalization and Induced Sparsity” paper.

Computes a regularization penalty \(\in [0, 1]\) for each row of a matrix according to

\[\mathcal{L}_\textrm{Gini}^i = \sum_j^n \sum_{j'}^n \frac{|w_{ij} - w_{ij'}|}{2 (n^2 - n)\bar{w_i}}\]

and returns an average over all rows.

Parameters:

w (torch.Tensor) – A two-dimensional tensor.

Return type:

Tensor