refactored matrix.py
@@ -123,7 +123,6 @@ def centering(size):
centering_matrix = np.identity(size) - np.ones(size) / size
return centering_matrix
-
def row_col_indicator_RDM(n_cond):
""" generates a row and column indicator matrix for an RDM vector
@@ -137,11 +136,7 @@ def row_col_indicator_RDM(n_cond):
n_dist = int(n_cond * (n_cond - 1) / 2)
rowI = np.zeros((n_dist, n_cond))
colI = np.zeros((n_dist, n_cond))
- j=0
- for i in range(n_cond):
- rowI[j:j+n_cond-i-1,i]=1
- np.fill_diagonal(colI[j:j+n_cond-i-1,i+1:],1)
- j=j+(n_cond-i-1)
+ _row_col_indicator(rowI, colI, n_cond)
return (rowI,colI)
def row_col_indicator_G(n_cond):
@@ -158,11 +153,21 @@ def row_col_indicator_G(n_cond):
n_elem = int(n_cond * (n_cond - 1) / 2)+n_cond # Number of elements in G
rowI = np.zeros((n_elem, n_cond))
colI = np.zeros((n_elem, n_cond))
+ _row_col_indicator(rowI, colI, n_cond)
+ np.fill_diagonal(rowI[-n_cond:, :], 1)
+ np.fill_diagonal(colI[-n_cond:, :], 1)
+ return (rowI,colI)
+
+def _row_col_indicator(rowI,colI,n_cond):
+ """ Helper function that writes the correct pattern for the row / column indicator matrix
+
+ Args:
+ row_indicator: rowI (numpy.ndarray):
+ col_indicator: rowI (numpy.ndarray):
+ n_cond (int): Number of conditions underlying the second moment
+ """
j = 0
for i in range(n_cond):
rowI[j:j+n_cond-i-1, i] = 1
np.fill_diagonal(colI[j:j+n_cond-i-1, i+1:] ,1)
j = j + (n_cond - i - 1)
\ No newline at end of file
- np.fill_diagonal(rowI[j:, :], 1)
- np.fill_diagonal(colI[j:, :], 1)
- return (rowI,colI)
\ No newline at end of file
