def setdict(self, D): """Set dictionary array.""" self.D = np.asarray(D, dtype=self.dtype) # Factorise dictionary for efficient solves self.lu, self.piv = sl.cho_factor(self.D, 1.0) self.lu = np.asarray(self.lu, dtype=self.dtype)
def setdict(self, D): """Set dictionary array.""" self.D = np.asarray(D) self.DTS = self.D.T.dot(self.S) # Factorise dictionary for efficient solves self.lu, self.piv = sl.cho_factor(self.D, self.mu + self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def test_05(self): rho = 1e-1 N = 64 M = 128 K = 32 D = np.random.randn(N, M) X = np.random.randn(M, K) S = D.dot(X) Z = (D.T.dot(D).dot(X) + rho*X - D.T.dot(S)) / rho c, lwr = linalg.cho_factor(D, rho) Xslv = linalg.cho_solve_ATAI(D, rho, D.T.dot(S) + rho*Z, c, lwr) assert(linalg.rrs(D.T.dot(D).dot(Xslv) + rho*Xslv, D.T.dot(S) + rho*Z) < 1e-11)
def test_08(self): rho = 1e-1 N = 128 M = 64 K = 32 D = np.random.randn(N, M) X = np.random.randn(M, K) S = D.dot(X) Z = (D.dot(X).dot(X.T) + rho*D - S.dot(X.T)) / rho c, lwr = linalg.cho_factor(X, rho) Dslv = linalg.cho_solve_AATI(X, rho, S.dot(X.T) + rho*Z, c, lwr) assert(linalg.rrs(Dslv.dot(X).dot(X.T) + rho*Dslv, S.dot(X.T) + rho*Z) < 1e-11)
def test_06(self): rho = 1e-1 N = 128 M = 64 K = 32 D = np.random.randn(N, M) X = np.random.randn(M, K) S = D.dot(X) Z = (D.T.dot(D).dot(X) + rho*X - D.T.dot(S)) / rho c, lwr = linalg.cho_factor(D, rho) Xslv = linalg.cho_solve_ATAI(D, rho, D.T.dot(S) + rho*Z, c, lwr) assert(linalg.rrs(D.T.dot(D).dot(Xslv) + rho*Xslv, D.T.dot(S) + rho*Z) < 1e-14)
def rhochange(self): """Re-factorise matrix when rho changes.""" self.lu, self.piv = sl.cho_factor(self.D, self.mu + self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)