Guest User

Untitled

a guest
Jan 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. private static void FindCommunities()
  2. {
  3. MatrixGenerator mg = new MatrixGenerator();
  4. List<Tuple<int, double>> eigenVectorMapping = new List<Tuple<int, double>>();
  5.  
  6. Matrix<double> AdjacencyArray = DenseMatrix.OfArray(mg.GetAdjancencyMatrix());
  7. Matrix<double> DegreeArray = DenseMatrix.OfArray(mg.GetDegreeMatrix());
  8.  
  9. Control.UseNativeMKL();
  10. var unnormalizedlaplace = DegreeArray - AdjacencyArray;
  11. Console.WriteLine("unnormalized");
  12. Console.WriteLine(unnormalizedlaplace);
  13. var evdmat = unnormalizedlaplace.Evd();
  14. Console.WriteLine("Eigenvectors");
  15. Console.WriteLine(evdmat.EigenVectors);
  16.  
  17. Console.WriteLine("Result:");
  18.  
  19. for (int i = 0; i < evdmat.EigenVectors.RowCount; i++)
  20. {
  21. eigenVectorMapping.Add(new Tuple<int, double>(i, evdmat.EigenVectors[i, 1]));
  22. }
  23.  
  24. eigenVectorMapping = eigenVectorMapping.OrderBy(t => t.Item2).ToList();
  25.  
  26.  
  27. List<int> cuts = new List<int>();
  28.  
  29. for (int i = 0; i < eigenVectorMapping.Count; i++)
  30. {
  31. if (i < eigenVectorMapping.Count - 1)
  32. {
  33. if (((eigenVectorMapping[i + 1].Item2 - eigenVectorMapping[i].Item2) / eigenVectorMapping[i].Item2) * 100 >= 30)
  34. {
  35. Console.WriteLine("Cut: " + i);
  36. cuts.Add(i);
  37. }
  38. }
  39. }
  40.  
  41. List<List<int>> communities = new List<List<int>>();
  42.  
  43. int j = 0;
  44. foreach (int index in cuts)
  45. {
  46. communities.Add(new List<int>());
  47.  
  48. for (int i = j; i < index; i++)
  49. {
  50. communities.Last().Add(eigenVectorMapping[i].Item1);
  51. }
  52.  
  53. j = index;
  54. }
  55.  
  56. communities.Add(new List<int>());
  57.  
  58. for (int i = j; i < eigenVectorMapping.Count; i++)
  59. {
  60. communities.Last().Add(eigenVectorMapping[i].Item1);
  61. }
  62.  
  63. foreach (List<int> c in communities)
  64. {
  65. Console.WriteLine(c.Count);
  66. }
  67. }
Add Comment
Please, Sign In to add comment