Bases: BaseNumericDistance
DTS distance metric (Custom Implementation: Combination of AD and CVM).
Source code in src/xwhy/distance/distances.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231 | class DTSDistance(BaseNumericDistance):
"""DTS distance metric (Custom Implementation: Combination of AD and CVM)."""
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)
width = xy_sorted[i + 1] - xy_sorted[i]
res += ((height / sd) ** power) * width
return float(res)
|