microsoft / graspologic
Showing 1 of 2 files from the diff.
Other files ignored by Codecov

@@ -57,6 +57,19 @@
 57 57  Gives users the option to solve QAP rather than the Graph Matching Problem 58 58  (GMP). This is accomplished through trivial negation of the objective function. 59 59 60 +  padding : string (default = 'adopted') 61 +  Allows user to specify padding scheme if A and B are not of equal size. 62 + 63 +  "adopted" : say that A and B have :math:n_1 and :mathn_2 nodes, respectively. 64 +  Define :math:\tilde{A} = 2A - 1_{n1}1_{n1}^T and 65 +  :math:\tilde{B} = 2B - 1_{n2}1_{n2}^T. If :math:n_1 < n_2, then we substitute 66 +  :math:\tilde{A} \oplus 0_{(n2-n1)x(n2-n1)} and :math:\tilde{B} in place of A 67 +  and B. 68 + 69 +  "naive" : say that A and B have :math:n_1 and :mathn_2 nodes, respectively. 70 +  If :math:n_1 < n_2, then we substitute :math:A \oplus 0_{(n2-n1)x(n2-n1)} 71 +  and :math:B in place of A and B. 72 + 60 73  Attributes 61 74  ---------- 62 75
@@ -91,6 +104,7 @@
 91 104  shuffle_input=True, 92 105  eps=0.1, 93 106  gmp=True, 107 +  padding="adopted", 94 108  ): 95 109 96 110  if type(n_init) is int and n_init > 0:
@@ -126,6 +140,11 @@
 126 140  else: 127 141  msg = '"gmp" must be a boolean' 128 142  raise TypeError(msg) 143 +  if padding in {"adopted", "naive"}: 144 +  self.padding = padding 145 +  else: 146 +  msg = 'Invalid "padding" parameter string' 147 +  raise ValueError(msg) 129 148 130 149  def fit(self, A, B, seeds_A=[], seeds_B=[]): 131 150  """
@@ -156,10 +175,7 @@
 156 175  seeds_A = column_or_1d(seeds_A) 157 176  seeds_B = column_or_1d(seeds_B) 158 177 159 -  if A.shape[0] != B.shape[0]: 160 -  msg = "Adjacency matrices must be of equal size" 161 -  raise ValueError(msg) 162 -  elif A.shape[0] != A.shape[1] or B.shape[0] != B.shape[1]: 178 +  if A.shape[0] != A.shape[1] or B.shape[0] != B.shape[1]: 163 179  msg = "Adjacency matrix entries must be square" 164 180  raise ValueError(msg) 165 181  elif seeds_A.shape[0] != seeds_B.shape[0]:
@@ -178,6 +194,10 @@
 178 194  msg = "Seed array entries must be less than or equal to n-1" 179 195  raise ValueError(msg) 180 196 197 +  # pads A and B according to section 2.5 of [2] 198 +  if A.shape[0] != B.shape[0]: 199 +  A, B = _adj_pad(A, B, self.padding) 200 + 181 201  n = A.shape[0] # number of vertices in graphs 182 202  n_seeds = seeds_A.shape[0] # number of seeds 183 203  n_unseed = n - n_seeds
@@ -326,6 +346,27 @@
 326 346  return self.perm_inds_ 327 347 328 348 349 + def _adj_pad(A, B, method): 350 +  def pad(X, n): 351 +  X_pad = np.zeros((n[1], n[1])) 352 +  X_pad[: n[0], : n[0]] = X 353 +  return X_pad 354 + 355 +  A_n = A.shape[0] 356 +  B_n = B.shape[0] 357 +  n = np.sort([A_n, B_n]) 358 +  if method == "adopted": 359 +  A = 2 * A - np.ones((A_n, A_n)) 360 +  B = 2 * B - np.ones((B_n, B_n)) 361 + 362 +  if A.shape[0] == n[0]: 363 +  A = pad(A, n) 364 +  else: 365 +  B = pad(B, n) 366 + 367 +  return A, B 368 + 369 + 329 370 def _unshuffle(array, n): 330 371  unshuffle = np.array(range(n)) 331 372  unshuffle[array] = np.array(range(n))
Files Coverage
graspy 87.93%
Project Totals (42 files) 87.93%
2366.1
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux

2366.2
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux