本文整理汇总了C++中DistanceMatrix::nc方法的典型用法代码示例。如果您正苦于以下问题:C++ DistanceMatrix::nc方法的具体用法?C++ DistanceMatrix::nc怎么用?C++ DistanceMatrix::nc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DistanceMatrix
的用法示例。
在下文中一共展示了DistanceMatrix::nc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: max_cost_assignment
// Find a 1:1 mapping from rows to columns of the specified square matrix such that the total cost is minimized. Returns a
// vector V such that V[i] = j maps rows i to columns j.
static std::vector<long>
findMinimumAssignment(const DistanceMatrix &matrix) {
#ifdef ROSE_HAVE_DLIB
ASSERT_forbid(matrix.size() == 0);
ASSERT_require(matrix.nr() == matrix.nc());
// We can avoid the O(n^3) Kuhn-Munkres algorithm if all values of the matrix are the same.
double minValue, maxValue;
dlib::find_min_and_max(matrix, minValue /*out*/, maxValue /*out*/);
if (minValue == maxValue) {
std::vector<long> ident;
ident.reserve(matrix.nr());
for (long i=0; i<matrix.nr(); ++i)
ident.push_back(i);
return ident;
}
// Dlib's Kuhn-Munkres finds the *maximum* mapping over *integers*, so we negate everything to find the minumum, and we map
// the doubles onto a reasonably large interval of integers. The interval should be large enough to have some precision,
// but not so large that things might overflow.
const int iGreatest = 1000000; // arbitrary upper bound for integer interval
dlib::matrix<long> intMatrix(matrix.nr(), matrix.nc());
for (long i=0; i<matrix.nr(); ++i) {
for (long j=0; j<matrix.nc(); ++j)
intMatrix(i, j) = round(-iGreatest * (matrix(i, j) - minValue) / (maxValue - minValue));
}
return dlib::max_cost_assignment(intMatrix);
#else
throw FunctionSimilarity::Exception("dlib support is necessary for FunctionSimilarity analysis"
"; see ROSE installation instructions");
#endif
}
示例2: matrix
// Given a square matrix and a 1:1 mapping from rows to columns, return the total cost of the mapping.
static double
totalAssignmentCost(const DistanceMatrix &matrix, const std::vector<long> assignment) {
double sum = 0.0;
ASSERT_require(matrix.nr() == matrix.nc());
ASSERT_require((size_t)matrix.nr() == assignment.size());
for (long i=0; i<matrix.nr(); ++i) {
ASSERT_require(assignment[i] < matrix.nc());
sum += matrix(i, assignment[i]);
}
return sum;
}