Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
 def rhochange(self):
     self.lu, self.piv = sl.lu_factor(self.coefs, self.rho)
     self.lu = np.asarray(self.lu, dtype=self.dtype)
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
    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)