def cov(lar): """ Covariance matrix adjusted for missing (NaN) values. Note: Only works on 2d larrys. The mean of each row is assumed to be zero. So rows are not demeaned and therefore the covariance is normalized by the number of columns, not by the number of columns minus 1. Parameters ---------- lar : larry The larry you want to find the covariance of. Returns ------- out : larry For 2d input of shape (N, T), for example, returns a NxN covariance matrix. Raises ------ ValueError If input is not 2d """ if lar.ndim != 2: raise ValueError, 'This function only works on 2d larrys' y = lar.copy() y.label[1] = list(y.label[0]) y.x = covMissing(y.x) return y
def test_covMissing_2(): "farray.covMissing_2" a = np.ones((2, 4)) a[0, 1] = np.nan b = a.copy() ignore = covMissing(a) aae(a, b)
def test_covMissing_2(): "farray.covMissing_2" a = np.ones((2,4)) a[0,1] = np.nan b = a.copy() ignore = covMissing(a) aae(a, b)
def test_covMissing_1(): "farray.covMissing_1" a = np.ones((2, 10)) actual = covMissing(a) desired = np.ones((2, 2)) aae(actual, desired)
def test_covMissing_1(): "farray.covMissing_1" a = np.ones((2,10)) actual = covMissing(a) desired = np.ones((2,2)) aae(actual, desired)