inFairness.distances.explore_distance module#

class inFairness.distances.explore_distance.EXPLOREDistance[source]#

Bases: MahalanobisDistances

Implements the Embedded Xenial Pairs Logistic Regression metric (EXPLORE) defined in Section 2.2 of Two Simple Ways to Learn Individual Fairness Metrics from Data.

EXPLORE defines the distance in the input space to be of the form:

\[d_x(x_1, x_2) := \langle \phi(x_1) - \phi(x_2), \Sigma (\phi(x_1) - \phi(x_2)) \rangle\]

where \(\phi(x)\) is an embedding map and \(\Sigma\) is a semi-positive definite matrix.

The metric expects the data to be in the form of triplets \(\{(x_{i_1}, x_{i_2}, y_i)\}_{i=1}^{n}\) where \(y_i \in \{0, 1\}\) indicates whether the human considers \(x_{i_1}\) and \(x_{i_2}\) comparable (\(y_i = 1\) indicates comparable) or not.

References

Mukherjee, Debarghya, Mikhail Yurochkin, Moulinath Banerjee, and Yuekai Sun. “Two simple ways to learn individual fairness metrics from data.” In International Conference on Machine Learning, pp. 7097-7107. PMLR, 2020.

compute_sigma(X, Y, iters, batchsize)[source]#
fit(X1, X2, Y, iters, batchsize, autoinfer_device=True)[source]#

Fit EXPLORE distance metric

Parameters:
  • X1 (torch.Tensor) – first set of input samples

  • X2 (torch.Tensor) – second set of input samples

  • Y (torch.Tensor) – \(y_i\) vector containing 1 if corresponding elements from X1 and X2 are comparable, and 0 if not

  • iters (int) – number of iterations of SGD to compute the \(\Sigma\) matrix

  • batchsize (int) – batch size of each iteration

  • 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 X1 is on. If set to False, keeps the metric on CPU.

training: bool#