Bases: BaseNumericDistance
DTS distance metric (Custom Implementation: Combination of AD and CVM).
Source code in src/xwhy/distance/distances.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 | 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)
|