inFairness.auditor.sensr_auditor module#

class inFairness.auditor.sensr_auditor.SenSRAuditor(loss_fn, distance_x, num_steps, lr, max_noise=0.1, min_noise=-0.1)[source]#

Bases: Auditor

SenSR Auditor implements the functionality to generate worst-case examples by solving the following optimization equation:

\[x_{t_b}^* \gets arg\max_{x \in X} l((x,y_{t_b}),h) - \lambda d_x^2(x_{t_b},x)\]

Proposed in Training individually fair ML models with sensitive subspace robustness

Parameters:
  • loss_fn (torch.nn.Module) – Loss function

  • distance_x (inFairness.distances.Distance) – Distance metric in the input space

  • num_steps (int) – Number of update steps should the auditor perform to find worst-case examples

  • lr (float) – Learning rate

audit(network, X_audit, Y_audit, audit_threshold=None, lambda_param=None, confidence=0.95, optimizer=None)[source]#

Audit a model for individual fairness

Parameters:
  • network (torch.nn.Module) – PyTorch network model

  • X_audit (torch.Tensor) – Auditing data samples. Shape: (B, *)

  • Y_audit (torch.Tensor) – Auditing data samples. Shape: (B)

  • loss_fn (torch.nn.Module) – Loss function

  • audit_threshold (float, optional) – Auditing threshold to consider a model individually fair or not If audit_threshold is specified, the audit procedure determines if the model is individually fair or not. If audit_threshold is not specified, the audit procedure simply returns the mean and lower bound of loss ratio, leaving the determination of models’ fairness to the user. Default=None

  • lambda_param (float) – Lambda weighting parameter as defined in the equation above

  • confidence (float, optional) – Confidence value. Default = 0.95

  • optimizer (torch.optim.Optimizer, optional) – PyTorch Optimizer object. Default: torch.optim.SGD

Returns:

audit_response – Audit response containing test statistics

Return type:

inFairness.auditor.datainterface.AuditorResponse

generate_worst_case_examples(network, x, y, lambda_param, optimizer=None)[source]#

Generate worst case example given the input data sample batch x

Parameters:
  • network (torch.nn.Module) – PyTorch network model

  • x (torch.Tensor) – Batch of input datapoints

  • y (torch.Tensor) – Batch of output datapoints

  • lambda_param (float) – Lambda weighting parameter as defined in the equation above

  • optimizer (torch.optim.Optimizer, optional) – PyTorch Optimizer object

Returns:

X_worst – Worst case examples for the provided input datapoints

Return type:

torch.Tensor