summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@yahoo.it>2015-05-12 00:36:26 +0100
committerKatolaZ <katolaz@yahoo.it>2015-05-12 00:36:26 +0100
commit29cc00c2d4dd86d6649d4ddd676601ecae943b6d (patch)
treed16e386221e75c903f61e5482cc577ff71f12af7
parentc42c3d71ac9244ebb42e76808f0a2e1be4a67f66 (diff)
more efficient costruction of the Laplacian
-rw-r--r--python/multired.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/python/multired.py b/python/multired.py
index be5ddbf..f885c12 100644
--- a/python/multired.py
+++ b/python/multired.py
@@ -125,9 +125,11 @@ class layer:
self.N, _x = matrix.shape
#K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N)))
#D = np.diag(np.diag(K))
- K = self.adj_matr.sum(0)
- D = csr_matrix((self.N, self.N))
- D.setdiag(eye(self.N) * K.transpose())
+ K = self.adj_matr.sum(0).reshape((1, self.N)).tolist()[0]
+ D = csr_matrix((K, (range(self.N), range(self.N)) ), shape=(self.N, self.N))
+ #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)
K = self.laplacian.diagonal().sum()
self.resc_laplacian = csr_matrix(self.laplacian / K)
@@ -140,9 +142,9 @@ class layer:
self.adj_matr = self.adj_matr + self.adj_matr.transpose()
#K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N)))
#D = np.diag(np.diag(K))
- K = self.adj_matr.sum(0)
- D = csr_matrix((self.N, self.N))
- D.setdiag(eye(self.N) * K.transpose())
+ K = self.adj_matr.sum(0).reshape((1, self.N)).tolist()[0]
+ D = csr_matrix((K, (range(self.N), range(self.N)) ), shape=(self.N, self.N))
+ #D.setdiag(eye(self.N) * K.transpose())
self.laplacian = csr_matrix(D - self.adj_matr)
K = self.laplacian.diagonal().sum()
self.resc_laplacian = csr_matrix(self.laplacian / K)
@@ -179,9 +181,11 @@ class layer:
self.adj_matr = copy.copy(other_layer.adj_matr)
#K = np.multiply(self.adj_matr.sum(0), np.ones((self.N,self.N)))
#D = np.diag(np.diag(K))
- K = self.adj_matr.sum(0)
- D = csr_matrix((self.N, self.N))
- D.setdiag(eye(self.N) * K. transpose())
+ K = self.adj_matr.sum(0).reshape((1, self.N)).tolist()[0]
+ D = csr_matrix((K, (range(self.N), range(self.N)) ), shape=(self.N, self.N))
+ #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)
K = self.laplacian.diagonal().sum()
self.resc_laplacian = csr_matrix(self.laplacian / K)