Compute mean(abs(x-y); x in [t0_lo, t0_hi], y in [t1_lo, t1_hi]).
(t0_lo, t0_hi, t1_lo, t1_hi)
| 308 | |
| 309 | |
| 310 | def interval_distortion(t0_lo, t0_hi, t1_lo, t1_hi): |
| 311 | """Compute mean(abs(x-y); x in [t0_lo, t0_hi], y in [t1_lo, t1_hi]).""" |
| 312 | # Distortion when the intervals do not overlap. |
| 313 | d_disjoint = torch.abs((t1_lo + t1_hi) / 2 - (t0_lo + t0_hi) / 2) |
| 314 | |
| 315 | # Distortion when the intervals overlap. |
| 316 | d_overlap = (2 * |
| 317 | (torch.minimum(t0_hi, t1_hi) ** 3 - torch.maximum(t0_lo, t1_lo) ** 3) + |
| 318 | 3 * (t1_hi * t0_hi * torch.abs(t1_hi - t0_hi) + |
| 319 | t1_lo * t0_lo * torch.abs(t1_lo - t0_lo) + t1_hi * t0_lo * |
| 320 | (t0_lo - t1_hi) + t1_lo * t0_hi * |
| 321 | (t1_lo - t0_hi))) / (6 * (t0_hi - t0_lo) * (t1_hi - t1_lo)) |
| 322 | |
| 323 | # Are the two intervals not overlapping? |
| 324 | are_disjoint = (t0_lo > t1_hi) | (t1_lo > t0_hi) |
| 325 | |
| 326 | return torch.where(are_disjoint, d_disjoint, d_overlap) |
| 327 | |
| 328 | |
| 329 | def weighted_percentile(t, w, ps): |
nothing calls this directly
no outgoing calls
no test coverage detected