inFairness.utils.postprocessing module#
- inFairness.utils.postprocessing.build_graph_from_dists(dists: Tensor, scale: float | None = None, threshold: float | None = None, normalize: bool = False)[source]#
Build the adjacency matrix W given distances
- Parameters:
dists (torch.Tensor) – Distance matrix between data points. Shape: (N, N)
scale (float) – Parameter used to scale the computed distances
threshold (float) – Parameter used to determine if two data points are connected or not. Distances below threshold value are connected, and beyond threshold value are disconnected.
normalize (bool) – Whether to normalize the adjacency matrix or not
- Returns:
W (torch.Tensor) – Adjancency matrix. It contains data points which are connected to atleast one other datapoint. Isolated datapoints, or ones which are not connected to any other datapoints, are not included in the adjancency matrix.
idxs_in (torch.Tensor) – Indices of data points which are included in the adjacency matrix
- inFairness.utils.postprocessing.get_laplacian(W: Tensor, normalize: bool = False)[source]#
Get the Laplacian of the matrix W
- Parameters:
W (torch.Tensor) – Adjacency matrix of shape (N, N)
normalize (bool) – Whether to normalize the computed laplacian or not
- Returns:
Laplacian – Laplacian of the adjacency matrix
- Return type:
- inFairness.utils.postprocessing.laplacian_solve(L: Tensor, y_hat: Tensor, lambda_param: float | None = None)[source]#
Solves a system of linear equations to get the post-processed output. The system of linear equation it solves is: \(\hat{{f}} = {(I + \lambda * L)}^{-1} \hat{y}\)
- Parameters:
L (torch.Tensor) – Laplacian matrix
y_hat (torch.Tensor) – Model predicted output class probabilities
lambda_param (float) – Weight for the laplacian regularizer
- Returns:
y – Post-processed solution according to the equation above
- Return type: