You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.py 468 B

123456789101112131415
  1. import numpy as np
  2. def vec2sym_mat(v):
  3. """
  4. Convert a vector encoding a symmetric matrix into a matrix
  5. See Golub and Van Loan, Matrix Computations, 3rd edition, p21
  6. """
  7. n = int((-1+np.sqrt(1+8*len(v)))/2) # second order resolution
  8. M = np.zeros((n, n))
  9. for i in range(n):
  10. for j in range(i, n):
  11. # Golub van Loan, Matrix Computations, Eq. 1.2.2, p21
  12. M[i, j] = M[j, i] = v[i*n - (i+1)*(i)//2 + j]
  13. return M

A Python package for graph kernels, graph edit distances and graph pre-image problem.