inFairness.distances.sensitive_subspace_dist module#

class inFairness.distances.sensitive_subspace_dist.SVDSensitiveSubspaceDistance[source]#

Bases: SensitiveSubspaceDistance

Sensitive Subspace metric that uses SVD to find the basis vectors of the sensitive subspace. The metric learns a subspace from a set of user-curated comparable data samples.

Proposed in Section B.2 of Training individually fair ML models with sensitive subspace robustness

References

Yurochkin, Mikhail, Amanda Bower, and Yuekai Sun. “Training individually fair ML models with sensitive subspace robustness.” arXiv preprint arXiv:1907.00020 (2019).

compute_basis_vectors(X_train, n_components)[source]#

Compute basis vectors using SVD

fit(X_train, n_components, autoinfer_device=True)[source]#

Fit SVD Sensitive Subspace distance metric parameters

Parameters:
  • X_train (torch.Tensor | List[torch.Tensor]) – Training data containing comparable data samples. If only one set of comparable data samples is provided, the input should be a torch.Tensor of shape \((N, D)\). For multiple sets of comparable data samples a list of shape \([ (N_1, D), \cdots, (N_x, D)]\) can be provided.

  • n_components (int) – Desired number of latent variable dimensions

  • autoinfer_device (bool) – Should the distance metric be automatically moved to an appropriate device (CPU / GPU) or not? If set to True, it moves the metric to the same device X_train is on. If set to False, keeps the metric on CPU.

training: bool#
class inFairness.distances.sensitive_subspace_dist.SensitiveSubspaceDistance[source]#

Bases: MahalanobisDistances

Implements Sensitive Subspace metric base class that accepts the basis vectors of a sensitive subspace, and computes a projection that ignores the sensitive subspace.

The projection from the sensitive subspace basis vectors (A) is computed as:

\[P^{'} = I - (A (A A^{T})^{-1} A^{T})\]
compute_projection_complement(basis_vectors)[source]#

Compute the projection complement of the space defined by the basis_vectors:

projection complement given basis vectors (A) is computed as:

\[P^{'} = I - (A (A A^{T})^{-1} A^{T})\]
Parameters:

basis_vectors (torch.Tensor) – Basis vectors of the sensitive subspace Dimension (d, k) where d is the data features dimension and k is the number of protected dimensions

Returns:

projection complement – Projection complement computed as described above. Shape (d, d) where d is the data feature dimension

Return type:

torch.Tensor

fit(basis_vectors)[source]#

Fit Sensitive Subspace Distance metric

Parameters:

basis_vectors (torch.Tensor) – Basis vectors of the sensitive subspace

training: bool#