# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1421418464 18000 # Node ID 077261db7a584d9d217918aad9c01505ea6b851e # Parent c81f6d26389752e3865e7062eba24bc74bd8d420 Whitespace cleanup diff --git a/pymedcouple b/pymedcouple --- a/pymedcouple +++ b/pymedcouple @@ -11,15 +11,15 @@ Also known as quickselect. The elements of W are ignored for the purposes of this partial sort. """ - + beg = 0 end = len(L) - + while True: pivot = random.randint(beg,end-1) pivotval = L[pivot][0] L[pivot], L[end-1] = L[end-1], L[pivot] - + idx = beg for i in xrange(beg, end): if L[i][0] < pivotval: @@ -39,7 +39,7 @@ """This computes the weighted median of array A with corresponding weights W. """ - + AW = zip(A,W) n = len(AW) @@ -50,7 +50,7 @@ while True: mid = (beg + end)//2 - + partsort(AW, mid) trial = AW[mid][0] @@ -81,7 +81,7 @@ ------- mc : float The medcouple statistic - + .. [1] G. Brys, M. Hubert, and A. Struyf "A Robust Measure of Skewness." Journal of Computational and Graphical Statistics, Vol. 13, No. 4 (Dec., 2004), pp. 996- 1017 @@ -92,7 +92,7 @@ """ # FIXME: Figure out what to do about NaNs. - + n = len(X) n2 = (n-1)//2 @@ -105,7 +105,7 @@ Zmed = Z[n2] else: Zmed = (Z[n2] + Z[n2+1])/2 - + #Check if the median is at the edges up to relative epsilon if abs(Z[0] - Zmed) < eps1*(eps1 + abs(Zmed)): return -1.0 @@ -119,7 +119,7 @@ Zden = 2*max(Z[0], -Z[-1]) Z = [z/Zden for z in Z] Zmed /= Zden - + Zeps = eps1*(eps1 + abs(Zmed)) # These overlap on the entries that are tied with the median @@ -157,7 +157,7 @@ # kth pair algorithm (Johnson & Mizoguchi) while Rtot - Ltot > n_plus: - + # First, compute the median inside the given bounds # (Be stingy, reuse same generator) [I1, I2] = tee(i for i in xrange(0, n_plus) if L[i] <= R[i]) @@ -165,7 +165,7 @@ A = [h_kern(i, (L[i] + R[i])//2) for i in I1] W = [R[i] - L[i] + 1 for i in I2] Am = wmedian(A,W) - + Am_eps = eps1*(eps1 + abs(Am)) # Compute new left and right boundaries, based on the weighted @@ -178,7 +178,7 @@ while j < n_minus - 1 and h_kern(i, j) - Am > Am_eps: j += 1 P.append(j - 1) - + P.reverse() j = n_minus - 1 @@ -215,7 +215,7 @@ Am = A[medc_idx - Ltot] return Am - + def signum(x): if x > 0: