From 395bc7cb5ce0ffc49a3a316d847830b1dc61085f Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 11 May 2015 23:25:18 +0100 Subject: Removed the last full matrix dangling around --- python/multired.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/python/multired.py b/python/multired.py index 3952eec..0023d38 100644 --- a/python/multired.py +++ b/python/multired.py @@ -35,7 +35,7 @@ # -------------------------------------------- # # -- 2015/04/23 -- release 0.1 -# +# -- 2015/05/11 -- release 0.1.1 -- removed the last full matrices # @@ -123,8 +123,10 @@ class layer: elif matrix != None: self.adj_matr = copy.copy(matrix) 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 = 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 = K * eye(self.N) self.laplacian = csr_matrix(D - self.adj_matr) K = self.laplacian.diagonal().sum() self.resc_laplacian = csr_matrix(self.laplacian / K) @@ -135,8 +137,10 @@ class layer: self.N = N self.adj_matr = csr_matrix((self._ww, (self._ii, self._jj)), shape=(self.N, self.N)) 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 = 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 = K * eye(self.N) self.laplacian = csr_matrix(D - self.adj_matr) K = self.laplacian.diagonal().sum() self.resc_laplacian = csr_matrix(self.laplacian / K) @@ -171,8 +175,10 @@ class layer: self.adj_matr = self.adj_matr + other_layer.adj_matr else: 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 = 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 = K * eye(self.N) self.laplacian = csr_matrix(D - self.adj_matr) K = self.laplacian.diagonal().sum() self.resc_laplacian = csr_matrix(self.laplacian / K) -- cgit v1.2.3 From c42c3d71ac9244ebb42e76808f0a2e1be4a67f66 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Tue, 12 May 2015 00:04:24 +0100 Subject: Removed the last dangling full matrix --- python/multired.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/multired.py b/python/multired.py index 0023d38..be5ddbf 100644 --- a/python/multired.py +++ b/python/multired.py @@ -126,7 +126,8 @@ class layer: #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 = K * eye(self.N) + 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,12 +141,13 @@ class layer: #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 = K * eye(self.N) + 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) self._matrix_called = True - + def dump_info(self): N, M = self.adj_matr.shape K = self.adj_matr.nnz @@ -178,13 +180,15 @@ class layer: #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 = K * eye(self.N) + 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) self._matrix_called = True - + def dump_laplacian(self): + print self.laplacian class multiplex_red: -- cgit v1.2.3 From 29cc00c2d4dd86d6649d4ddd676601ecae943b6d Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Tue, 12 May 2015 00:36:26 +0100 Subject: more efficient costruction of the Laplacian --- python/multired.py | 22 +++++++++++++--------- 1 file 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) -- cgit v1.2.3 From 815c998aa757969edd25b34a8eefa8f5be4d4097 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Tue, 12 May 2015 12:01:50 +0100 Subject: A better solution to remove the last few full matrices around (all of them were in the "layer" class...) --- python/multired.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/python/multired.py b/python/multired.py index f885c12..06fbc79 100644 --- a/python/multired.py +++ b/python/multired.py @@ -123,13 +123,8 @@ class layer: elif matrix != None: self.adj_matr = copy.copy(matrix) 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).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,11 +135,8 @@ class layer: self.N = N self.adj_matr = csr_matrix((self._ww, (self._ii, self._jj)), shape=(self.N, self.N)) 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).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,13 +171,8 @@ class layer: self.adj_matr = self.adj_matr + other_layer.adj_matr else: 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).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) -- cgit v1.2.3