more efficient costruction of the Laplacian

master
KatolaZ 10 years ago
parent c42c3d71ac
commit 29cc00c2d4
  1. 22
      python/multired.py

@ -125,9 +125,11 @@ class layer:
self.N, _x = matrix.shape self.N, _x = matrix.shape
#K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N))) #K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N)))
#D = np.diag(np.diag(K)) #D = np.diag(np.diag(K))
K = self.adj_matr.sum(0) K = self.adj_matr.sum(0).reshape((1, self.N)).tolist()[0]
D = csr_matrix((self.N, self.N)) D = csr_matrix((K, (range(self.N), range(self.N)) ), shape=(self.N, self.N))
D.setdiag(eye(self.N) * K.transpose()) #K = self.adj_matr.sum(0)
#D = csr_matrix((self.N, self.N))
#D.setdiag(eye(self.N) * K.transpose())
self.laplacian = csr_matrix(D - self.adj_matr) self.laplacian = csr_matrix(D - self.adj_matr)
K = self.laplacian.diagonal().sum() K = self.laplacian.diagonal().sum()
self.resc_laplacian = csr_matrix(self.laplacian / K) self.resc_laplacian = csr_matrix(self.laplacian / K)
@ -140,9 +142,9 @@ class layer:
self.adj_matr = self.adj_matr + self.adj_matr.transpose() self.adj_matr = self.adj_matr + self.adj_matr.transpose()
#K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N))) #K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N)))
#D = np.diag(np.diag(K)) #D = np.diag(np.diag(K))
K = self.adj_matr.sum(0) K = self.adj_matr.sum(0).reshape((1, self.N)).tolist()[0]
D = csr_matrix((self.N, self.N)) D = csr_matrix((K, (range(self.N), range(self.N)) ), shape=(self.N, self.N))
D.setdiag(eye(self.N) * K.transpose()) #D.setdiag(eye(self.N) * K.transpose())
self.laplacian = csr_matrix(D - self.adj_matr) self.laplacian = csr_matrix(D - self.adj_matr)
K = self.laplacian.diagonal().sum() K = self.laplacian.diagonal().sum()
self.resc_laplacian = csr_matrix(self.laplacian / K) self.resc_laplacian = csr_matrix(self.laplacian / K)
@ -179,9 +181,11 @@ class layer:
self.adj_matr = copy.copy(other_layer.adj_matr) self.adj_matr = copy.copy(other_layer.adj_matr)
#K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N))) #K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N)))
#D = np.diag(np.diag(K)) #D = np.diag(np.diag(K))
K = self.adj_matr.sum(0) K = self.adj_matr.sum(0).reshape((1, self.N)).tolist()[0]
D = csr_matrix((self.N, self.N)) D = csr_matrix((K, (range(self.N), range(self.N)) ), shape=(self.N, self.N))
D.setdiag(eye(self.N) * K. transpose()) #K = self.adj_matr.sum(0)
#D = csr_matrix((self.N, self.N))
#D.setdiag(eye(self.N) * K. transpose())
self.laplacian = csr_matrix(D - self.adj_matr) self.laplacian = csr_matrix(D - self.adj_matr)
K = self.laplacian.diagonal().sum() K = self.laplacian.diagonal().sum()
self.resc_laplacian = csr_matrix(self.laplacian / K) self.resc_laplacian = csr_matrix(self.laplacian / K)

Loading…
Cancel
Save