Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fair_mango/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = (0, 2, 1)
__version__ = (0, 2, 2)
35 changes: 26 additions & 9 deletions fair_mango/metrics/base.py
Comment thread
MarcBresson marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

from fair_mango.dataset.dataset import Dataset
from fair_mango.typing import (
BaseMetricResult,
CombinedPerformanceResult,
DisparityResultDict,
FairnessSummaryDifferenceResult,
FairnessSummaryDifferenceFairResult,
FairnessSummaryRatioResult,
FairnessSummaryDifferenceResult,
FairnessSummaryRatioFairResult,
BaseMetricResult,
CombinedPerformanceResult,
FairnessSummaryRatioResult,
RankResult,
SensitiveGroupTupleT,
SensitiveGroupOptionalT,
SensitiveGroupTupleT,
)

LabelT = TypeVar("LabelT", bound=str)
Expand Down Expand Up @@ -270,11 +270,26 @@ def _to_float(result) -> float:
return float(data)

a, b = _to_float(rec_i), _to_float(rec_j)

if method == "difference":
# # Ensure a is the larger value for consistent disparity calculation
# # that way, the difference will always be >= 0
Comment thread
AmineMahiddine marked this conversation as resolved.
Outdated
if b > a:
a, b = b, a
grp_i, grp_j = grp_j, grp_i

disp = a - b
else:
if b == 0:
disp = 1.0 if a == 0 else float("inf")
# Ensure b is the larger value for consistent disparity calculation
# that way, the ratio will always be <= 1
Comment thread
AmineMahiddine marked this conversation as resolved.
if a > b:
a, b = b, a
grp_i, grp_j = grp_j, grp_i

if a == b:
disp = 1.0
elif b == 0:
disp = float("inf")
else:
disp = a / b

Expand Down Expand Up @@ -394,14 +409,16 @@ def summary(
unprivileged_sensitive_group: SensitiveGroupOptionalT = None

for disparity_result in self.results:
abs_disparity = abs(disparity_result["disparity"])
disparity = disparity_result["disparity"]
abs_disparity = abs(disparity)

if abs_disparity > max_disparity:
max_disparity = abs_disparity
if disparity_result["disparity"] > 0:
if disparity > 0:
privileged_sensitive_group = disparity_result["group_1"]
unprivileged_sensitive_group = disparity_result["group_2"]
else:
# in case disparity is negative, we swap the two groups to make it positive again
privileged_sensitive_group = disparity_result["group_2"]
unprivileged_sensitive_group = disparity_result["group_1"]

Expand Down