| 102 | } |
| 103 | |
| 104 | double compute_modularity_simple ( |
| 105 | const std::vector<sample_pair>& edges, |
| 106 | std::vector<unsigned long> labels |
| 107 | ) |
| 108 | { |
| 109 | double m; |
| 110 | matrix<double> A,P; |
| 111 | make_modularity_matrices(edges, A, P, m); |
| 112 | matrix<double> B = A - P; |
| 113 | |
| 114 | double Q = 0; |
| 115 | for (long r = 0; r < B.nr(); ++r) |
| 116 | { |
| 117 | for (long c = 0; c < B.nc(); ++c) |
| 118 | { |
| 119 | if (labels[r] == labels[c]) |
| 120 | { |
| 121 | Q += B(r,c); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | return 1.0/(2*m) * Q; |
| 126 | } |
| 127 | |
| 128 | // ---------------------------------------------------------------------------------------- |
| 129 |
no test coverage detected