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.

check_gm.py 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Test gram matrices.
  5. Created on Wed Sep 19 15:32:29 2018
  6. @author: ljia
  7. """
  8. import numpy as np
  9. import matplotlib.pyplot as plt
  10. from numpy.linalg import eig
  11. # read gram matrices from file.
  12. results_dir = 'results/marginalizedkernel/myria'
  13. ds_name = 'MUTAG'
  14. gmfile = np.load(results_dir + '/' + ds_name + '.gm.npz')
  15. #print('gm time: ', gmfile['gmtime'])
  16. # a list to store gram matrices for all param_grid_precomputed
  17. gram_matrices = gmfile['gms']
  18. # param_list_pre_revised = gmfile['params'] # list to store param grids precomputed ignoring the useless ones
  19. #y = gmfile['y'].tolist()
  20. #x = gram_matrices[0]
  21. for x in gram_matrices:
  22. plt.imshow(x)
  23. plt.colorbar()
  24. plt.savefig('check_gm/' + ds_name + '.gm.eps', format='eps', dpi=300)
  25. # print(np.transpose(x))
  26. print('if symmetric: ', np.array_equal(x, np.transpose(x)))
  27. print('diag: ', np.diag(x))
  28. print('sum diag < 0.1: ', np.sum(np.diag(x) < 0.1))
  29. print('min, max diag: ', min(np.diag(x)), max(np.diag(x)))
  30. print('mean x: ', np.mean(np.mean(x)))
  31. [lamnda, v] = eig(x)
  32. print('min, max lambda: ', min(lamnda), max(lamnda))
  33. if -1e-10 > min(lamnda):
  34. raise Exception('wrong eigen values.')

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