Bases: BaseNumericDistance
Anderson-Darling distance metric (Custom Implementation).
Source code in src/xwhy/distance/distances.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 | class AndersonDarlingDistance(BaseNumericDistance):
"""Anderson-Darling distance metric (Custom Implementation)."""
def _compute_1d(self, a: np.ndarray, b: np.ndarray) -> float:
n, xy_sorted, x2_sorted, y2_sorted = self._prepare_ecdf_data(a, b)
res = 0.0
e_cdf = 0.0
f_cdf = 0.0
g_cdf = 0.0
power = 1
for i in range(n - 2):
e_cdf += x2_sorted[i]
f_cdf += y2_sorted[i]
g_cdf += 1 / n
sd = (n * g_cdf * (1 - g_cdf)) ** 0.5
height = abs(f_cdf - e_cdf)
if xy_sorted[i + 1] != xy_sorted[i] and sd > 0:
res += (height / sd) ** power
return float(res)
|