def corr(self): '''The correlation matrix''' cov = self.cov() N = cov.shape[0] corr = ndarray((N,N)) for r in range(N): for c in range(r): corr[r,c] = corr[c,r] = cov[r,c]/sqrt(cov[r,r]*cov[c,c]) corr[r,r] = 1. return corr
def corr(self): '''The correlation matrix''' cov = self.cov() N = cov.shape[0] corr = ndarray((N, N)) for r in range(N): for c in range(r): corr[r, c] = corr[c, r] = cov[r, c] / sqrt(cov[r, r] * cov[c, c]) corr[r, r] = 1. return corr
def vector_to_symmetric(v): '''Convert an iterable into a symmetric matrix.''' np = len(v) N = (int(sqrt(1 + 8 * np)) - 1) // 2 if N * (N + 1) // 2 != np: raise ValueError('Cannot convert vector to symmetric matrix') sym = ndarray((N, N)) iterable = iter(v) for r in range(N): for c in range(r + 1): sym[r, c] = sym[c, r] = iterable.next() return sym
def vector_to_symmetric(v): '''Convert an iterable into a symmetric matrix.''' np = len(v) N = (int(sqrt(1 + 8*np)) - 1)//2 if N*(N+1)//2 != np: raise ValueError('Cannot convert vector to symmetric matrix') sym = ndarray((N,N)) iterable = iter(v) for r in range(N): for c in range(r+1): sym[r,c] = sym[c,r] = iterable.next() return sym
def testVar(self): '''Calculate the biased variance of a series''' ts = dynts.timeseries(date=datepopulate(10), data=range(1, 11), backend=self.backend) self.assertAlmostEqual(ts.var()[0], 8.25, places) self.assertAlmostEqual(ts.var(ddof=1)[0], 9.166667, places)
def testVar(self): '''Calculate the biased variance of a series''' ts = timeseries(date = datepopulate(10), data = range(1,11), backend = self.backend) self.assertAlmostEqual(ts.var()[0],8.25) self.assertAlmostEqual(ts.var(ddof=1)[0],9.166667)