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.lu_factor(self.D, 1.0) self.lu = np.asarray(self.lu, dtype=self.dtype)
def setcoef(self, A): """Set coefficient array.""" self.A = np.asarray(A, dtype=self.dtype) self.SAT = self.S.dot(A.T) # Factorise dictionary for efficient solves self.lu, self.piv = sl.lu_factor(A, self.rho) 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.lu_factor(self.D, self.mu + self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def setcoef(self, Z): """Set coefficient array.""" self.Z = np.asarray(Z, dtype=self.dtype) self.SZT = self.S.dot(Z.T) # Factorise dictionary for efficient solves self.lu, self.piv = sl.lu_factor(Z, self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def setcoef(self, Z): """Set coefficient array.""" self.Z = np.asarray(Z, dtype=self.dtype) self.SZT = self.S.dot(Z.T) # Factorise dictionary for efficient solves self.lu, self.piv = sl.lu_factor(Z, self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def rhochange(self): r""" This method is called when the penalty parameter :math:`\rho` is updated by the parent class solve method. It computes an LU factorisation of :math:`A_k^T A_k + \rho I`. """ self.lu = [] self.piv = [] for i in range(self.Nb): lu, piv = sl.lu_factor(self.A[i], self.rho) self.lu.append(lu) self.piv.append(piv)
def test_04(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 lu, piv = linalg.lu_factor(X, rho) Dslv = linalg.lu_solve_AATI(X, rho, S.dot(X.T) + rho*Z, lu, piv) assert(linalg.rrs(Dslv.dot(X).dot(X.T) + rho*Dslv, S.dot(X.T) + rho*Z) < 1e-11)
def test_02(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 lu, piv = linalg.lu_factor(D, rho) Xslv = linalg.lu_solve_ATAI(D, rho, D.T.dot(S) + rho*Z, lu, piv) assert(linalg.rrs(D.T.dot(D).dot(Xslv) + rho*Xslv, D.T.dot(S) + rho*Z) < 1e-14)
def test_04(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 lu, piv = linalg.lu_factor(X, rho) Dslv = linalg.lu_solve_AATI(X, rho, S.dot(X.T) + rho*Z, lu, piv) assert(linalg.rrs(Dslv.dot(X).dot(X.T) + rho*Dslv, S.dot(X.T) + rho*Z) < 1e-11)
def test_02(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 lu, piv = linalg.lu_factor(D, rho) Xslv = linalg.lu_solve_ATAI(D, rho, D.T.dot(S) + rho*Z, lu, piv) assert(linalg.rrs(D.T.dot(D).dot(Xslv) + rho*Xslv, D.T.dot(S) + rho*Z) < 1e-14)
def rhochange(self): r""" This method is called when the penalty parameter :math:`\rho` is updated by the parent class solve method. It computes an LU factorisation of :math:`A_k^T A_k + \rho I`. """ self.lu = [] self.piv = [] for i in range(self.Nb): lu, piv = spl.lu_factor(self.A[i], self.rho) self.lu.append(lu) self.piv.append(piv)
def setdict(self, D): """Set dictionary properly.""" if D.ndim == 2: # [patch_size, num_atoms] self.D = D.copy() elif D.ndim == 3: # [patch_h, patch_w, num_atoms] self.D = D.reshape((-1, D.shape[-1])) elif D.ndim == 4: # [patch_h, patch_w, channels, num_atoms] assert D.shape[-2] == 1 or D.shape[-2] == 3 self.D = D.transpose(2, 0, 1, 3) self.D = self.D.reshape((-1, self.D.shape[-1])) else: raise ValueError('Invalid dict D dimension of {}'.format(D.shape)) self.lu, self.piv = sl.lu_factor(self.D, self.gamma ** 2) self.lu = np.asarray(self.lu, dtype=self.dtype)
def rhochange(self): """Re-factorise matrix when rho changes""" self.lu, self.piv = sl.lu_factor(self.A, self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def rhochange(self): self.lu, self.piv = sl.lu_factor(self.coefs, self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def setcoef(self, coefs, signals): super().setcoef(coefs, signals) self.SZT = self.signals.dot(self.coefs.T) self.lu, self.piv = sl.lu_factor(self.coefs, self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)
def rhochange(self): """Re-factorise matrix when rho changes""" self.lu, self.piv = sl.lu_factor(self.Z, self.rho) self.lu = np.asarray(self.lu, dtype=self.dtype)