// ---------------------------------------------------------------- explicit q_data(const matrix_type & d) : d_ij () , d_ik () , d_jk () , i () , j () { static const auto k_0_5 = value_type(0.5); const auto n = d.get_height(); const auto k_n_2 = value_type(n - 2); // // Cache the row sums; column sums would work equally well // because the matrix is symmetric. // std::vector<value_type> sigma; for (size_t c = 0; c < n; c++) sigma.push_back(d.get_row_sum(c)); // // Compute the values of the Q matrix. // matrix_type q (n, n); for (size_t r = 0; r < n; r++) for (size_t c = 0; c < r; c++) q(r, c) = k_n_2 * d(r, c) - sigma[r] - sigma[c]; // // Find the cell with the minimum value. // i = 1, j = 0; for (size_t r = 2; r < n; r++) for (size_t c = 0; c < r; c++) if (q(r, c) < q(i, j)) i = r, j = c; // // Compute distances between the new nodes. // d_ij = d(i, j); d_ik = k_0_5 * (d_ij + ((sigma[i] - sigma[j]) / k_n_2)); d_jk = d_ij - d_ik; }